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

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

[nongnu] elpa/symbol-overlay 6c7ec584b6 074/152: 170826


From: ELPA Syncer
Subject: [nongnu] elpa/symbol-overlay 6c7ec584b6 074/152: 170826
Date: Thu, 7 Jul 2022 12:04:16 -0400 (EDT)

branch: elpa/symbol-overlay
commit 6c7ec584b62b7922a5398a552a1bf60f8144306c
Author: wolray <290061869@qq.com>
Commit: wolray <290061869@qq.com>

    170826
---
 readme.md         | 11 +++++++++
 symbol-overlay.el | 74 +++++++++++++++++++++++++++++++++----------------------
 2 files changed, 55 insertions(+), 30 deletions(-)

diff --git a/readme.md b/readme.md
index 9d42a985ac..354c0e94b5 100644
--- a/readme.md
+++ b/readme.md
@@ -9,6 +9,10 @@ Highlight symbols with overlays while providing a keymap for 
various operations
 What's New!
 ---
 
+### 20170826:
+
+`symbol-overlay-toggle-in-scope` now affects both global and in-scope 
highlighting. `symbol-overlay-rename` now uses the original symbol name as the 
initial text in minibuffer. New command `symbol-overlay-count` for counting 
symbol at point. And other improvements.
+
 ### 20170426:
 
 Minor-mode `symbol-overlay-mode` for auto-highlighting is now enabled.
