[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/symbol-overlay 08a6f3d732 035/152: (v3.2) better way to co
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/symbol-overlay 08a6f3d732 035/152: (v3.2) better way to count and filter overlays |
Date: |
Thu, 7 Jul 2022 12:04:10 -0400 (EDT) |
branch: elpa/symbol-overlay
commit 08a6f3d7321a25dff22f5459964a91c0824ea310
Author: wolray <290061869@qq.com>
Commit: wolray <290061869@qq.com>
(v3.2) better way to count and filter overlays
---
symbol-overlay.el | 57 +++++++++++++++++++++++++------------------------------
1 file changed, 26 insertions(+), 31 deletions(-)
diff --git a/symbol-overlay.el b/symbol-overlay.el
index 54a9c911b0..1fc2ea2991 100644
--- a/symbol-overlay.el
+++ b/symbol-overlay.el
@@ -3,7 +3,7 @@
;; Copyright (C) 2017 wolray
;; Author: wolray <wolray@foxmail.com>
-;; Version: 3.1
+;; Version: 3.2
;; URL: https://github.com/wolray/symbol-overlay/
;; Keywords: faces, matching
;; Package-Requires: ((emacs "24.3"))
@@ -105,18 +105,20 @@ You can re-bind the commands to any keys you prefer.")
"Colors used for overlays' background.
You can add more colors whatever you like.")
-(defun symbol-overlay-get-list (&optional symbol exclude)
+(defun symbol-overlay-get-list (&optional symbol car-or-cdr exclude)
"Get all highlighted overlays in the buffer.
If SYMBOL is non-nil, get the overlays that belong to it.
+CAR-OR-CDR must a symbol whose value is 'car or 'cdr, if not nil.
If EXCLUDE is non-nil, get all overlays excluding those belong to SYMBOL."
- (let ((list (overlay-lists)))
+ (let ((lists (or (overlay-recenter (point)) (overlay-lists))))
(seq-filter
'(lambda (overlay)
(let ((value (overlay-get overlay 'symbol)))
(and value
(or (not symbol)
(if (string= value symbol) (not exclude) exclude)))))
- (append (car list) (cdr list)))))
+ (if car-or-cdr (funcall car-or-cdr lists)
+ (append (car lists) (cdr lists))))))
(defun symbol-overlay-get-symbol (&optional string noerror)
"Get the symbol at point.
@@ -199,17 +201,15 @@ If KEYWORD is non-nil, remove it and use its color for
new overlays."
"Show the number of KEYWORD's occurrences.
If SCOPE is non-nil, display an \"in scope\" message.
If SHOW-COLOR is non-nil, display the color used by current overlay."
- (let ((symbol (car keyword))
- (pt (point))
- list prev)
- (setq list (symbol-overlay-get-list symbol)
- prev (seq-filter '(lambda (overlay) (<= (overlay-start overlay) pt))
- list))
+ (let* ((symbol (car keyword))
+ (before (symbol-overlay-get-list symbol 'car))
+ (after (symbol-overlay-get-list symbol 'cdr))
+ (count (length before)))
(message (concat (substring symbol 3 -3) ": %d/%d"
(and (cadr keyword) " in scope")
(and show-color (format " (%s)" (cddr keyword))))
- (length prev)
- (length list))))
+ (+ count 1)
+ (+ count (length after)))))
;;;###autoload
(defun symbol-overlay-put ()
@@ -218,8 +218,8 @@ If SHOW-COLOR is non-nil, display the color used by current
overlay."
(unless (minibufferp)
(let ((symbol (symbol-overlay-get-symbol)))
(or (symbol-overlay-remove (symbol-overlay-assoc symbol t))
- (symbol-overlay-count (symbol-overlay-put-all symbol) t))
- (and (looking-at-p "\\_>") (backward-char)))))
+ (and (looking-at-p "\\_>") (backward-char))
+ (symbol-overlay-count (symbol-overlay-put-all symbol) t)))))
;;;###autoload
(defun symbol-overlay-toggle-in-scope ()
@@ -331,19 +331,14 @@ with the input symbol."
"Switch to the closest symbol highlighted nearby, in the direction DIR.
DIR must be 1 or -1."
(unless (minibufferp)
- (let ((symbol (symbol-overlay-get-symbol nil t))
- (pt (point))
- list begs)
- (setq list (symbol-overlay-get-list symbol t)
- begs (seq-filter
- '(lambda (x) (> (* dir (- x pt)) 0))
- (mapcar 'overlay-start list)))
- (unless begs
+ (let* ((symbol (symbol-overlay-get-symbol nil t))
+ (list (symbol-overlay-get-list symbol (if (> dir 0) 'cdr 'car) t)))
+ (unless list
(user-error (concat "No more "
(if (> dir 0) "forward" "backward")
" symbols")))
(setq symbol-overlay-mark (point))
- (goto-char (funcall (if (> dir 0) 'seq-min 'seq-max) begs))
+ (goto-char (overlay-start (car list)))
(symbol-overlay-count
(symbol-overlay-assoc (symbol-overlay-get-symbol))))))
@@ -364,7 +359,6 @@ DIR must be 1 or -1."
If COUNT is non-nil, count at the end."
(unless (minibufferp)
(let* ((case-fold-search nil)
- (inhibit-modification-hooks t)
(symbol (symbol-overlay-get-symbol))
(keyword (symbol-overlay-assoc symbol))
(scope (cadr keyword))
@@ -386,14 +380,14 @@ If COUNT is non-nil, count at the end."
(interactive)
(symbol-overlay-replace-call
'(lambda (symbol new scope)
- (let (defaults)
- (and scope (user-error "Query replace is invalid in scope"))
- (setq new (read-string "Replacement: ")
- defaults (cons symbol new))
+ (and scope (user-error "Query replace is invalid in scope"))
+ (setq new (read-string "Replacement: "))
+ (let ((inhibit-modification-hooks t)
+ (defaults (cons symbol new)))
(query-replace-regexp symbol new)
(setq query-replace-defaults
- (if (< emacs-major-version 25) `,defaults `(,defaults)))
- (symbol-overlay-get-symbol new)))))
+ (if (< emacs-major-version 25) `,defaults `(,defaults))))
+ (symbol-overlay-get-symbol new))))
;;;###autoload
(defun symbol-overlay-rename ()
@@ -408,7 +402,8 @@ If COUNT is non-nil, count at the end."
(save-restriction
(symbol-overlay-narrow scope)
(goto-char (point-min))
- (while (re-search-forward symbol nil t) (replace-match new))))
+ (let ((inhibit-modification-hooks t))
+ (while (re-search-forward symbol nil t) (replace-match new)))))
(symbol-overlay-get-symbol new))))
(defun symbol-overlay-refresh (beg end len)
- [nongnu] elpa/symbol-overlay 914fffc8e5 140/152: fixup! fixup! add symbol-overlay-ignore-function-clojure, (continued)
- [nongnu] elpa/symbol-overlay 914fffc8e5 140/152: fixup! fixup! add symbol-overlay-ignore-function-clojure, ELPA Syncer, 2022/07/07
- [nongnu] elpa/symbol-overlay ca3b02c99e 136/152: When highlighting, check current buffer is the one in selected-window, ELPA Syncer, 2022/07/07
- [nongnu] elpa/symbol-overlay 5bcd6d7e3f 143/152: Revert "Merge pull request #71 from mpenet/feat/add-clojure-kw-list", ELPA Syncer, 2022/07/07
- [nongnu] elpa/symbol-overlay 22686cddc3 126/152: Merge pull request #55 from tarsiiformes/inhibit-map, ELPA Syncer, 2022/07/07
- [nongnu] elpa/symbol-overlay 29e50c7c2e 139/152: fixup! add symbol-overlay-ignore-function-clojure, ELPA Syncer, 2022/07/07
- [nongnu] elpa/symbol-overlay 07119d9c95 151/152: Make the timer function only affect the current buffer, ELPA Syncer, 2022/07/07
- [nongnu] elpa/symbol-overlay 3fd1607725 022/152: (v2.5) a totally new architecture, ELPA Syncer, 2022/07/07
- [nongnu] elpa/symbol-overlay 368af27599 029/152: fix the image, ELPA Syncer, 2022/07/07
- [nongnu] elpa/symbol-overlay f4fac7d541 030/152: fix the image, ELPA Syncer, 2022/07/07
- [nongnu] elpa/symbol-overlay fdb432babd 034/152: (v3.1) add narrow-function, ELPA Syncer, 2022/07/07
- [nongnu] elpa/symbol-overlay 08a6f3d732 035/152: (v3.2) better way to count and filter overlays,
ELPA Syncer <=
- [nongnu] elpa/symbol-overlay e288067203 039/152: fix documentation and code style, ELPA Syncer, 2022/07/07
- [nongnu] elpa/symbol-overlay 191d07ec35 001/152: (init 1.0), ELPA Syncer, 2022/07/07
- [nongnu] elpa/symbol-overlay 3bbbd22852 002/152: (so-overlay-map) (major-version), ELPA Syncer, 2022/07/07
- [nongnu] elpa/symbol-overlay 8330423db6 005/152: add readme.md, ELPA Syncer, 2022/07/07
- [nongnu] elpa/symbol-overlay 331b14542c 004/152: rename so-keywords to so-keywords-alist, ELPA Syncer, 2022/07/07
- [nongnu] elpa/symbol-overlay 188df4744b 007/152: after auot-insert, ELPA Syncer, 2022/07/07
- [nongnu] elpa/symbol-overlay 4da9d67578 008/152: edit the summary, ELPA Syncer, 2022/07/07
- [nongnu] elpa/symbol-overlay e31bbd140a 011/152: Fix some typos, ELPA Syncer, 2022/07/07
- [nongnu] elpa/symbol-overlay 8b4e26db1c 014/152: Fix the prefix errors, ELPA Syncer, 2022/07/07
- [nongnu] elpa/symbol-overlay 4cf1d3c0d2 024/152: better auto-refresh, ELPA Syncer, 2022/07/07