emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/zones aed6ee5: * zones.el: Improve pieces of advice


From: Stefan Monnier
Subject: [elpa] externals/zones aed6ee5: * zones.el: Improve pieces of advice
Date: Tue, 30 Oct 2018 23:34:33 -0400 (EDT)

branch: externals/zones
commit aed6ee5fb5bc0e320065e8a2eac7ae9e4a48d21e
Author: Stefan Monnier <address@hidden>
Commit: Stefan Monnier <address@hidden>

    * zones.el: Improve pieces of advice
    
    (zz-user-error): Make it a function.
    (narrow-to-defun, narrow-to-page): Make the advice less invasive.
    * .gitignore: New file.
---
 .gitignore |  3 ++
 zones.el   | 93 +++++++-------------------------------------------------------
 2 files changed, 13 insertions(+), 83 deletions(-)

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..ac49de9
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+zones-autoloads.el
+zones-pkg.el
+*.elc
diff --git a/zones.el b/zones.el
index 605bb08..1140d81 100644
--- a/zones.el
+++ b/zones.el
@@ -743,8 +743,8 @@
 ;;;;;;;;;;;;;;;;;;;;;;;;;;
 
 
-(defmacro zz-user-error (&rest args)
-  `(if (fboundp 'user-error) (user-error ,@args) (error ,@args))) ; For Emacs 
22-23. 
+(defalias 'zz-user-error
+  (if (fboundp 'user-error) #'user-error #'error)) ; For Emacs 22-23.
 
 (defgroup zones nil
   "Zones of text - like multiple regions."
@@ -1860,6 +1860,8 @@ current zones instead of adding to them."
 
 ;;---------------------
 
+;; FIXME: Just loading this file shouldn't overwrite bindings a user may
+;; have put into narrow-map.
 (cond ((boundp 'narrow-map)             ; Emacs 23+
        (define-key narrow-map "a"    'zz-add-zone)
        (define-key narrow-map "A"    'zz-add-zone-and-unite)
@@ -1912,100 +1914,25 @@ value can be modified."
 
 ;; Call `zz-add-zone' if interactive or if `zz-add-zone-anyway-p'.
 ;;
-(defadvice narrow-to-defun (around zz-add-zone--defun activate)
+(defadvice narrow-to-defun (after zz-add-zone--defun activate)
   "Push the defun limits to the current `zz-izones-var'.
 You can use `C-x n x' to widen to a previous buffer restriction.
 
 This is a destructive operation. The list structure of the variable
 value can be modified."
-  (interactive (and (boundp 'narrow-to-defun-include-comments) ; Emacs 24+
-                    (list narrow-to-defun-include-comments)))
-  (save-excursion
-    (widen)
-    (let ((opoint (point))
-         beg end)
-      ;; Try first in this order for the sake of languages with nested 
functions where several can end at the same
-      ;; place as with the offside rule, e.g. Python.
-      ;; Finding the start of the function is a bit problematic since 
`beginning-of-defun' when we are on the
-      ;; first character of the function might go to the previous function.
-      ;; Therefore we first move one character forward and then call 
`beginning-of-defun'.  However now we must
-      ;; check that we did not move into the next function.
-      (let ((here  (point)))
-        (unless (eolp) (forward-char))
-        (beginning-of-defun)
-        (when (< (point) here)
-          (goto-char here)
-          (beginning-of-defun)))
-      (setq beg  (point))
-      (end-of-defun)
-      (setq end  (point))
-      (while (looking-at "^\n")        (forward-line 1))
-      (unless (> (point) opoint) ; `beginning-of-defun' moved back one defun 
so we got the wrong one.
-       (goto-char opoint)
-       (end-of-defun)
-       (setq end  (point))
-       (beginning-of-defun)
-       (setq beg  (point)))
-      (when (ad-get-arg 0) ; Argument INCLUDE-COMMENTS
-       (goto-char beg)
-       (when (forward-comment -1) ; Move back past all preceding comments (and 
whitespace).
-         (while (forward-comment -1))
-         ;; Move forward past any page breaks within these comments.
-         (when (and page-delimiter  (not (string= page-delimiter "")))
-           (while (re-search-forward page-delimiter beg t)))
-         ;; Lastly, move past any empty lines.
-         (skip-chars-forward "[:space:]\n")
-         (beginning-of-line)
-         (setq beg (point))))
-      (goto-char end)
-      (re-search-backward "^\n" (- (point) 1) t)
-      ;; THIS IS THE ONLY CHANGE FOR `zones.el'.
-      (when (or (interactive-p)  zz-add-zone-anyway-p) (zz-add-zone beg end 
nil nil nil 'MSG))
-      (narrow-to-region beg end))))
+  (when (or (interactive-p)  zz-add-zone-anyway-p)
+    (zz-add-zone (point-min) (point-max) nil nil nil 'MSG)))
 
 ;; Call `zz-add-zone' if interactive or `zz-add-zone-anyway-p'.
 ;;
-(defadvice narrow-to-page (around zz-add-zone--defun activate)
+(defadvice narrow-to-page (after zz-add-zone--defun activate)
   "Push the page limits to the current `zz-izones-var'.
 You can use `C-x n x' to widen to a previous buffer restriction.
 
 This is a destructive operation. The list structure of the variable
 value can be modified."
-  (interactive "P")
-  (setq arg  (if arg (prefix-numeric-value arg) 0))
-  (save-excursion
-    (widen)
-    (if (> arg 0)
-       (forward-page arg)
-      (if (< arg 0)
-         (let ((adjust  0)
-               (opoint  (point)))
-           ;; If not now at the beginning of a page, move back one extra time, 
to get to start of this page.
-           (save-excursion
-             (beginning-of-line)
-             (or (and (looking-at page-delimiter)  (eq (match-end 0) opoint))
-                 (setq adjust 1)))
-           (forward-page (- arg adjust)))))
-    ;; Find the end of the page.
-    (set-match-data nil)
-    (forward-page)
-    ;; If we stopped due to end of buffer, stay there.
-    ;; If we stopped after a page delimiter, put end of restriction at the 
beginning of that line.
-    ;; Before checking the match that was found, verify that `forward-page' 
actually set the match data.
-    (if (and (match-beginning 0)  (save-excursion (goto-char (match-beginning 
0)) (looking-at page-delimiter)))
-       (goto-char (match-beginning 0)))
-    (let ((beg  (point))
-          (end  (progn
-                  ;; Find the top of the page.
-                  (forward-page -1)
-                  ;; If we found beginning of buffer, stay there.
-                  ;; If extra text follows page delimiter on same line, 
include it.
-                  ;; Otherwise, show text starting with following line.
-                  (when (and (eolp)  (not (bobp))) (forward-line 1))
-                  (point))))
-      ;; THIS IS THE ONLY CHANGE FOR `zones.el'.
-      (when (or (interactive-p)  zz-add-zone-anyway-p) (zz-add-zone beg end 
nil nil nil 'MSG))
-      (narrow-to-region beg end))))
+  (when (or (interactive-p)  zz-add-zone-anyway-p)
+    (zz-add-zone (point-min) (point-max) nil nil nil 'MSG)))
 
 
 (when (> emacs-major-version 24)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]