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
*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>
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.
* 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
**Note:** The function and variable names were previously separated by “/”

View File

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