[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master e9d2e60 08/17: Customize the leading char style for chars
From: |
Oleh Krehel |
Subject: |
[elpa] master e9d2e60 08/17: Customize the leading char style for chars and words |
Date: |
Fri, 08 May 2015 13:42:09 +0000 |
branch: master
commit e9d2e60965d2d0299205116f7f7e33a6887b34f0
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>
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
---
avy-jump.el | 87 ++++++++++++++++++++++++++++++++++++++---------------------
1 files changed, 56 insertions(+), 31 deletions(-)
diff --git a/avy-jump.el b/avy-jump.el
index 2f8617b..5f8334a 100644
--- a/avy-jump.el
+++ b/avy-jump.el
@@ -215,39 +215,64 @@ LEAF is ((BEG . END) . WND)."
(cdr leaf)
(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.
-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
- (if flip
+ (if window-flip
(not avy-all-windows)
avy-all-windows)))
(avy--goto
(avy--process
(avy--regex-candidates
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
;;;###autoload
(defun avy-goto-char (&optional arg)
"Read one char and jump to it.
-The window scope is determined by `avy-all-windows'.
-When ARG is non-nil, flip the window scope."
+The window scope is determined by `avy-all-windows' (ARG negates it)."
(interactive "P")
(avy--generic-jump
- (regexp-quote (string (read-char "char: "))) arg))
+ (regexp-quote (string (read-char "char: ")))
+ arg
+ avy-goto-char-style))
;;;###autoload
(defun avy-goto-char-2 (&optional arg)
- "Read two chars and jump to them in current window.
-When ARG is non-nil, flip the window scope."
+ "Read two consecutive chars and jump to the first one.
+The window scope is determined by `avy-all-windows' (ARG negates it)."
(interactive "P")
(avy--generic-jump
(regexp-quote (string
(read-char "char 1: ")
(read-char "char 2: ")))
- arg))
+ arg
+ avy-goto-char-style))
;;;###autoload
(defun avy-isearch ()
@@ -263,44 +288,44 @@ When ARG is non-nil, flip the window scope."
;;;###autoload
(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")
(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
(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")
(let* ((avy-all-windows
(if arg
(not avy-all-windows)
avy-all-windows))
(avy-keys (number-sequence ?a ?z))
- (case-fold-search nil)
+ (case-fold-search nil)
(candidates (avy--regex-candidates
"\\(\\b\\sw\\)\\|\\(?:[^A-Z]\\([A-Z]\\)\\)")))
(dolist (x candidates)
(when (> (- (cdar x) (caar x)) 1)
(cl-incf (caar x))))
(avy--goto
- (avy--process candidates #'avy--overlay-pre))))
-
-;;;###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))))
+ (avy--process candidates (avy--style-fn avy-goto-word-style)))))
(defun avy--line (&optional arg)
"Select line in current window."
- [elpa] master updated (74b34f2 -> 876d210), Oleh Krehel, 2015/05/08
- [elpa] master 1684e6a 03/17: Avoid image-mode and doc-view-mode, Oleh Krehel, 2015/05/08
- [elpa] master 1d184b0 05/17: Regexp-quote strings of avy-goto-char* functions., Oleh Krehel, 2015/05/08
- [elpa] master 33546b6 06/17: Fix avy-goto-subword-0, Oleh Krehel, 2015/05/08
- [elpa] master 5677270 04/17: Move obsoletes to one place, Oleh Krehel, 2015/05/08
- [elpa] master 18cf1ef 07/17: README.md: add, Oleh Krehel, 2015/05/08
- [elpa] master 6c1f2f6 02/17: Move from "avi-" to "avy-", leave old stuff obsolete, Oleh Krehel, 2015/05/08
- [elpa] master 974e55b 09/17: avy-jump.el (avy--line): Avoid image-mode and doc-view-mode, Oleh Krehel, 2015/05/08
- [elpa] master 5d2979b 01/17: Initial import, Oleh Krehel, 2015/05/08
- [elpa] master e9d2e60 08/17: Customize the leading char style for chars and words,
Oleh Krehel <=
- [elpa] master 903e172 12/17: Special-case char RET to allow for jumping to end-of-lines., Oleh Krehel, 2015/05/08
- [elpa] master 487d5ea 11/17: Abstract windows and rely on subword, Oleh Krehel, 2015/05/08
- [elpa] master ca1ca04 14/17: Add avy-goto-subword-1, Oleh Krehel, 2015/05/08
- [elpa] master e4f493e 10/17: README.md: Add command descriptions, Oleh Krehel, 2015/05/08
- [elpa] master 3200351 16/17: avy-jump.el (avy-setup-default): Setup some bindings, Oleh Krehel, 2015/05/08
- [elpa] master b2112e0 13/17: avy-jump.el (avy-goto-word-1): Fix for ".", Oleh Krehel, 2015/05/08
- [elpa] master f2290f2 15/17: avy.el: Update commentary, Oleh Krehel, 2015/05/08
- [elpa] master 876d210 17/17: Add 'packages/avy/' from commit '32003515c8efa2cf38b62c45499dae30bc7cacb8', Oleh Krehel, 2015/05/08