[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 8620d4c: * packages/nhexl-mode/nhexl-mode.el (nhexl-group-
From: |
Stefan Monnier |
Subject: |
[elpa] master 8620d4c: * packages/nhexl-mode/nhexl-mode.el (nhexl-group-size): New user config |
Date: |
Tue, 15 Oct 2019 18:40:49 -0400 (EDT) |
branch: master
commit 8620d4cd3aeaa75910785c39b34a38d92f8a8570
Author: Stefan Monnier <address@hidden>
Commit: Stefan Monnier <address@hidden>
* packages/nhexl-mode/nhexl-mode.el (nhexl-group-size): New user config
(nhexl--make-line, nhexl--header-line, nhexl--adjust-to-width): Obey it.
(nhexl--window-size-change): Adjust to Emacs-27's new calling
convention of window-size-change-functions.
(nhexl-mode): Use the local part of window-size-change-functions
when it works reliably.
---
packages/nhexl-mode/nhexl-mode.el | 52 +++++++++++++++++++++++++--------------
1 file changed, 33 insertions(+), 19 deletions(-)
diff --git a/packages/nhexl-mode/nhexl-mode.el
b/packages/nhexl-mode/nhexl-mode.el
index 3a116f0..fdd9866 100644
--- a/packages/nhexl-mode/nhexl-mode.el
+++ b/packages/nhexl-mode/nhexl-mode.el
@@ -107,6 +107,11 @@ Otherwise they are applied unconditionally."
"If non-nil, nhexl will highlight Isearch matches in the hex areas as well."
:type 'boolean)
+(defcustom nhexl-group-size (max 1 (/ hexl-bits 8))
+ "Number of bytes in each group.
+Groups are separated by spaces."
+ :type 'integer)
+
(defvar nhexl--display-table
(let ((dt (make-display-table)))
(unless nhexl-display-unprintables
@@ -125,7 +130,6 @@ Otherwise they are applied unconditionally."
;; FIXME: Region highlighting in this minor mode should highlight the hex area
;; rather than only the ascii area!
-;; FIXME: Isearch in this minor mode should try and "search in the hex area".
;; FIXME: Kill&yank in this minor mode should work on the hex representation
;; of the buffer's content (and should obey overwrite-mode)!
@@ -418,7 +422,9 @@ existing text, if needed with `nhexl-overwrite-clear-byte'."
(add-hook 'after-change-functions #'nhexl--change-function nil 'local)
(add-hook 'window-configuration-change-hook
#'nhexl--window-config-change nil 'local)
- (add-hook 'window-size-change-functions #'nhexl--window-size-change)
+ (add-hook 'window-size-change-functions #'nhexl--window-size-change
+ ;; Make it local in Emacs≥27
+ nil (boundp 'window-buffer-change-functions))
(add-function :around (local 'isearch-search-fun-function)
#'nhexl--isearch-search-fun)
;; FIXME: We should delay this to after running the minor-mode hook.
@@ -659,7 +665,7 @@ Return the corresponding nibble, if applicable."
(put-text-property 0 (length s)
'face '(highlight default)
s)))
- (if (zerop (mod i 2))
+ (if (not (zerop (mod (1+ i) nhexl-group-size)))
;; FIXME: If this char and the next are both
;; covered by isearch highlight, we should
;; also highlight the space.
@@ -667,13 +673,14 @@ Return the corresponding nibble, if applicable."
bufstr
"")
(if (> next nextpos)
- (make-string (+ (/ (1+ (- next nextpos)) 2)
+ (make-string (+ (/ (1+ (- next nextpos)) nhexl-group-size)
(* (- next nextpos) 2))
?\s))
(propertize " " 'display
`(space :align-to
- ,(+ (/ (* lw 5) 2)
- 12 3))))))
+ ,(+ (* lw 2) ;digits
+ (/ lw nhexl-group-size) ;spaces
+ 12 3)))))) ;addr + borders
(font-lock-append-text-property 0 (length s) prop 'default s)
;; If the first char of the text has a button (e.g. it's part of
;; a hyperlink), clicking in the hex part of the display might signal
@@ -766,9 +773,9 @@ Return the corresponding nibble, if applicable."
(setq i (logand i #xf))
(push (if (< i 10) (+ i ?0) (+ i -10 ?a)) tmp))
(apply #'string (nreverse tmp))))
- (pos (mod (- (point) zero) lw))
- (i -1))
- (put-text-property pos (1+ pos) 'face 'highlight text)
+ (pos (1+ (mod (- (point) zero) lw)))
+ (i 0))
+ (put-text-property (1- pos) pos 'face 'highlight text)
(concat
(eval-when-compile (propertize " " 'display '(space :align-to 0)))
"Address:"
@@ -776,7 +783,7 @@ Return the corresponding nibble, if applicable."
(mapconcat (lambda (c)
(setq i (1+ i))
(let ((s (string c c)))
- (when (eq i pos)
+ (when (eql i pos)
(if nhexl-nibble-edit-mode
(let ((nib (min (nhexl--nibble (point))
(1- (length s)))))
@@ -786,17 +793,21 @@ Return the corresponding nibble, if applicable."
(put-text-property 0 (length s)
'face 'highlight
s)))
- (if (zerop (mod i 2)) s
+ (if (not (zerop (mod i nhexl-group-size)))
+ s
(concat
s (propertize " " 'display
`(space :align-to
- ,(+ (/ (* i 5) 2) 12 3)))))))
+ ,(+ (* i 2) ;digits
+ (/ i nhexl-group-size) ;spaces
+ 12))))))) ;addr
text
"")
(propertize " " 'display
`(space :align-to
- ,(+ (/ (* lw 5) 2)
- 12 3)))
+ ,(+ (* lw 2) ;digits
+ (/ lw nhexl-group-size) ;spaces
+ 12 3))) ;addr + border
text)))
@@ -971,11 +982,14 @@ Return the corresponding nibble, if applicable."
(when (fboundp 'add-variable-watcher)
(add-variable-watcher 'nhexl-line-width #'nhexl--line-width-watcher))
-(defun nhexl--window-size-change (frame)
+(defun nhexl--window-size-change (frame-or-window)
(when (eq t (default-value 'nhexl-line-width))
- (dolist (win (window-list frame 'nomini))
- (when (buffer-local-value 'nhexl-mode (window-buffer win))
- (with-selected-window win (nhexl--adjust-to-width))))))
+ (if (windowp frame-or-window) ;Emacs≥27
+ (with-selected-window frame-or-window
+ (nhexl--adjust-to-width))
+ (dolist (win (window-list frame-or-window 'nomini))
+ (when (buffer-local-value 'nhexl-mode (window-buffer win))
+ (with-selected-window win (nhexl--adjust-to-width)))))))
(defun nhexl--window-config-change ()
;; Doing it only from `window-size-change-functions' is not sufficient
@@ -994,7 +1008,7 @@ Return the corresponding nibble, if applicable."
(+ 9 ;Address
3 ;Spaces between address and hex area
4))) ;Spaces between hex area and ascii area
- 3.5)) ;Columns per byte
+ (+ 3 (/ 1.0 nhexl-group-size)))) ;Columns per byte
(pow2bytes (lsh 1 (truncate (log bytes 2)))))
(when (> (/ bytes pow2bytes) 1.5)
;; Add 1½ steps: 4, *6*, 8, *12*, 16, *24*, 32, *48*, 64
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [elpa] master 8620d4c: * packages/nhexl-mode/nhexl-mode.el (nhexl-group-size): New user config,
Stefan Monnier <=