[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/multiple-cursors 6e15923 229/434: Use uninterned symbols i
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/multiple-cursors 6e15923 229/434: Use uninterned symbols in macros to avoid surprising local vars |
Date: |
Sat, 7 Aug 2021 09:20:31 -0400 (EDT) |
branch: elpa/multiple-cursors
commit 6e159238b23005893d30185418ba4d50a5b221cd
Author: Magnar Sveen <magnars@gmail.com>
Commit: Magnar Sveen <magnars@gmail.com>
Use uninterned symbols in macros to avoid surprising local vars
---
multiple-cursors-core.el | 60 ++++++++++++++++++++++++++----------------------
1 file changed, 33 insertions(+), 27 deletions(-)
diff --git a/multiple-cursors-core.el b/multiple-cursors-core.el
index dc27687..26c8baa 100644
--- a/multiple-cursors-core.el
+++ b/multiple-cursors-core.el
@@ -41,13 +41,14 @@
(defmacro mc/add-fake-cursor-to-undo-list (&rest forms)
"Make sure point is in the right place when undoing"
- `(let ((undo-cleaner (cons 'apply (cons 'deactivate-cursor-after-undo (list
id)))))
- (setq buffer-undo-list (cons undo-cleaner buffer-undo-list))
- ,@forms
- (if (eq undo-cleaner (car buffer-undo-list)) ;; if nothing has been added
to the undo-list
- (setq buffer-undo-list (cdr buffer-undo-list)) ;; then pop the
cleaner right off again
- (setq buffer-undo-list ;; otherwise add a function to activate this
cursor
- (cons (cons 'apply (cons 'activate-cursor-for-undo (list id)))
buffer-undo-list)))))
+ (let ((uc (make-symbol "undo-cleaner")))
+ `(let ((,uc (cons 'apply (cons 'deactivate-cursor-after-undo (list id)))))
+ (setq buffer-undo-list (cons ,uc buffer-undo-list))
+ ,@forms
+ (if (eq ,uc (car buffer-undo-list)) ;; if nothing has been added to the
undo-list
+ (setq buffer-undo-list (cdr buffer-undo-list)) ;; then pop the
cleaner right off again
+ (setq buffer-undo-list ;; otherwise add a function to activate this
cursor
+ (cons (cons 'apply (cons 'activate-cursor-for-undo (list id)))
buffer-undo-list))))))
(defun mc/all-fake-cursors (&optional start end)
(remove-if-not 'mc/fake-cursor-p
@@ -61,35 +62,40 @@
(defmacro mc/save-excursion (&rest forms)
"Saves and restores all the state that multiple-cursors cares about."
- `(let ((current-state (mc/store-current-state-in-overlay
- (make-overlay (point) (point) nil nil t))))
- (overlay-put current-state 'type 'original-cursor)
- (save-excursion ,@forms)
- (mc/pop-state-from-overlay current-state)))
+ (let ((cs (make-symbol "current-state")))
+ `(let ((,cs (mc/store-current-state-in-overlay
+ (make-overlay (point) (point) nil nil t))))
+ (overlay-put ,cs 'type 'original-cursor)
+ (save-excursion ,@forms)
+ (mc/pop-state-from-overlay ,cs))))
(defun mc--compare-by-overlay-start (o1 o2)
(< (overlay-start o1) (overlay-start o2)))
(defmacro mc/for-each-cursor-ordered (&rest forms)
"Runs the body for each cursor, fake and real, bound to the name cursor"
- `(let ((real-cursor-id (overlay-get (mc/create-fake-cursor-at-point)
'mc-id)))
- (mapc #'(lambda (cursor)
- (when (mc/fake-cursor-p cursor)
- ,@forms))
- (sort (overlays-in (point-min) (point-max))
'mc--compare-by-overlay-start))
- (mc/pop-state-from-overlay (mc/cursor-with-id real-cursor-id))))
+ (let ((rci (make-symbol "real-cursor-id")))
+ `(let ((,rci (overlay-get (mc/create-fake-cursor-at-point) 'mc-id)))
+ (mapc #'(lambda (cursor)
+ (when (mc/fake-cursor-p cursor)
+ ,@forms))
+ (sort (overlays-in (point-min) (point-max))
'mc--compare-by-overlay-start))
+ (mc/pop-state-from-overlay (mc/cursor-with-id ,rci)))))
(defmacro mc/save-window-scroll (&rest forms)
"Saves and restores the window scroll position"
- `(let ((p (set-marker (make-marker) (point)))
- (start (set-marker (make-marker) (window-start)))
- (hscroll (window-hscroll)))
- ,@forms
- (goto-char p)
- (set-window-start nil start t)
- (set-window-hscroll nil hscroll)
- (set-marker p nil)
- (set-marker start nil)))
+ (let ((p (make-symbol "p"))
+ (s (make-symbol "start"))
+ (h (make-symbol "hscroll")))
+ `(let ((,p (set-marker (make-marker) (point)))
+ (,s (set-marker (make-marker) (window-start)))
+ (,h (window-hscroll)))
+ ,@forms
+ (goto-char ,p)
+ (set-window-start nil ,s t)
+ (set-window-hscroll nil ,h)
+ (set-marker ,p nil)
+ (set-marker ,s nil))))
(defun mc/make-cursor-overlay-at-eol (pos)
"Create overlay to look like cursor at end of line."
- [nongnu] elpa/multiple-cursors 60b9ef8 385/434: Updated readme according to `mc/always-run-for-all, (continued)
- [nongnu] elpa/multiple-cursors 60b9ef8 385/434: Updated readme according to `mc/always-run-for-all, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors ad95d28 386/434: Update docstring of `mc/cursor-is-bar`, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 21e4825 387/434: mc/mark-previous-like-this-word/symbol., ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 95f2e41 391/434: Add @AndreaOrru to list of contributors, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors e14fdb7 401/434: Merge pull request #298 from Quasilyte/update_readme, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 8172edd 417/434: Realign the file according to Elisp conventions, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors b9b851a 426/434: Merge pull request #358 from renatofdds/master, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 6a04a14 428/434: Fix docstrings, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 7b13b03 433/434: Add homepage, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 84ab4ee 196/434: Fix mc/dump-list (take 2): it looses old setting, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 6e15923 229/434: Use uninterned symbols in macros to avoid surprising local vars,
ELPA Syncer <=
- [nongnu] elpa/multiple-cursors cb848b2 239/434: Add @smithzvk to contributors list, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 6745142 250/434: Move from Carton to Cask, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors bf01772 230/434: Use phi-search for C-s in mc-mode when available., ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 186cb3b 255/434: Release 1.2.3, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors c94eca5 254/434: Fix broken let binding, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors d8c5227 268/434: Merge pull request #103 from mathrick/compat-24.2, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 239acbf 281/434: Skip folded lines with mc/edit-lines, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 5cd6ddf 293/434: Merge pull request #125 from kyanagi/fix-cycle-cursors-on-edge, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors d1ad51f 296/434: Gitignore *.elc, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors a3e6ec7 297/434: Merge pull request #135 from jistr/gitignore_elc, ELPA Syncer, 2021/08/07