[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/nhexl-mode 26fe10c 06/23: * nhexl-mode.el: Add our own
From: |
Stefan Monnier |
Subject: |
[elpa] externals/nhexl-mode 26fe10c 06/23: * nhexl-mode.el: Add our own line-movement functions |
Date: |
Sat, 28 Nov 2020 18:35:42 -0500 (EST) |
branch: externals/nhexl-mode
commit 26fe10ce8a1f54d1a3c67f6d9a3135fda511798e
Author: Stefan Monnier <monnier@iro.umontreal.ca>
Commit: Stefan Monnier <monnier@iro.umontreal.ca>
* nhexl-mode.el: Add our own line-movement functions
(nhexl-mode-map): New keymap.
(nhexl-next-line, nhexl-previous-line): New commands.
(nhexl-nibble-next-line, nhexl-nibble-previous-line): Remove.
---
nhexl-mode.el | 54 ++++++++++++++++++++++++++++++++++++++----------------
1 file changed, 38 insertions(+), 16 deletions(-)
diff --git a/nhexl-mode.el b/nhexl-mode.el
index 75a949f..f125bfc 100644
--- a/nhexl-mode.el
+++ b/nhexl-mode.el
@@ -64,6 +64,8 @@
(defvar nhexl--point nil)
(make-variable-buffer-local 'nhexl--point)
+;;;; Nibble editing minor mode
+
(defvar nhexl-nibble-edit-mode-map
(let ((map (make-sparse-keymap)))
(define-key map [remap self-insert-command] #'nhexl-nibble-self-insert)
@@ -71,8 +73,6 @@
(define-key map [remap forward-char] #'nhexl-nibble-forward)
(define-key map [remap left-char] #'nhexl-nibble-backward)
(define-key map [remap backward-char] #'nhexl-nibble-backward)
- (define-key map [remap next-line] #'nhexl-nibble-next-line)
- (define-key map [remap previous-line] #'nhexl-nibble-previous-line)
map))
(define-minor-mode nhexl-nibble-edit-mode
@@ -135,20 +135,6 @@
(backward-char 1)
(nhexl--nibble-set (nhexl--nibble-max)))))
-(defun nhexl-nibble-next-line ()
- "Go to next line, preserving the nibble position."
- (interactive)
- (let ((nib (nhexl--nibble)))
- (call-interactively 'next-line)
- (nhexl--nibble-set nib)))
-
-(defun nhexl-nibble-previous-line ()
- "Go to next line, preserving the nibble position."
- (interactive)
- (let ((nib (nhexl--nibble)))
- (call-interactively 'previous-line)
- (nhexl--nibble-set nib)))
-
(defun nhexl-nibble-self-insert ()
"Overwrite current nibble with the hex character you type."
(interactive)
@@ -166,6 +152,22 @@
(backward-char 1)
(nhexl--nibble-set (1+ nib)))))
+;;;; Main minor mode
+
+(defvar nhexl-mode-map
+ (let ((map (make-sparse-keymap)))
+ ;; `next-line' and `previous-line' work correctly, but they take ages in
+ ;; large buffers and allocate an insane amount of memory, so the GC is
+ ;; constantly triggered.
+ ;; So instead we just override them with our own custom-tailored functions
+ ;; which don't have to work nearly as hard to figure out where's the
+ ;; next line.
+ ;; FIXME: It would also be good to try and improve `next-line' and
+ ;; `previous-line' for this case, tho it is pretty pathological for them.
+ (define-key map [remap next-line] #'nhexl-next-line)
+ (define-key map [remap previous-line] #'nhexl-previous-line)
+ ;; FIXME: Find a key binding for nhexl-nibble-edit-mode!
+ map))
;;;###autoload
(define-minor-mode nhexl-mode
@@ -197,6 +199,26 @@
(add-hook 'post-command-hook #'nhexl--post-command nil 'local)
(add-hook 'after-change-functions #'nhexl--change-function nil 'local)))
+(defun nhexl-next-line (&optional arg)
+ "Move cursor vertically down ARG lines."
+ (interactive "p")
+ (unless arg (setq arg 1))
+ (if (< arg 0)
+ (nhexl-previous-line (- arg))
+ (let ((nib (nhexl--nibble)))
+ (forward-char (* arg nhexl-line-width))
+ (nhexl--nibble-set nib))))
+
+(defun nhexl-previous-line (&optional arg)
+ "Move cursor vertically up ARG lines."
+ (interactive "p")
+ (unless arg (setq arg 1))
+ (if (< arg 0)
+ (nhexl-next-line (- arg))
+ (let ((nib (nhexl--nibble)))
+ (backward-char (* arg nhexl-line-width))
+ (nhexl--nibble-set nib))))
+
(defun nhexl--change-function (beg end len)
;; Round modifications up-to the hexl-line length since nhexl--jit will need
;; to modify the overlay that covers that text.
- [elpa] branch externals/nhexl-mode created (now 903f1b6), Stefan Monnier, 2020/11/28
- [elpa] externals/nhexl-mode 7b18468 02/23: Commentary tweaks for csv-mode, ioccur, and nhexl-mode packages., Stefan Monnier, 2020/11/28
- [elpa] externals/nhexl-mode d3712d3 01/23: Add nhexl-mode., Stefan Monnier, 2020/11/28
- [elpa] externals/nhexl-mode cd15bed 04/23: * nhexl-mode.el: Use cl-lib, Stefan Monnier, 2020/11/28
- [elpa] externals/nhexl-mode 26fe10c 06/23: * nhexl-mode.el: Add our own line-movement functions,
Stefan Monnier <=
- [elpa] externals/nhexl-mode 80d9a10 11/23: * nhexl-mode/nhexl-mode.el (nhexl-line-width): Allow dynamic adjust, Stefan Monnier, 2020/11/28
- [elpa] externals/nhexl-mode 485c2c1 05/23: * nhexl-mode.el (nhexl-nibble-edit-mode): New minor mode, Stefan Monnier, 2020/11/28
- [elpa] externals/nhexl-mode 5ae7dc1 07/23: * nhexl-mode.el (nhexl-overwrite-only-mode): New minor mode., Stefan Monnier, 2020/11/28
- [elpa] externals/nhexl-mode 4ec0242 08/23: * nhexl-mode.el: Bump version number for new release, Stefan Monnier, 2020/11/28
- [elpa] externals/nhexl-mode 25704c9 10/23: * nhexl-mode/nhexl-mode.el: Let isearch look for addresses as well, Stefan Monnier, 2020/11/28
- [elpa] externals/nhexl-mode 16b716f 03/23: nhexl-mode.el: Fix last change., Stefan Monnier, 2020/11/28
- [elpa] externals/nhexl-mode e2450fd 09/23: * nhexl-mode.el: Hide undisplayable chars by default, Stefan Monnier, 2020/11/28
- [elpa] externals/nhexl-mode 1082cc6 12/23: * nhexl-mode/nhexl-mode.el: Fix minor issues, Stefan Monnier, 2020/11/28
- [elpa] externals/nhexl-mode 8310ad1 13/23: * nhexl-mode/nhexl-mode.el: Improve multi-window behavior, Stefan Monnier, 2020/11/28
- [elpa] externals/nhexl-mode 1cb2581 14/23: * nhexl-mode/nhexl-mode.el: Get rid of the spurious top empty line, Stefan Monnier, 2020/11/28