[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/nhexl-mode 70d3c54585: * nhexl-mode.el (nhexl-nibble-co
From: |
Stefan Monnier |
Subject: |
[elpa] externals/nhexl-mode 70d3c54585: * nhexl-mode.el (nhexl-nibble-copy-hex): New var |
Date: |
Thu, 15 Dec 2022 15:24:26 -0500 (EST) |
branch: externals/nhexl-mode
commit 70d3c545857f59e892fba9dbefdca4fa25b9af9a
Author: Stefan Monnier <monnier@iro.umontreal.ca>
Commit: Stefan Monnier <monnier@iro.umontreal.ca>
* nhexl-mode.el (nhexl-nibble-copy-hex): New var
(nhexl-nibble-edit-mode): Obey it.
(nhexl--convert-to-hex): New function.
---
nhexl-mode.el | 31 +++++++++++++++++++++++++++----
1 file changed, 27 insertions(+), 4 deletions(-)
diff --git a/nhexl-mode.el b/nhexl-mode.el
index 241372abdf..2ade8d7a0e 100644
--- a/nhexl-mode.el
+++ b/nhexl-mode.el
@@ -68,6 +68,12 @@
;; - Always reload the file with find-file-literally instead
;; of editing the multibyte representation?
+;;; News:
+
+;; Since v1.5:
+;; - New var `nhexl-nibble-copy-hex' to allow kill operations to copy
+;; the hex form when in nibble mode.
+
;;; Code:
(eval-when-compile (require 'cl-lib))
@@ -136,9 +142,14 @@ Groups are separated by spaces."
;; FIXME: Region highlighting in this minor mode should highlight the hex area
;; rather than only the ascii area!
-;; FIXME: Kill&yank in this minor mode should work on the hex representation
+;; FIXME: Yank in this minor mode should work on the hex representation
;; of the buffer's content (and should obey overwrite-mode)!
+(defcustom nhexl-nibble-copy-hex nil ;Probably more annoying than anything!
+ "if non-nil, copy/kill text's hexadecimal representation.
+Only takes effect when in `nhexl-nibble-edit-mode'."
+ :type 'boolean)
+
(defvar nhexl-nibble-edit-mode-map
(let ((map (make-sparse-keymap)))
(define-key map [remap self-insert-command] #'nhexl-nibble-self-insert)
@@ -155,9 +166,17 @@ Groups are separated by spaces."
(define-minor-mode nhexl-nibble-edit-mode
"Minor mode to edit the hex nibbles in `nhexl-mode'."
:global nil
- (if nhexl-nibble-edit-mode
- (setq-local cursor-type 'hbar)
- (kill-local-variable 'cursor-type))
+ (cond
+ (nhexl-nibble-edit-mode
+ (add-function :filter-return (local 'filter-buffer-substring-function)
+ #'nhexl--convert-to-hex)
+ (setq-local nhexl-isearch-hex-bytes t)
+ (setq-local cursor-type 'hbar))
+ (t
+ (remove-function (local 'filter-buffer-substring-function)
+ #'nhexl--convert-to-hex)
+ (kill-local-variable 'cursor-type)
+ (kill-local-variable 'nhexl-isearch-hex-bytes)))
(nhexl--refresh-cursor))
(defvar-local nhexl--nibbles nil
@@ -242,6 +261,10 @@ and TICKS is the `buffer-chars-modified-tick' for which
this was valid.")
(backward-char 1)
(nhexl--nibble-set (1+ nib)))))
+(defun nhexl--convert-to-hex (string)
+ (when nhexl-nibble-edit-mode
+ (mapconcat (lambda (c) (format "%02x" c)) string "")))
+
;;;; No insertion/deletion minor mode
;; FIXME: To make it work more generally, we should hook into
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [elpa] externals/nhexl-mode 70d3c54585: * nhexl-mode.el (nhexl-nibble-copy-hex): New var,
Stefan Monnier <=