[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 4e4c488 020/110: Add avy-linum-mode
From: |
Oleh Krehel |
Subject: |
[elpa] master 4e4c488 020/110: Add avy-linum-mode |
Date: |
Sat, 11 May 2019 10:15:35 -0400 (EDT) |
branch: master
commit 4e4c488eefe4dad1b143ed100bbc26e838a56e10
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>
Add avy-linum-mode
* avy.el (avy--linum-strings): New defun.
(avy--linum-update-window): New defun. This is a copy-paste of
`linum-update-window' with just a few lines added.
(avy-linum-mode): New minor mode. Currently, only works with
`avy-all-windows' set to nil.
(avy--line): When `avy-linum-mode' is on, don't display
overlays. Instead, display a simple message.
Fixes #155
---
avy.el | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 81 insertions(+), 1 deletion(-)
diff --git a/avy.el b/avy.el
index 74aba07..4461cbb 100644
--- a/avy.el
+++ b/avy.el
@@ -1160,6 +1160,83 @@ Which one depends on variable `subword-mode'."
(forward-line 1)))))))
(nreverse candidates)))
+(defun avy--linum-strings ()
+ (let* ((lines (mapcar #'car (avy--line-cands)))
+ (line-tree (avy-tree lines avy-keys))
+ (line-list nil))
+ (avy-traverse
+ line-tree
+ (lambda (path _leaf)
+ (let ((str (propertize (apply #'string (reverse path))
+ 'face 'avy-lead-face)))
+ (when (> (length str) 1)
+ (set-text-properties 0 1 '(face avy-lead-face-0) str))
+ (push str line-list))))
+ (nreverse line-list)))
+
+(defun avy--linum-update-window (_ win)
+ "Update line numbers for the portion visible in window WIN."
+ (goto-char (window-start win))
+ (let ((line (line-number-at-pos))
+ (limit (window-end win t))
+ (fmt (cond ((stringp linum-format) linum-format)
+ ((eq linum-format 'dynamic)
+ (let ((w (length (number-to-string
+ (count-lines (point-min) (point-max))))))
+ (concat "%" (number-to-string w) "d")))))
+ (width 0)
+ (avy-strs (when avy-linum-mode
+ (avy--linum-strings))))
+ (run-hooks 'linum-before-numbering-hook)
+ ;; Create an overlay (or reuse an existing one) for each
+ ;; line visible in this window, if necessary.
+ (while (and (not (eobp)) (< (point) limit))
+ (let* ((str
+ (cond (avy-linum-mode
+ (pop avy-strs))
+ (fmt
+ (propertize (format fmt line) 'face 'linum))
+ (t
+ (funcall linum-format line))))
+ (visited (catch 'visited
+ (dolist (o (overlays-in (point) (point)))
+ (when (equal-including-properties
+ (overlay-get o 'linum-str) str)
+ (unless (memq o linum-overlays)
+ (push o linum-overlays))
+ (setq linum-available (delq o linum-available))
+ (throw 'visited t))))))
+ (setq width (max width (length str)))
+ (unless visited
+ (let ((ov (if (null linum-available)
+ (make-overlay (point) (point))
+ (move-overlay (pop linum-available) (point) (point)))))
+ (push ov linum-overlays)
+ (overlay-put ov 'before-string
+ (propertize " " 'display `((margin left-margin)
,str)))
+ (overlay-put ov 'linum-str str))))
+ ;; Text may contain those nasty intangible properties, but that
+ ;; shouldn't prevent us from counting those lines.
+ (let ((inhibit-point-motion-hooks t))
+ (forward-line))
+ (setq line (1+ line)))
+ (when (display-graphic-p)
+ (setq width (ceiling
+ (/ (* width 1.0 (linum--face-width 'linum))
+ (frame-char-width)))))
+ (set-window-margins win width (cdr (window-margins win)))))
+
+(define-minor-mode avy-linum-mode
+ "Minor mode that uses avy hints for `linum-mode'."
+ :group 'avy
+ (if avy-linum-mode
+ (progn
+ (require 'linum)
+ (advice-add 'linum-update-window :around 'avy--linum-update-window)
+ (linum-mode 1))
+ (advice-remove 'linum-update-window 'avy--linum-update-window)
+ (linum-mode -1)))
+
(defun avy--line (&optional arg beg end)
"Select a line.
The window scope is determined by `avy-all-windows' (ARG negates it).
@@ -1167,7 +1244,10 @@ Narrow the scope to BEG END."
(let ((avy-action #'identity))
(avy--process
(avy--line-cands arg beg end)
- (avy--style-fn avy-style))))
+ (if avy-linum-mode
+ (progn (message "Goto line:")
+ 'ignore)
+ (avy--style-fn avy-style)))))
;;;###autoload
(defun avy-goto-line (&optional arg)
- [elpa] master a911903 029/110: avy.el (avy-goto-word-1): Work for "^A"-"^Z", (continued)
- [elpa] master a911903 029/110: avy.el (avy-goto-word-1): Work for "^A"-"^Z", Oleh Krehel, 2019/05/11
- [elpa] master a5fb936 028/110: avy.el (avy-resume): Make it show up in M-x, Oleh Krehel, 2019/05/11
- [elpa] master 20ecb9b 024/110: Use flyspell if its minor mode is active, Oleh Krehel, 2019/05/11
- [elpa] master b522bfe 023/110: avy.el (avy-resume): Add, Oleh Krehel, 2019/05/11
- [elpa] master e460d7e 025/110: avy.el (flyspell-correct-word-before-point): Declare, Oleh Krehel, 2019/05/11
- [elpa] master 05a5003 022/110: avy.el: Fix linum-related compile warnings, Oleh Krehel, 2019/05/11
- [elpa] master 430d750 019/110: avy.el (avy--line-cands): Split away from avy--line, Oleh Krehel, 2019/05/11
- [elpa] master 0f5e99b 030/110: avy.el: Use next-char-property-change, not next-overlay-change, Oleh Krehel, 2019/05/11
- [elpa] master 33af738 017/110: avy.el (avy-goto-word-1-above): Add, Oleh Krehel, 2019/05/11
- [elpa] master 105efc8 037/110: avy.el (avy-action-copy): Copy line for avy-goto-line, Oleh Krehel, 2019/05/11
- [elpa] master 4e4c488 020/110: Add avy-linum-mode,
Oleh Krehel <=
- [elpa] master d644be1 016/110: avy.el (avy-goto-char-2-above): Simplify, Oleh Krehel, 2019/05/11
- [elpa] master 4dcf0a9 018/110: avy.el (avy-goto-char-2): Translate "RET" to "C-j", Oleh Krehel, 2019/05/11
- [elpa] master ba950a0 015/110: avy.el (avy-goto-char-2-above): Add, Oleh Krehel, 2019/05/11
- [elpa] master 58bc417 014/110: Escape regex metacharacters for standard isearch, Oleh Krehel, 2019/05/11
- [elpa] master 2e3c2f7 013/110: Add new command `avy-move-region', Oleh Krehel, 2019/05/11
- [elpa] master 85a384a 012/110: Add char at window start for avy-goto-subword-0, Oleh Krehel, 2019/05/11
- [elpa] master a80f95c 007/110: Add "X" dispatch to kill a word without moving there, Oleh Krehel, 2019/05/11
- [elpa] master 9e61f78 006/110: avy.el: Improve defcustom :type, Oleh Krehel, 2019/05/11
- [elpa] master 5ba3602 009/110: Assign avy-action-ispell to "i", Oleh Krehel, 2019/05/11
- [elpa] master 53706d2 011/110: avy.el (avy-all-windows-alt): Change the default to nil, Oleh Krehel, 2019/05/11