@@ -81,3 +85,10 @@ Default key-bindings defined in `symbol-overlay-map`:
 You can re-bind the commands to any keys you prefer by simply writing
 
     (define-key symbol-overlay-map (kbd "your-prefer-key") 'any-command)
+
+Or you may prefer to overwrite the keymap
+
+    (let ((map (make-sparse-keymap)))
+      (define-key map (kbd "key1") 'command-1)
+      (define-key map (kbd "key2") 'command-2)
+      (setq symbol-overlay-map map))
diff --git a/symbol-overlay.el b/symbol-overlay.el
index a15d5361bc..e986e71609 100644
--- a/symbol-overlay.el
+++ b/symbol-overlay.el
@@ -156,7 +156,7 @@ If NOERROR is non-nil, just return nil when no symbol is 
found."
   "Get SYMBOL's associated list in `symbol-overlay-keywords-alist'."
   (assoc symbol symbol-overlay-keywords-alist))
 
-(defun symbol-overlay-remove (keyword)
+(defun symbol-overlay-maybe-remove (keyword)
   "Delete the KEYWORD list and all its overlays."
   (when keyword
     (mapc 'delete-overlay (symbol-overlay-get-list (car keyword)))
@@ -172,7 +172,7 @@ If NOERROR is non-nil, just return nil when no symbol is 
found."
 
 (defun symbol-overlay-narrow (scope &optional window)
   "Narrow to a specific region.
-Region might be current scope or displayed window or a specific one,
+Region might be current scope or displayed window,
 depending on SCOPE and WINDOW."
   (if scope
       (let ((pt (point))
@@ -207,7 +207,7 @@ depending on SCOPE and WINDOW."
   (mapc 'delete-overlay (symbol-overlay-get-list ""))
   (setq symbol-overlay-temp-symbol nil))
 
-(defun symbol-overlay-put-temp ()
+(defun symbol-overlay-maybe-put-temp ()
   "Highlight symbol at point when there are more than 2 occurrences.
 This only effects symbols in the current displayed window."
   (when symbol-overlay-mode
@@ -237,7 +237,7 @@ This only effects symbols in the current displayed window."
   (and symbol-overlay-timer (cancel-timer symbol-overlay-timer))
   (setq symbol-overlay-timer
        (and value (> value 0)
-            (run-with-idle-timer value t 'symbol-overlay-put-temp))))
+            (run-with-idle-timer value t 'symbol-overlay-maybe-put-temp))))
 
 (defun symbol-overlay-post-command ()
   "Installed on `post-command-hook'."
@@ -264,7 +264,7 @@ If SCOPE is non-nil, put overlays only on occurrences in 
scope.
 If KEYWORD is non-nil, remove it then use its color on new overlays."
   (let* ((case-fold-search nil)
         (limit (length symbol-overlay-colors))
-        (color (or (symbol-overlay-remove keyword)
+        (color (or (symbol-overlay-maybe-remove keyword)
                    (elt symbol-overlay-colors (random limit))))
         (alist symbol-overlay-keywords-alist)
         (colors (mapcar 'cddr alist))
@@ -272,7 +272,7 @@ If KEYWORD is non-nil, remove it then use its color on new 
overlays."
     (if (< (length alist) limit)
        (while (seq-position colors color)
          (setq color (elt symbol-overlay-colors (random limit))))
-      (setq color (symbol-overlay-remove (car (last alist)))))
+      (setq color (symbol-overlay-maybe-remove (car (last alist)))))
     (and symbol-overlay-temp-symbol (symbol-overlay-remove-temp))
     (save-excursion
       (save-restriction
@@ -284,7 +284,7 @@ If KEYWORD is non-nil, remove it then use its color on new 
overlays."
     (push keyword symbol-overlay-keywords-alist)
     keyword))
 
-(defun symbol-overlay-count (keyword &optional show-color)
+(defun symbol-overlay-maybe-count (keyword &optional show-color)
   "Show the number of KEYWORD's occurrences.
 If SHOW-COLOR is non-nil, display the color used by current overlay."
   (when keyword
@@ -308,14 +308,23 @@ If SHOW-COLOR is non-nil, display the color used by 
current overlay."
           (keyword (symbol-overlay-assoc symbol)))
       (if keyword
           (if (symbol-overlay-maybe-reput symbol keyword)
-              (symbol-overlay-count keyword)
-           (symbol-overlay-remove keyword)
-           (symbol-overlay-put-temp))
+              (symbol-overlay-maybe-count keyword)
+           (symbol-overlay-maybe-remove keyword)
+           (symbol-overlay-maybe-put-temp))
        (and (looking-at-p "\\_>") (backward-char))
-       (symbol-overlay-count
+       (symbol-overlay-maybe-count
          (symbol-overlay-put-all symbol symbol-overlay-scope)
          t)))))
 
+;;;###autoload
+(defun symbol-overlay-count ()
+  "Show count of symbol at point."
+  (interactive)
+  (unless (minibufferp)
+    (let* ((symbol (symbol-overlay-get-symbol))
+          (keyword (symbol-overlay-assoc symbol)))
+      (symbol-overlay-maybe-count keyword))))
+
 ;;;###autoload
 (defun symbol-overlay-remove-all ()
   "Remove all highlighted symbols in the buffer."
@@ -344,24 +353,29 @@ If SHOW-COLOR is non-nil, display the color used by 
current overlay."
           (keyword (symbol-overlay-assoc symbol)))
       (if keyword
           (let ((scope (not (cadr keyword))))
-            (symbol-overlay-count (symbol-overlay-put-all symbol scope 
keyword))
+            (symbol-overlay-maybe-count (symbol-overlay-put-all symbol scope 
keyword))
             (setq symbol-overlay-scope scope))
         (setq symbol-overlay-scope (not symbol-overlay-scope))))))
 
-(defun symbol-overlay-maybe-reput (&optional symbol keyword)
-  (let* ((symbol (or symbol (symbol-overlay-get-symbol)))
-         (keyword (or keyword (symbol-overlay-assoc symbol))))
-    (unless (seq-find #'(lambda (ov)
-                          (string= (overlay-get ov 'symbol) symbol))
-                      (overlays-at (car (bounds-of-thing-at-point 'symbol))))
-      (symbol-overlay-put-all symbol t keyword))))
+(defun symbol-overlay-maybe-reput (symbol keyword)
+  "Put overlays on SYMBOL that is not highlighted in scope.
+KEYWORD provides the scope information."
+  (when (and (cadr keyword)
+             (not (seq-find #'(lambda (ov)
+                                (string= (overlay-get ov 'symbol) symbol))
+                            (overlays-at
+                             (car (bounds-of-thing-at-point 'symbol))))))
+    (symbol-overlay-put-all symbol t keyword)))
 
 ;;;###autoload
 (defun symbol-overlay-echo-mark ()
   "Jump back to the mark."
   (interactive)
-  (let ((pt (mark))) (and pt (goto-char pt)))
-  (symbol-overlay-maybe-reput))
+  (let* ((pt (mark))
+         (symbol (symbol-overlay-get-symbol))
+         (keyword (symbol-overlay-assoc symbol)))
+    (and pt (goto-char pt))
+    (symbol-overlay-maybe-reput symbol keyword)))
 
 (defun symbol-overlay-jump-call (jump-function dir)
   "A general jumping process during which JUMP-FUNCTION is called to jump.
@@ -374,9 +388,8 @@ DIR must be 1 or -1."
       (if keyword
           (progn
             (symbol-overlay-maybe-reput symbol keyword)
-            (symbol-overlay-count keyword))
-        (symbol-overlay-mode)
-        (symbol-overlay-put-temp)))))
+            (symbol-overlay-maybe-count keyword))
+        (symbol-overlay-mode)))))
 
 (defun symbol-overlay-basic-jump (symbol dir)
   "Jump to SYMBOL's next location in the direction DIR.  DIR must be 1 or -1."
@@ -440,7 +453,7 @@ DIR must be 1 or -1."
                              " symbols")))
       (push-mark nil t)
       (goto-char (overlay-start (car list)))
-      (symbol-overlay-count
+      (symbol-overlay-maybe-count
        (symbol-overlay-assoc (symbol-overlay-get-symbol))))))
 
 ;;;###autoload
@@ -482,14 +495,14 @@ DIR must be 1 or -1."
            new (symbol-overlay-get-symbol txt)
            defaults (cons symbol txt))
       (unless (string= new symbol)
-       (symbol-overlay-remove (symbol-overlay-assoc new))
+       (symbol-overlay-maybe-remove (symbol-overlay-assoc new))
        (setq keyword (symbol-overlay-put-all new scope keyword))
        (query-replace-regexp symbol txt)
        (setq query-replace-defaults
              (if (< emacs-major-version 25) `,defaults `(,defaults))))
       (when (string= new (symbol-overlay-get-symbol nil t))
        (beginning-of-thing 'symbol)
-       (symbol-overlay-count keyword)))))
+       (symbol-overlay-maybe-count keyword)))))
 
 ;;;###autoload
 (defun symbol-overlay-rename ()
@@ -503,10 +516,11 @@ DIR must be 1 or -1."
           txt new)
       (beginning-of-thing 'symbol)
       (push-mark nil t)
-      (setq txt (read-string (concat "Rename" (and scope " in scope") ": "))
+      (setq txt (read-string (concat "Rename" (and scope " in scope") ": ")
+                             (substring symbol 3 -3))
            new (symbol-overlay-get-symbol txt))
       (unless (string= new symbol)
-       (symbol-overlay-remove (symbol-overlay-assoc new))
+       (symbol-overlay-maybe-remove (symbol-overlay-assoc new))
        (save-excursion
          (save-restriction
            (symbol-overlay-narrow scope)
@@ -515,7 +529,7 @@ DIR must be 1 or -1."
              (while (re-search-forward symbol nil t) (replace-match txt t)))))
        (setq keyword (symbol-overlay-put-all new scope keyword)))
       (when (string= new (symbol-overlay-get-symbol nil t))
-       (symbol-overlay-count keyword)))))
+       (symbol-overlay-maybe-count keyword)))))
 
 (defun symbol-overlay-refresh (beg end len)
   "Refresh overlays.  Installed on `after-change-functions'.



reply via email to

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