mirror of
https://github.com/abo-abo/avy.git
synced 2025-10-13 21:33:05 +00:00
Customize the leading char style for chars and words
* avy-jump.el (avy--style-fn): New defun. (avy--generic-jump): Add a STYLE arg. (avy-goto-char-style): New defcustom. (avy-goto-word-style): New defcustom. (avy-goto-char): Update. (avy-goto-char-2): Update. (avy-goto-word-0): Update. (avy-goto-word-1): Simplify. (avy-goto-subword-0): Update doc. Fixes #5
This commit is contained in:
parent
18cf1ef995
commit
e9d2e60965
87
avy-jump.el
87
avy-jump.el
@ -215,39 +215,64 @@ LEAF is ((BEG . END) . WND)."
|
|||||||
(cdr leaf)
|
(cdr leaf)
|
||||||
(selected-window))))
|
(selected-window))))
|
||||||
|
|
||||||
(defun avy--generic-jump (regex flip)
|
(defun avy--style-fn (style)
|
||||||
|
"Transform STYLE symbol to a style function."
|
||||||
|
(cl-case style
|
||||||
|
(pre #'avy--overlay-pre)
|
||||||
|
(at #'avy--overlay-at)
|
||||||
|
(post #'avy--overlay-post)
|
||||||
|
(t (error "Unexpected style %S" style))))
|
||||||
|
|
||||||
|
(defun avy--generic-jump (regex window-flip style)
|
||||||
"Jump to REGEX.
|
"Jump to REGEX.
|
||||||
When FLIP is non-nil, flip `avy-all-windows'."
|
When WINDOW-FLIP is non-nil, do the opposite of `avy-all-windows'.
|
||||||
|
STYLE determines the leading char overlay style."
|
||||||
(let ((avy-all-windows
|
(let ((avy-all-windows
|
||||||
(if flip
|
(if window-flip
|
||||||
(not avy-all-windows)
|
(not avy-all-windows)
|
||||||
avy-all-windows)))
|
avy-all-windows)))
|
||||||
(avy--goto
|
(avy--goto
|
||||||
(avy--process
|
(avy--process
|
||||||
(avy--regex-candidates
|
(avy--regex-candidates
|
||||||
regex)
|
regex)
|
||||||
#'avy--overlay-post))))
|
(avy--style-fn style)))))
|
||||||
|
|
||||||
|
(defcustom avy-goto-char-style 'pre
|
||||||
|
"Method of displaying the overlays for `avy-goto-char' and `avy-goto-char-2'."
|
||||||
|
:type '(choice
|
||||||
|
(const :tag "Pre" pre)
|
||||||
|
(const :tag "At" at)
|
||||||
|
(const :tag "Post" post)))
|
||||||
|
|
||||||
|
(defcustom avy-goto-word-style 'pre
|
||||||
|
"Method of displaying the overlays for `avy-goto-word-0' and `avy-goto-word-0'."
|
||||||
|
:type '(choice
|
||||||
|
(const :tag "Pre" pre)
|
||||||
|
(const :tag "At" at)
|
||||||
|
(const :tag "Post" post)))
|
||||||
|
|
||||||
;;* Commands
|
;;* Commands
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun avy-goto-char (&optional arg)
|
(defun avy-goto-char (&optional arg)
|
||||||
"Read one char and jump to it.
|
"Read one char and jump to it.
|
||||||
The window scope is determined by `avy-all-windows'.
|
The window scope is determined by `avy-all-windows' (ARG negates it)."
|
||||||
When ARG is non-nil, flip the window scope."
|
|
||||||
(interactive "P")
|
(interactive "P")
|
||||||
(avy--generic-jump
|
(avy--generic-jump
|
||||||
(regexp-quote (string (read-char "char: "))) arg))
|
(regexp-quote (string (read-char "char: ")))
|
||||||
|
arg
|
||||||
|
avy-goto-char-style))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun avy-goto-char-2 (&optional arg)
|
(defun avy-goto-char-2 (&optional arg)
|
||||||
"Read two chars and jump to them in current window.
|
"Read two consecutive chars and jump to the first one.
|
||||||
When ARG is non-nil, flip the window scope."
|
The window scope is determined by `avy-all-windows' (ARG negates it)."
|
||||||
(interactive "P")
|
(interactive "P")
|
||||||
(avy--generic-jump
|
(avy--generic-jump
|
||||||
(regexp-quote (string
|
(regexp-quote (string
|
||||||
(read-char "char 1: ")
|
(read-char "char 1: ")
|
||||||
(read-char "char 2: ")))
|
(read-char "char 2: ")))
|
||||||
arg))
|
arg
|
||||||
|
avy-goto-char-style))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun avy-isearch ()
|
(defun avy-isearch ()
|
||||||
@ -263,44 +288,44 @@ When ARG is non-nil, flip the window scope."
|
|||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun avy-goto-word-0 (arg)
|
(defun avy-goto-word-0 (arg)
|
||||||
"Jump to a word start."
|
"Jump to a word start.
|
||||||
|
The window scope is determined by `avy-all-windows' (ARG negates it)."
|
||||||
(interactive "P")
|
(interactive "P")
|
||||||
(let ((avy-keys (number-sequence ?a ?z)))
|
(let ((avy-keys (number-sequence ?a ?z)))
|
||||||
(avy--generic-jump "\\b\\sw" arg)))
|
(avy--generic-jump "\\b\\sw" arg avy-goto-word-style)))
|
||||||
|
|
||||||
|
;;;###autoload
|
||||||
|
(defun avy-goto-word-1 (&optional arg)
|
||||||
|
"Read one char at word start and jump there.
|
||||||
|
The window scope is determined by `avy-all-windows' (ARG negates it)."
|
||||||
|
(interactive "P")
|
||||||
|
(let* ((str (string (read-char "char: ")))
|
||||||
|
(regex (if (and avy-word-punc-regexp
|
||||||
|
(string-match avy-word-punc-regexp str))
|
||||||
|
str
|
||||||
|
(concat
|
||||||
|
"\\b"
|
||||||
|
str))))
|
||||||
|
(avy--generic-jump regex arg avy-goto-word-style)))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun avy-goto-subword-0 (&optional arg)
|
(defun avy-goto-subword-0 (&optional arg)
|
||||||
"Jump to a word or subword start."
|
"Jump to a word or subword start.
|
||||||
|
The window scope is determined by `avy-all-windows' (ARG negates it)."
|
||||||
(interactive "P")
|
(interactive "P")
|
||||||
(let* ((avy-all-windows
|
(let* ((avy-all-windows
|
||||||
(if arg
|
(if arg
|
||||||
(not avy-all-windows)
|
(not avy-all-windows)
|
||||||
avy-all-windows))
|
avy-all-windows))
|
||||||
(avy-keys (number-sequence ?a ?z))
|
(avy-keys (number-sequence ?a ?z))
|
||||||
(case-fold-search nil)
|
(case-fold-search nil)
|
||||||
(candidates (avy--regex-candidates
|
(candidates (avy--regex-candidates
|
||||||
"\\(\\b\\sw\\)\\|\\(?:[^A-Z]\\([A-Z]\\)\\)")))
|
"\\(\\b\\sw\\)\\|\\(?:[^A-Z]\\([A-Z]\\)\\)")))
|
||||||
(dolist (x candidates)
|
(dolist (x candidates)
|
||||||
(when (> (- (cdar x) (caar x)) 1)
|
(when (> (- (cdar x) (caar x)) 1)
|
||||||
(cl-incf (caar x))))
|
(cl-incf (caar x))))
|
||||||
(avy--goto
|
(avy--goto
|
||||||
(avy--process candidates #'avy--overlay-pre))))
|
(avy--process candidates (avy--style-fn avy-goto-word-style)))))
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun avy-goto-word-1 ()
|
|
||||||
"Jump to a word start in current window.
|
|
||||||
Read one char with which the word should start."
|
|
||||||
(interactive)
|
|
||||||
(let* ((str (string (read-char "char: ")))
|
|
||||||
(candidates (avy--regex-candidates
|
|
||||||
(if (and avy-word-punc-regexp
|
|
||||||
(string-match avy-word-punc-regexp str))
|
|
||||||
str
|
|
||||||
(concat
|
|
||||||
"\\b"
|
|
||||||
str)))))
|
|
||||||
(avy--goto
|
|
||||||
(avy--process candidates #'avy--overlay-pre))))
|
|
||||||
|
|
||||||
(defun avy--line (&optional arg)
|
(defun avy--line (&optional arg)
|
||||||
"Select line in current window."
|
"Select line in current window."
|
||||||
|
Loading…
x
Reference in New Issue
Block a user