Visit file-queries too, not just markers.

When a position is stored in a register, it is stored as marker. If the buffer
is closed, the marker is transformed to a file-query. We now cycle through both.
This commit is contained in:
tastytea 2020-03-07 15:14:32 +01:00
parent 21971bb469
commit 3282e669e9
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
2 changed files with 38 additions and 25 deletions

View File

@ -1,7 +1,7 @@
# register-quicknav - Quickly jump to next/previous register # register-quicknav - Quickly jump to next/previous register
*Author:* tastytea <tastytea@tastytea.de><br> *Author:* tastytea <tastytea@tastytea.de><br>
*Version:* 0.1.2<br> *Version:* 0.2.0<br>
*URL:* [https://schlomp.space/tastytea/register-quicknav](https://schlomp.space/tastytea/register-quicknav)<br> *URL:* [https://schlomp.space/tastytea/register-quicknav](https://schlomp.space/tastytea/register-quicknav)<br>
This package is built on top of `register.el` and allows you to quickly jump This package is built on top of `register.el` and allows you to quickly jump
@ -13,11 +13,6 @@ wraps around and continues with the first (or last) register.
* Cycle through all position registers in both directions. * Cycle through all position registers in both directions.
* Clear current register. * Clear current register.
## Known limitations
Works only for as long as the buffer containing the registers is open. If
you close and reopen it, it won't work anymore.
## Installation ## Installation
**Note:** The function and variable names were previously separated by “/” **Note:** The function and variable names were previously separated by “/”

View File

@ -3,7 +3,7 @@
;; Copyright (C) 2020 tastytea ;; Copyright (C) 2020 tastytea
;; Author: tastytea <tastytea@tastytea.de> ;; Author: tastytea <tastytea@tastytea.de>
;; Version: 0.1.2 ;; Version: 0.2.0
;; Package-Requires: ((emacs "24.3")) ;; Package-Requires: ((emacs "24.3"))
;; Keywords: convenience ;; Keywords: convenience
;; URL: https://schlomp.space/tastytea/register-quicknav ;; URL: https://schlomp.space/tastytea/register-quicknav
@ -32,11 +32,6 @@
;; * Cycle through all position registers in both directions. ;; * Cycle through all position registers in both directions.
;; * Clear current register. ;; * Clear current register.
;; Known limitations:
;;
;; Works only for as long as the buffer containing the registers is open. If
;; you close and reopen it, it won't work anymore.
;; Installation: ;; Installation:
;; ;;
;; **Note:** The function and variable names were previously separated by “/” ;; **Note:** The function and variable names were previously separated by “/”
@ -99,21 +94,44 @@
"Return all position registers, sorted by file name and position. "Return all position registers, sorted by file name and position.
If `register-quicknav-buffer-only' is t, return only registers in If `register-quicknav-buffer-only' is t, return only registers in
current buffer." current buffer."
(cl-flet ((sort-registers (cl-flet* ((item-file-name
(lambda (a b) (lambda (item)
(let ((marker-a (cdr a)) "Return file-name of ITEM.
(marker-b (cdr b))) Works on markers and file-queries."
(and (string= (buffer-file-name (marker-buffer marker-a)) (if (markerp (cdr item))
(buffer-file-name (marker-buffer marker-b))) (buffer-file-name (marker-buffer (cdr item)))
(< (marker-position marker-a) (nth 2 item))))
(marker-position marker-b))))))) (is-current-buffer?
(lambda (item)
"Return t if ITEM is in current buffer.
Works on markers and file-queries."
(if (markerp (cdr item))
(eq (current-buffer) (marker-buffer (cdr item)))
(string= (buffer-file-name (current-buffer))
(item-file-name item)))))
(sort-registers
(lambda (a b)
"Return t if position of A is < B.
Works on markers and file-queries."
(cl-flet ((item-position
(lambda (item)
"Return position of ITEM.
Works on markers and file-queries."
(if (markerp (cdr item))
(marker-position (cdr item))
(nth 3 item)))))
(and (string= (item-file-name a)
(item-file-name b))
(< (item-position a)
(item-position b)))))))
(let ((result)) (let ((result))
(dolist (item register-alist) (dolist (item register-alist)
(when (markerp (cdr item)) (if (or (markerp (cdr item))
(if register-quicknav-buffer-only (eq (nth 1 item) 'file-query))
(when (eq (current-buffer) (marker-buffer (cdr item))) (if register-quicknav-buffer-only
(push item result)) (when (is-current-buffer? item)
(push item result)))) (push item result))
(push item result))))
(sort result #'sort-registers)))) (sort result #'sort-registers))))
;;;###autoload ;;;###autoload