[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/symbol-overlay 8b4e26db1c 014/152: Fix the prefix errors
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/symbol-overlay 8b4e26db1c 014/152: Fix the prefix errors |
Date: |
Thu, 7 Jul 2022 12:04:07 -0400 (EDT) |
branch: elpa/symbol-overlay
commit 8b4e26db1c45abb5f04daae30094811743c77a0e
Author: wolray <290061869@qq.com>
Commit: wolray <290061869@qq.com>
Fix the prefix errors
---
readme.md | 22 +++----
symbol-overlay.el | 185 +++++++++++++++++++++++++++---------------------------
2 files changed, 103 insertions(+), 104 deletions(-)
diff --git a/readme.md b/readme.md
index b823e6b233..0c8653488b 100644
--- a/readme.md
+++ b/readme.md
@@ -6,30 +6,30 @@ Advantages
---
- In `symbol-overlay`, `overlay-put` is much faster than the traditional
highligting method `font-lock-fontify-buffer`, especially in a large buffer or
even a less-than-100-lines small buffer of major-mode with complicated keywords
syntax such as haskell-mode.
- More importantly, using `overlay-put` to highlight symbols has a significant
benefit to enabling **AN AUTO-ACTIVATED OVERLAY-INSIDE KEYMAP** for quick jump
and other useful commands.
-- You can also jump to a symbol's definition from any occurrence by using
`so-jump-to-def`, as long as the syntax of the definition is specified in the
buffer-local variable `so-def-function`.
-- All the overlays of each symbol are stored sequentially in an alist
`so-keywords-alist`. By simply getting the current overlay's index in the
corresponding keyword-list as well as the length of it in the alist, the number
of occurrences can be immediately obtained. While in `highlight-symbol`, this
would call the function `how-many` twice, causing extra costs.
+- You can also jump to a symbol's definition from any occurrence by using
`symbol-overlay-jump-to-definition`, as long as the syntax of the definition is
specified in the buffer-local variable `symbol-overlay-definition-function`.
+- All the overlays of each symbol are stored sequentially in an alist
`symbol-overlay-keywords-alist`. By simply getting the current overlay's index
in the corresponding keyword-list as well as the length of it in the alist, the
number of occurrences can be immediately obtained. While in `highlight-symbol`,
this would call the function `how-many` twice, causing extra costs.
Usage
---
To use `symbol-overlay` in your Emacs, you need only to bind one key:
(require 'symbol-overlay)
- (global-set-key (kbd "M-i") 'so-put)
+ (global-set-key (kbd "M-i") 'symbol-overlay-put)
-A keymap `so-overlay-map` is already defined in the package:
+A keymap `symbol-overlay-map` is already defined in the package:
-"i" -> `so-put` : Toggle overlays of all occurrences of symbol at point.
+"i" -> `symbol-overlay-put` : Toggle overlays of all occurrences of symbol at
point.
-"u" -> `so-jump-prev` : Jump to the previous location of symbol at point.
+"u" -> `symbol-overlay-jump-prev` : Jump to the previous location of symbol at
point.
-"o" -> `so-jump-next` : Jump to the next location of symbol at point.
+"o" -> `symbol-overlay-jump-next` : Jump to the next location of symbol at
point.
-"k" -> `so-remove-all` : Delete all highlighted symbols in the buffer.
+"k" -> `symbol-overlay-remove-all` : Delete all highlighted symbols in the
buffer.
-"d" -> `so-jump-to-def` : Jump to the definition of symbol at point.
+"d" -> `symbol-overlay-jump-to-definition` : Jump to the definition of symbol
at point.
-"q" -> `so-query-replace` : Command for query-replacing symbol at point.
+"q" -> `symbol-overlay-query-replace` : Command for query-replacing symbol at
point.
You can customize the keymap by writing
- (define-key so-overlay-map (kbd "your-prefer-key") 'any-command)
+ (define-key symbol-overlay-map (kbd "your-prefer-key") 'any-command)
diff --git a/symbol-overlay.el b/symbol-overlay.el
index 8286153246..91042f9167 100644
--- a/symbol-overlay.el
+++ b/symbol-overlay.el
@@ -24,8 +24,8 @@
;; Highlighting symbol while enabling you to jump from one occurrence to
another
;; or directly to the definition of that symbol in the buffer, with A SINGLE
-;; KEYSTROKE. It was originally inspired by the package `highlight-symbol'. The
-;; difference is that every symbol in `symbol-overlay' is highlighted by the
+;; KEYSTROKE. It was originally inspired by the package `highlight-symbol'.
+;; The difference is that every symbol in `symbol-overlay' is highlighted by
the
;; Emacs built-in function `overlay-put' rather than the `font-lock' mechanism
;; used in `highlight-symbol'.
@@ -41,13 +41,14 @@
;; and other useful commands.
;; You can also jump to a symbol's definition from any occurrence by
-;; using `so-jump-to-def', as long as the syntax of the definition is specified
-;; in the buffer-local variable `so-def-function'.
+;; using `symbol-overlay-jump-to-definition', as long as the syntax of the
+;; definition is specified in the buffer-local variable
+;; `symbol-overlay-definition-function'.
;; All the overlays of each symbol are stored sequentially in an alist
-;; `so-keywords-alist'. By simply getting the current overlay's index in the
-;; corresponding keyword-list as well as the length of it in the alist, the
-;; number of occurrences can be immediately obtained. While in
+;; `symbol-overlay-keywords-alist'. By simply getting the current overlay's
+;; index in the corresponding keyword-list as well as the length of it in the
+;; alist,the number of occurrences can be immediately obtained. While in
;; `highlight-symbol', this would call the function `how-many' twice, causing
;; extra costs.
@@ -55,65 +56,65 @@
;; To use `symbol-overlay' in your Emacs, you need only to bind one key:
;; (require 'symbol-overlay)
-;; (global-set-key (kbd "M-i") 'so-put)
+;; (global-set-key (kbd "M-i") 'symbol-overlay-put)
;;; Code:
(require 'thingatpt)
(require 'cl-lib)
-(defvar so-overlay-map
+(defvar symbol-overlay-map
(let ((map (make-sparse-keymap)))
- (define-key map (kbd "i") 'so-put)
- (define-key map (kbd "u") 'so-jump-prev)
- (define-key map (kbd "o") 'so-jump-next)
- (define-key map (kbd "k") 'so-remove-all)
- (define-key map (kbd "d") 'so-jump-to-def)
- (define-key map (kbd "q") 'so-query-replace)
+ (define-key map (kbd "i") 'symbol-overlay-put)
+ (define-key map (kbd "u") 'symbol-overlay-jump-prev)
+ (define-key map (kbd "o") 'symbol-overlay-jump-next)
+ (define-key map (kbd "k") 'symbol-overlay-remove-all)
+ (define-key map (kbd "d") 'symbol-overlay-jump-to-definition)
+ (define-key map (kbd "q") 'symbol-overlay-query-replace)
map)
"Keymap automatically activated inside overlays.
You can re-bind the commands to any keys you prefer.")
-(defvar so-keywords-alist)
-(make-variable-buffer-local 'so-keywords-alist)
-
-(defvar so-colors '("dodger blue"
- "hot pink"
- "orange"
- "orchid"
- "red"
- "salmon"
- "spring green"
- "turquoise")
+(defvar symbol-overlay-keywords-alist)
+(make-variable-buffer-local 'symbol-overlay-keywords-alist)
+
+(defvar symbol-overlay-colors '("dodger blue"
+ "hot pink"
+ "orange"
+ "orchid"
+ "red"
+ "salmon"
+ "spring green"
+ "turquoise")
"Colors used for overlays' background.")
-(defvar so-def-function
+(defvar symbol-overlay-definition-function
'(lambda (symbol) (concat "(?def[a-z-]* " symbol))
"It must be an one-argument lambda function that returns a regexp.")
-(make-variable-buffer-local 'so-def-function)
+(make-variable-buffer-local 'symbol-overlay-definition-function)
-(defun so-get-s (&optional str)
- "Get the symbol at point, if none, return nil. If STR is non-nil,
-`regexp-quote' STR rather than the symbol."
+(defun symbol-overlay-get-symbol (&optional str)
+ "Get the symbol at point, if none, return nil.
+If STR is non-nil, `regexp-quote' STR rather than the symbol."
(let ((symbol (or str (thing-at-point 'symbol))))
(if symbol (concat "\\_<" (regexp-quote symbol) "\\_>")
(user-error "No symbol at point"))))
-(defun so-put-s (symbol)
- "Put overlay to all occurrences of SYMBOL in the buffer, using a random
-background color from `so-colors'."
+(defun symbol-overlay-put-overlay (symbol)
+ "Put overlay to all occurrences of SYMBOL in the buffer.
+The background color is randomly picked from `symbol-overlay-colors'."
(let* ((case-fold-search nil)
- (limit (length so-colors))
+ (limit (length symbol-overlay-colors))
(index (random limit))
- (indexes (mapcar 'cadr so-keywords-alist))
+ (indexes (mapcar 'cadr symbol-overlay-keywords-alist))
keyword color face overlay)
- (if (< (length so-keywords-alist) limit)
+ (if (< (length symbol-overlay-keywords-alist) limit)
(while (cl-find index indexes) (setq index (random limit)))
- (let ((oldest-keyword (car (last so-keywords-alist))))
- (so-remove-s (car oldest-keyword))
+ (let ((oldest-keyword (car (last symbol-overlay-keywords-alist))))
+ (symbol-overlay-remove (car oldest-keyword))
(setq index (cadr oldest-keyword))))
(setq keyword `(,symbol ,index)
- color (elt so-colors index)
+ color (elt symbol-overlay-colors index)
face `((foreground-color . "black")
(background-color . ,color)))
(save-excursion
@@ -122,16 +123,16 @@ background color from `so-colors'."
(setq overlay (make-overlay (match-beginning 0) (match-end 0))
keyword (append keyword `(,overlay)))
(overlay-put overlay 'face face)
- (overlay-put overlay 'keymap so-overlay-map)))
- (push keyword so-keywords-alist)
+ (overlay-put overlay 'keymap symbol-overlay-map)))
+ (push keyword symbol-overlay-keywords-alist)
color))
-(defun so-count-s (symbol &optional color-msg)
- "Show the number of occurrences of SYMBOL. If COLOR-MSG is non-nil, add the
-color used by current overlay in brackets."
+(defun symbol-overlay-count (symbol &optional color-msg)
+ "Show the number of occurrences of SYMBOL.
+If COLOR-MSG is non-nil, add the color used by current overlay in brackets."
(let ((case-fold-search nil)
- (keyword (assoc symbol so-keywords-alist))
- overlay)
+ (keyword (assoc symbol symbol-overlay-keywords-alist))
+ overlay)
(when keyword
(setq overlay (car (overlays-at (point))))
(when (stringp color-msg) (setq color-msg (concat " (" color-msg ")")))
@@ -140,71 +141,74 @@ color used by current overlay in brackets."
(- (length keyword) 2)))))
;;;###autoload
-(defun so-put ()
+(defun symbol-overlay-put ()
"Toggle overlays of all occurrences of symbol at point."
(interactive)
(unless (minibufferp)
- (let ((symbol (so-get-s)))
- (if (assoc symbol so-keywords-alist) (so-remove-s symbol)
+ (let ((symbol (symbol-overlay-get-symbol)))
+ (if (assoc symbol symbol-overlay-keywords-alist)
+ (symbol-overlay-remove symbol)
(when (looking-at-p "\\_>") (backward-char))
- (so-count-s symbol (so-put-s symbol))))))
+ (symbol-overlay-count symbol (symbol-overlay-put-overlay symbol))))))
;;;###autoload
-(defun so-remove-all ()
+(defun symbol-overlay-remove-all ()
"Delete all highlighted symbols in the buffer."
(interactive)
(unless (minibufferp)
- (mapc 'so-remove-s (mapcar 'car so-keywords-alist))))
+ (mapc 'symbol-overlay-remove (mapcar 'car symbol-overlay-keywords-alist))))
-(defun so-remove-s (symbol)
+(defun symbol-overlay-remove (symbol)
"Delete the highlighted SYMBOL."
- (let ((keyword (assoc symbol so-keywords-alist)))
- (setq so-keywords-alist (delq keyword so-keywords-alist))
+ (let ((keyword (assoc symbol symbol-overlay-keywords-alist)))
+ (setq symbol-overlay-keywords-alist
+ (delq keyword symbol-overlay-keywords-alist))
(mapc 'delete-overlay (cddr keyword))))
;;;###autoload
-(defun so-jump-next ()
+(defun symbol-overlay-jump-next ()
"Jump to the next location of symbol at point."
(interactive)
- (so-jump-call 'so-jump-s))
+ (symbol-overlay-jump-call 'symbol-overlay-basic-jump))
;;;###autoload
-(defun so-jump-prev ()
+(defun symbol-overlay-jump-prev ()
"Jump to the previous location of symbol at point."
(interactive)
- (so-jump-call 'so-jump-s t))
+ (symbol-overlay-jump-call 'symbol-overlay-basic-jump -1))
;;;###autoload
-(defun so-jump-to-def ()
- "Jump to the definition of symbol at point. The definition syntax should be
-defined in a lambda funtion stored in `so-def-function' that will return the
-definition's regexp with the input symbol."
+(defun symbol-overlay-jump-to-definition ()
+ "Jump to the definition of symbol at point.
+The definition syntax should be defined in a lambda funtion stored in
+`symbol-overlay-definition-function' that will return the definition's regexp
+with the input symbol."
(interactive)
- (so-jump-call
+ (symbol-overlay-jump-call
'(lambda (symbol dir)
(let ((p t) (pt (point)))
- (so-jump-s symbol dir)
+ (symbol-overlay-basic-jump symbol dir)
(while (and p (not (save-excursion
(beginning-of-line)
(skip-chars-forward " \t")
(looking-at-p
- (funcall so-def-function symbol)))))
- (so-jump-s symbol dir)
+ (funcall symbol-overlay-definition-function
+ symbol)))))
+ (symbol-overlay-basic-jump symbol dir)
(when (= pt (point)) (setq p nil)))))))
-(defun so-jump-call (jump-function &optional back)
- "A general jumping process during which JUMP-FUNCTION is called to jump to a
-nearby occurrence or the definition of the symbol. If BACK is non-nil, reverse
-the jumping direction."
+(defun symbol-overlay-jump-call (jump-function &optional dir)
+ "A general jumping process during which JUMP-FUNCTION is called to jump.
+If optional argument DIR is non-nil, use it rather than the default value 1."
(unless (minibufferp)
- (let ((symbol (so-get-s)))
+ (let ((symbol (symbol-overlay-get-symbol)))
(setq mark-active nil)
- (funcall jump-function symbol (if back -1 1))
+ (funcall jump-function symbol (or dir 1))
(push-mark nil t)
- (so-count-s symbol))))
+ (symbol-overlay-count symbol))))
-(defun so-jump-s (symbol dir)
- "Jump to SYMBOL's next location in the direction DIR."
+(defun symbol-overlay-basic-jump (symbol dir)
+ "Jump to SYMBOL's next location in the direction DIR. Dir must be 1 or -1."
(let* ((case-fold-search nil)
(bounds (bounds-of-thing-at-point 'symbol))
(offset (- (point) (if (> dir 0) (cdr bounds) (car bounds)))))
@@ -216,24 +220,19 @@ the jumping direction."
(goto-char (+ target offset)))))
;;;###autoload
-(defun so-query-replace ()
- "Command for query-replacing current symbol."
+(defun symbol-overlay-query-replace ()
+ "Command for query-replacing symbol at point."
(interactive)
(unless (minibufferp)
- (let ((symbol (so-get-s)))
- (if (assoc symbol so-keywords-alist) (so-query-replace-s symbol)
- (message "Symbol not highlighted")))))
-
-(defun so-query-replace-s (symbol)
- "Query replace SYMBOL with replacement from a prompt."
- (let* ((replacement (read-string "Replacement: "))
- (defaults (cons symbol replacement)))
- (so-remove-s symbol)
- (beginning-of-thing 'symbol)
- (query-replace-regexp symbol replacement)
- (setq query-replace-defaults
- (if (>= emacs-major-version 25) `(,defaults) `,defaults))
- (so-put-s (so-get-s replacement))))
+ (let* ((symbol (symbol-overlay-get-symbol))
+ (replacement (read-string "Replacement: "))
+ (defaults (cons symbol replacement)))
+ (symbol-overlay-remove symbol)
+ (beginning-of-thing 'symbol)
+ (query-replace-regexp symbol replacement)
+ (setq query-replace-defaults
+ (if (< emacs-major-version 25) `,defaults `(,defaults)))
+ (symbol-overlay-put-overlay (symbol-overlay-get-symbol replacement)))))
(provide 'symbol-overlay)
- [nongnu] elpa/symbol-overlay fdb432babd 034/152: (v3.1) add narrow-function, (continued)
- [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, 2022/07/07
- [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 <=
- [nongnu] elpa/symbol-overlay 4cf1d3c0d2 024/152: better auto-refresh, ELPA Syncer, 2022/07/07
- [nongnu] elpa/symbol-overlay 4a297843fd 016/152: v2.1, add 3 commands for switching and renaming symbols, ELPA Syncer, 2022/07/07
- [nongnu] elpa/symbol-overlay 06c5a46ef7 017/152: fix some typos, ELPA Syncer, 2022/07/07
- [nongnu] elpa/symbol-overlay 3d1811ca31 021/152: (v2.4) a new auto-refresh, ELPA Syncer, 2022/07/07
- [nongnu] elpa/symbol-overlay f68b908cbb 026/152: fix errors in symbol-replacing, ELPA Syncer, 2022/07/07
- [nongnu] elpa/symbol-overlay 2650738135 031/152: a new image, ELPA Syncer, 2022/07/07
- [nongnu] elpa/symbol-overlay 389cc1519a 040/152: fix missed minibufferp check, ELPA Syncer, 2022/07/07
- [nongnu] elpa/symbol-overlay a5b5e62cad 045/152: change the temp-face, ELPA Syncer, 2022/07/07
- [nongnu] elpa/symbol-overlay f0418dea49 047/152: enable scope in the minor-mode, ELPA Syncer, 2022/07/07
- [nongnu] elpa/symbol-overlay 765e1d3b07 050/152: improvements on refresh, ELPA Syncer, 2022/07/07