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

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

[nongnu] elpa/symbol-overlay 72c35dadcc 087/152: wip: add support for ma


From: ELPA Syncer
Subject: [nongnu] elpa/symbol-overlay 72c35dadcc 087/152: wip: add support for major-mode dependent ignored keywords
Date: Thu, 7 Jul 2022 12:04:17 -0400 (EDT)

branch: elpa/symbol-overlay
commit 72c35dadccd8806afa88b416aabfde261d0a339c
Author: wouter bolsterlee <wouter@bolsterl.ee>
Commit: wouter bolsterlee <wouter@bolsterl.ee>

    wip: add support for major-mode dependent ignored keywords
    
    see #17.
---
 symbol-overlay.el | 60 +++++++++++++++++++++++++++++++++++++++----------------
 1 file changed, 43 insertions(+), 17 deletions(-)

diff --git a/symbol-overlay.el b/symbol-overlay.el
index f5b3af7009..3c82d25dd8 100644
--- a/symbol-overlay.el
+++ b/symbol-overlay.el
@@ -151,6 +151,17 @@ You can add more colors whatever you like."
   :group 'symbol-overlay
   :type 'float)
 
+(defcustom symbol-overlay-ignore-functions
+  '((python-mode . symbol-overlay--ignore-function-python))
+  "Functions to determine whether a symbol should be ignored.
+
+This is an association list that maps a MAJOR-MODE symbol to a
+function that determines whether a symbol should be ignored. For
+instance, such a function could use a major mode's font-lock
+definitions to prevent a language's keywords from getting highlighted."
+  :group 'symbol-overlay)
+;; todo: add :type
+
 (defvar symbol-overlay-map
   (let ((map (make-sparse-keymap)))
     (define-key map (kbd "i") 'symbol-overlay-put)
@@ -250,6 +261,12 @@ depending on SCOPE and WINDOW."
          (forward-line lines)
          (narrow-to-region beg (point)))))))
 
+(defun symbol-overlay--ignored-p (symbol)
+  "Determine whether SYMBOL should be temporarily highlighted."
+  (let ((f (cdr (assoc major-mode symbol-overlay-ignore-functions))))
+    (when f
+      (funcall f symbol))))
+
 (defun symbol-overlay-remove-temp ()
   "Delete all temporary overlays."
   (mapc 'delete-overlay (symbol-overlay-get-list ""))
@@ -259,23 +276,26 @@ depending on SCOPE and WINDOW."
   "Highlight symbol at point when there are more than 2 occurrences.
 This only effects symbols in the current displayed window."
   (when symbol-overlay-mode
-    (let ((case-fold-search nil)
-         (symbol (symbol-overlay-get-symbol nil t))
-         p)
-      (when (and symbol (not (symbol-overlay-assoc symbol)))
-       (symbol-overlay-remove-temp)
-       (save-excursion
-         (save-restriction
-           (symbol-overlay-narrow symbol-overlay-scope t)
-           (goto-char (point-min))
-           (re-search-forward symbol nil t)
-           (save-match-data
-             (while (re-search-forward symbol nil t)
-               (symbol-overlay-put-one symbol)
-               (or p (setq p t))))
-           (when p
-             (symbol-overlay-put-one symbol)
-             (setq symbol-overlay-temp-symbol symbol))))))))
+    (let* ((case-fold-search nil)
+           (symbol (symbol-overlay-get-symbol nil t))
+           (should-put-overlay (and symbol
+                                    (not (symbol-overlay-assoc symbol))
+                                    (not (symbol-overlay--ignored-p symbol))))
+           p)
+      (when should-put-overlay
+        (symbol-overlay-remove-temp)
+        (save-excursion
+          (save-restriction
+            (symbol-overlay-narrow symbol-overlay-scope t)
+            (goto-char (point-min))
+            (re-search-forward symbol nil t)
+            (save-match-data
+              (while (re-search-forward symbol nil t)
+                (symbol-overlay-put-one symbol)
+                (or p (setq p t))))
+            (when p
+              (symbol-overlay-put-one symbol)
+              (setq symbol-overlay-temp-symbol symbol))))))))
 
 (defvar symbol-overlay-timer nil
   "Timer for temporary highlighting.")
@@ -346,6 +366,12 @@ If SHOW-COLOR is non-nil, display the color used by 
current overlay."
               (+ count 1)
               (+ count (length after))))))
 
+
+(defvar python-font-lock-keywords)
+(defun symbol-overlay--ignore-function-python (symbol)
+  "Determine whether SYMBOL should be ignored (Python)."
+  (string-match-p (car python-font-lock-keywords) symbol))
+
 ;;;###autoload
 (defun symbol-overlay-put ()
   "Toggle all overlays of symbol at point."



reply via email to

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