aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2011-01-14 14:55:35 -0500
committerStefan Monnier2011-01-14 14:55:35 -0500
commit4391b429f897002ef363daab52c08fd3e11e736e (patch)
tree71b113182bd43cc0dd78592ec3c607ed4d92921b
parent46d71064338f940f2ffbd7f49a1709ac39bf44a4 (diff)
downloademacs-4391b429f897002ef363daab52c08fd3e11e736e.tar.gz
emacs-4391b429f897002ef363daab52c08fd3e11e736e.zip
* lisp/hexl.el (hexl-mode-old-*): Remove.
(hexl-mode--old-var-vals): New var to replace them. (hexl-mode--minor-mode-p, hexl-mode--setq-local): New funs. (hexl-mode, hexl-follow-line, hexl-activate-ruler): Use them to set local vars. (hexl-mode-exit): Use hexl-mode--old-var-vals to restore state. (hexl-backward-short, hexl-backward-word, hexl-scroll-down) (hexl-scroll-up, hexl-end-of-1k-page, hexl-end-of-512b-page): Simplify. Fixes: debbugs:7846
-rw-r--r--lisp/ChangeLog9
-rw-r--r--lisp/hexl.el238
2 files changed, 105 insertions, 142 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 320335c4e7a..3c88bb33646 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,5 +1,14 @@
12011-01-14 Stefan Monnier <monnier@iro.umontreal.ca> 12011-01-14 Stefan Monnier <monnier@iro.umontreal.ca>
2 2
3 * hexl.el (hexl-mode-old-*): Remove.
4 (hexl-mode--old-var-vals): New var to replace them.
5 (hexl-mode--minor-mode-p, hexl-mode--setq-local): New funs.
6 (hexl-mode, hexl-follow-line, hexl-activate-ruler):
7 Use them to set local vars (bug#7846).
8 (hexl-mode-exit): Use hexl-mode--old-var-vals to restore state.
9 (hexl-backward-short, hexl-backward-word, hexl-scroll-down)
10 (hexl-scroll-up, hexl-end-of-1k-page, hexl-end-of-512b-page): Simplify.
11
3 * vc/smerge-mode.el: Resolve comment conflicts more aggressively. 12 * vc/smerge-mode.el: Resolve comment conflicts more aggressively.
4 (smerge-resolve--normalize-re): New var. 13 (smerge-resolve--normalize-re): New var.
5 (smerge-resolve--extract-comment, smerge-resolve--normalize): New funs. 14 (smerge-resolve--extract-comment, smerge-resolve--normalize): New funs.
diff --git a/lisp/hexl.el b/lisp/hexl.el
index 3cd987df0a3..bd8c29d3b6a 100644
--- a/lisp/hexl.el
+++ b/lisp/hexl.el
@@ -199,20 +199,8 @@ Quoting cannot be used, so the arguments cannot themselves contain spaces."
199(defvar hl-line-face) 199(defvar hl-line-face)
200 200
201;; Variables where the original values are stored to. 201;; Variables where the original values are stored to.
202(defvar hexl-mode-old-hl-line-mode) 202(defvar hexl-mode--old-var-vals ())
203(defvar hexl-mode-old-hl-line-range-function) 203(make-variable-buffer-local 'hexl-mode--old-var-vals)
204(defvar hexl-mode-old-hl-line-face)
205(defvar hexl-mode-old-local-map)
206(defvar hexl-mode-old-mode-name)
207(defvar hexl-mode-old-major-mode)
208(defvar hexl-mode-old-ruler-mode)
209(defvar hexl-mode-old-ruler-function)
210(defvar hexl-mode-old-isearch-search-fun-function)
211(defvar hexl-mode-old-require-final-newline)
212(defvar hexl-mode-old-syntax-table)
213(defvar hexl-mode-old-font-lock-keywords)
214(defvar hexl-mode-old-eldoc-documentation-function)
215(defvar hexl-mode-old-revert-buffer-function)
216 204
217(defvar hexl-ascii-overlay nil 205(defvar hexl-ascii-overlay nil
218 "Overlay used to highlight ASCII element corresponding to current point.") 206 "Overlay used to highlight ASCII element corresponding to current point.")
@@ -229,6 +217,25 @@ Quoting cannot be used, so the arguments cannot themselves contain spaces."
229 217
230(put 'hexl-mode 'mode-class 'special) 218(put 'hexl-mode 'mode-class 'special)
231 219
220
221(defun hexl-mode--minor-mode-p (var)
222 (memq var '(ruler-mode hl-line-mode)))
223
224(defun hexl-mode--setq-local (var val)
225 ;; `var' can be either a symbol or a pair, in which case the `car'
226 ;; is the getter function and the `cdr' is the corresponding setter.
227 (unless (or (member var hexl-mode--old-var-vals)
228 (assoc var hexl-mode--old-var-vals))
229 (push (if (or (consp var) (boundp var))
230 (cons var
231 (if (consp var) (funcall (car var)) (symbol-value var)))
232 var)
233 hexl-mode--old-var-vals))
234 (cond
235 ((consp var) (funcall (cdr var) val))
236 ((hexl-mode--minor-mode-p var) (funcall var (if val 1 -1)))
237 (t (set (make-local-variable var) val))))
238
232;;;###autoload 239;;;###autoload
233(defun hexl-mode (&optional arg) 240(defun hexl-mode (&optional arg)
234 "\\<hexl-mode-map>A mode for editing binary files in hex dump format. 241 "\\<hexl-mode-map>A mode for editing binary files in hex dump format.
@@ -334,58 +341,31 @@ You can use \\[hexl-find-file] to visit a file in Hexl mode.
334 341
335 ;; We do not turn off the old major mode; instead we just 342 ;; We do not turn off the old major mode; instead we just
336 ;; override most of it. That way, we can restore it perfectly. 343 ;; override most of it. That way, we can restore it perfectly.
337 (make-local-variable 'hexl-mode-old-local-map)
338 (setq hexl-mode-old-local-map (current-local-map))
339 (use-local-map hexl-mode-map)
340
341 (make-local-variable 'hexl-mode-old-mode-name)
342 (setq hexl-mode-old-mode-name mode-name)
343 (setq mode-name "Hexl")
344 344
345 (set (make-local-variable 'hexl-mode-old-isearch-search-fun-function) 345 (hexl-mode--setq-local '(current-local-map . use-local-map) hexl-mode-map)
346 isearch-search-fun-function)
347 (set (make-local-variable 'isearch-search-fun-function)
348 'hexl-isearch-search-function)
349 346
350 (make-local-variable 'hexl-mode-old-major-mode) 347 (hexl-mode--setq-local 'mode-name "Hexl")
351 (setq hexl-mode-old-major-mode major-mode) 348 (hexl-mode--setq-local 'isearch-search-fun-function
352 (setq major-mode 'hexl-mode) 349 'hexl-isearch-search-function)
350 (hexl-mode--setq-local 'major-mode 'hexl-mode)
353 351
354 (make-local-variable 'hexl-mode-old-ruler-mode) 352 (hexl-mode--setq-local '(syntax-table . set-syntax-table)
355 (setq hexl-mode-old-ruler-mode 353 (standard-syntax-table))
356 (and (boundp 'ruler-mode) ruler-mode))
357
358 (make-local-variable 'hexl-mode-old-hl-line-mode)
359 (setq hexl-mode-old-hl-line-mode
360 (and (boundp 'hl-line-mode) hl-line-mode))
361
362 (make-local-variable 'hexl-mode-old-syntax-table)
363 (setq hexl-mode-old-syntax-table (syntax-table))
364 (set-syntax-table (standard-syntax-table))
365 354
366 (add-hook 'write-contents-functions 'hexl-save-buffer nil t) 355 (add-hook 'write-contents-functions 'hexl-save-buffer nil t)
367 356
368 (make-local-variable 'hexl-mode-old-require-final-newline) 357 (hexl-mode--setq-local 'require-final-newline nil)
369 (setq hexl-mode-old-require-final-newline require-final-newline)
370 (make-local-variable 'require-final-newline)
371 (setq require-final-newline nil)
372 358
373 (make-local-variable 'hexl-mode-old-font-lock-keywords) 359
374 (setq hexl-mode-old-font-lock-keywords font-lock-defaults) 360 (hexl-mode--setq-local 'font-lock-defaults '(hexl-font-lock-keywords t))
375 (setq font-lock-defaults '(hexl-font-lock-keywords t))
376 361
377 (make-local-variable 'hexl-mode-old-revert-buffer-function) 362 (hexl-mode--setq-local 'revert-buffer-function
378 (setq hexl-mode-old-revert-buffer-function revert-buffer-function) 363 #'hexl-revert-buffer-function)
379 (setq revert-buffer-function 'hexl-revert-buffer-function)
380 (add-hook 'change-major-mode-hook 'hexl-maybe-dehexlify-buffer nil t) 364 (add-hook 'change-major-mode-hook 'hexl-maybe-dehexlify-buffer nil t)
381 365
382 ;; Set a callback function for eldoc. 366 ;; Set a callback function for eldoc.
383 (make-local-variable 'hexl-mode-old-eldoc-documentation-function) 367 (hexl-mode--setq-local 'eldoc-documentation-function
384 (setq hexl-mode-old-eldoc-documentation-function 368 #'hexl-print-current-point-info)
385 (bound-and-true-p eldoc-documentation-function))
386
387 (set (make-local-variable 'eldoc-documentation-function)
388 'hexl-print-current-point-info)
389 (eldoc-add-command-completions "hexl-") 369 (eldoc-add-command-completions "hexl-")
390 (eldoc-remove-command "hexl-save-buffer" 370 (eldoc-remove-command "hexl-save-buffer"
391 "hexl-current-address") 371 "hexl-current-address")
@@ -498,30 +478,22 @@ With arg, don't unhexlify buffer."
498 (remove-hook 'post-command-hook 'hexl-follow-ascii-find t) 478 (remove-hook 'post-command-hook 'hexl-follow-ascii-find t)
499 (setq hexl-ascii-overlay nil) 479 (setq hexl-ascii-overlay nil)
500 480
501 (if (and (boundp 'ruler-mode) ruler-mode (not hexl-mode-old-ruler-mode)) 481 (let ((mms ()))
502 (ruler-mode 0)) 482 (dolist (varval hexl-mode--old-var-vals)
503 (when (boundp 'hexl-mode-old-ruler-function) 483 (let* ((bound (consp varval))
504 (setq ruler-mode-ruler-function hexl-mode-old-ruler-function)) 484 (var (if bound (car varval) varval))
505 485 (val (cdr-safe varval)))
506 (if (and (boundp 'hl-line-mode) hl-line-mode (not hexl-mode-old-hl-line-mode)) 486 (cond
507 (hl-line-mode 0)) 487 ((consp var) (funcall (cdr var) val))
508 (when (boundp 'hexl-mode-old-hl-line-range-function) 488 ((hexl-mode--minor-mode-p var) (push (cons var val) mms))
509 (setq hl-line-range-function hexl-mode-old-hl-line-range-function)) 489 (bound (set (make-local-variable var) val))
510 (when (boundp 'hexl-mode-old-hl-line-face) 490 (t (kill-local-variable var)))))
511 (setq hl-line-face hexl-mode-old-hl-line-face)) 491 (kill-local-variable 'hexl-mode--old-var-vals)
512 492 ;; Enable/disable minor modes. Do it after having reset the other vars,
513 (when (boundp 'hexl-mode-old-eldoc-documentation-function) 493 ;; since some of them may affect the minor modes.
514 (setq eldoc-documentation-function 494 (dolist (mm mms)
515 hexl-mode-old-eldoc-documentation-function)) 495 (funcall (car mm) (if (cdr mm) 1 -1))))
516 496
517 (setq require-final-newline hexl-mode-old-require-final-newline)
518 (setq mode-name hexl-mode-old-mode-name)
519 (setq isearch-search-fun-function hexl-mode-old-isearch-search-fun-function)
520 (use-local-map hexl-mode-old-local-map)
521 (set-syntax-table hexl-mode-old-syntax-table)
522 (setq font-lock-defaults hexl-mode-old-font-lock-keywords)
523 (setq major-mode hexl-mode-old-major-mode)
524 (setq revert-buffer-function hexl-mode-old-revert-buffer-function)
525 (force-mode-line-update)) 497 (force-mode-line-update))
526 498
527(defun hexl-maybe-dehexlify-buffer () 499(defun hexl-maybe-dehexlify-buffer ()
@@ -620,23 +592,21 @@ Signal error if HEX-ADDRESS is out of range."
620 (progn 592 (progn
621 (setq arg (- arg)) 593 (setq arg (- arg))
622 (while (> arg 0) 594 (while (> arg 0)
623 (if (not (equal address (logior address 3))) 595 (setq address
624 (if (> address hexl-max-address) 596 (if (> address hexl-max-address)
625 (progn 597 (progn
626 (message "End of buffer.") 598 (message "End of buffer.")
627 (setq address hexl-max-address)) 599 hexl-max-address)
628 (setq address (logior address 3))) 600 (if (equal address (logior address 3))
629 (if (> address hexl-max-address) 601 (+ address 4)
630 (progn 602 (logior address 3))))
631 (message "End of buffer.")
632 (setq address hexl-max-address))
633 (setq address (+ address 4))))
634 (setq arg (1- arg))) 603 (setq arg (1- arg)))
635 (if (> address hexl-max-address) 604 (setq address
636 (progn 605 (if (> address hexl-max-address)
637 (message "End of buffer.") 606 (progn
638 (setq address hexl-max-address)) 607 (message "End of buffer.")
639 (setq address (logior address 3)))) 608 hexl-max-address)
609 (logior address 3))))
640 (while (> arg 0) 610 (while (> arg 0)
641 (if (not (equal address (logand address -4))) 611 (if (not (equal address (logand address -4)))
642 (setq address (logand address -4)) 612 (setq address (logand address -4))
@@ -659,23 +629,21 @@ Signal error if HEX-ADDRESS is out of range."
659 (progn 629 (progn
660 (setq arg (- arg)) 630 (setq arg (- arg))
661 (while (> arg 0) 631 (while (> arg 0)
662 (if (not (equal address (logior address 7))) 632 (setq address
663 (if (> address hexl-max-address) 633 (if (> address hexl-max-address)
664 (progn 634 (progn
665 (message "End of buffer.") 635 (message "End of buffer.")
666 (setq address hexl-max-address)) 636 hexl-max-address)
667 (setq address (logior address 7))) 637 (if (equal address (logior address 7))
668 (if (> address hexl-max-address) 638 (+ address 8)
669 (progn 639 (logior address 7))))
670 (message "End of buffer.")
671 (setq address hexl-max-address))
672 (setq address (+ address 8))))
673 (setq arg (1- arg))) 640 (setq arg (1- arg)))
674 (if (> address hexl-max-address) 641 (setq address
675 (progn 642 (if (> address hexl-max-address)
676 (message "End of buffer.") 643 (progn
677 (setq address hexl-max-address)) 644 (message "End of buffer.")
678 (setq address (logior address 7)))) 645 hexl-max-address)
646 (logior address 7))))
679 (while (> arg 0) 647 (while (> arg 0)
680 (if (not (equal address (logand address -8))) 648 (if (not (equal address (logand address -8)))
681 (setq address (logand address -8)) 649 (setq address (logand address -8))
@@ -746,18 +714,18 @@ With prefix arg N, puts point N bytes of the way from the true beginning."
746(defun hexl-scroll-down (arg) 714(defun hexl-scroll-down (arg)
747 "Scroll hexl buffer window upward ARG lines; or near full window if no ARG." 715 "Scroll hexl buffer window upward ARG lines; or near full window if no ARG."
748 (interactive "P") 716 (interactive "P")
749 (if (null arg) 717 (setq arg (if (null arg)
750 (setq arg (1- (window-height))) 718 (1- (window-height))
751 (setq arg (prefix-numeric-value arg))) 719 (prefix-numeric-value arg)))
752 (hexl-scroll-up (- arg))) 720 (hexl-scroll-up (- arg)))
753 721
754(defun hexl-scroll-up (arg) 722(defun hexl-scroll-up (arg)
755 "Scroll hexl buffer window upward ARG lines; or near full window if no ARG. 723 "Scroll hexl buffer window upward ARG lines; or near full window if no ARG.
756If there's no byte at the target address, move to the first or last line." 724If there's no byte at the target address, move to the first or last line."
757 (interactive "P") 725 (interactive "P")
758 (if (null arg) 726 (setq arg (if (null arg)
759 (setq arg (1- (window-height))) 727 (1- (window-height))
760 (setq arg (prefix-numeric-value arg))) 728 (prefix-numeric-value arg)))
761 (let* ((movement (* arg 16)) 729 (let* ((movement (* arg 16))
762 (address (hexl-current-address)) 730 (address (hexl-current-address))
763 (dest (+ address movement))) 731 (dest (+ address movement)))
@@ -785,10 +753,8 @@ If there's no byte at the target address, move to the first or last line."
785(defun hexl-end-of-1k-page () 753(defun hexl-end-of-1k-page ()
786 "Go to end of 1KB boundary." 754 "Go to end of 1KB boundary."
787 (interactive) 755 (interactive)
788 (hexl-goto-address (let ((address (logior (hexl-current-address) 1023))) 756 (hexl-goto-address
789 (if (> address hexl-max-address) 757 (max hexl-max-address (logior (hexl-current-address) 1023))))
790 (setq address hexl-max-address))
791 address)))
792 758
793(defun hexl-beginning-of-512b-page () 759(defun hexl-beginning-of-512b-page ()
794 "Go to beginning of 512 byte boundary." 760 "Go to beginning of 512 byte boundary."
@@ -798,10 +764,8 @@ If there's no byte at the target address, move to the first or last line."
798(defun hexl-end-of-512b-page () 764(defun hexl-end-of-512b-page ()
799 "Go to end of 512 byte boundary." 765 "Go to end of 512 byte boundary."
800 (interactive) 766 (interactive)
801 (hexl-goto-address (let ((address (logior (hexl-current-address) 511))) 767 (hexl-goto-address
802 (if (> address hexl-max-address) 768 (max hexl-max-address (logior (hexl-current-address) 511))))
803 (setq address hexl-max-address))
804 address)))
805 769
806(defun hexl-quoted-insert (arg) 770(defun hexl-quoted-insert (arg)
807 "Read next input character and insert it. 771 "Read next input character and insert it.
@@ -1056,27 +1020,17 @@ Customize the variable `hexl-follow-ascii' to disable this feature."
1056(defun hexl-activate-ruler () 1020(defun hexl-activate-ruler ()
1057 "Activate `ruler-mode'." 1021 "Activate `ruler-mode'."
1058 (require 'ruler-mode) 1022 (require 'ruler-mode)
1059 (unless (boundp 'hexl-mode-old-ruler-function) 1023 (hexl-mode--setq-local 'ruler-mode-ruler-function
1060 (set (make-local-variable 'hexl-mode-old-ruler-function) 1024 #'hexl-mode-ruler)
1061 ruler-mode-ruler-function)) 1025 (hexl-mode--setq-local 'ruler-mode t))
1062 (set (make-local-variable 'ruler-mode-ruler-function)
1063 'hexl-mode-ruler)
1064 (ruler-mode 1))
1065 1026
1066(defun hexl-follow-line () 1027(defun hexl-follow-line ()
1067 "Activate `hl-line-mode'." 1028 "Activate `hl-line-mode'."
1068 (require 'hl-line) 1029 (require 'hl-line)
1069 (unless (boundp 'hexl-mode-old-hl-line-range-function) 1030 (hexl-mode--setq-local 'hl-line-range-function
1070 (set (make-local-variable 'hexl-mode-old-hl-line-range-function) 1031 #'hexl-highlight-line-range)
1071 hl-line-range-function)) 1032 (hexl-mode--setq-local 'hl-line-face 'highlight)
1072 (unless (boundp 'hexl-mode-old-hl-line-face) 1033 (hexl-mode--setq-local 'hl-line-mode t))
1073 (set (make-local-variable 'hexl-mode-old-hl-line-face)
1074 hl-line-face))
1075 (set (make-local-variable 'hl-line-range-function)
1076 'hexl-highlight-line-range)
1077 (set (make-local-variable 'hl-line-face)
1078 'highlight)
1079 (hl-line-mode 1))
1080 1034
1081(defun hexl-highlight-line-range () 1035(defun hexl-highlight-line-range ()
1082 "Return the range of address region for the point. 1036 "Return the range of address region for the point.