Refactor register-quicknav--jump-to-register.
Shorten validity-check and index correction, update/add comments.
This commit is contained in:
parent
c90d005c54
commit
bab92365cd
|
@ -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.3.0<br>
|
*Version:* 0.3.1<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
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
;; Copyright (C) 2020 tastytea
|
;; Copyright (C) 2020 tastytea
|
||||||
|
|
||||||
;; Author: tastytea <tastytea@tastytea.de>
|
;; Author: tastytea <tastytea@tastytea.de>
|
||||||
;; Version: 0.3.0
|
;; Version: 0.3.1
|
||||||
;; 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
|
||||||
|
@ -155,30 +155,27 @@ Works on markers and file-queries."
|
||||||
(if next
|
(if next
|
||||||
(cl-incf index)
|
(cl-incf index)
|
||||||
(cl-decf index)))
|
(cl-decf index)))
|
||||||
|
|
||||||
;; Try to find the position register closest to point.
|
;; Try to find the position register closest to point.
|
||||||
(dolist (register register-list)
|
(dolist (register register-list)
|
||||||
(when (register-quicknav--is-current-buffer? register)
|
(when (register-quicknav--is-current-buffer? register)
|
||||||
(let ((register-pos (register-quicknav--position register)))
|
(let ((register-pos (register-quicknav--position register)))
|
||||||
(if next
|
(if next
|
||||||
(when (and (not stop-searching) (> register-pos (point)))
|
(when (and (not stop-searching)
|
||||||
|
(> register-pos (point)))
|
||||||
(setq index (cl-position register register-list)
|
(setq index (cl-position register register-list)
|
||||||
stop-searching t))
|
stop-searching t))
|
||||||
(when (< register-pos (point))
|
(when (< register-pos (point))
|
||||||
(setq index (cl-position register register-list)))))))
|
(setq index (cl-position register register-list)))))))
|
||||||
|
|
||||||
;; Check if index is valid, correct it if not, jump to register with index.
|
|
||||||
(if index
|
(if index
|
||||||
(progn
|
(progn ; If index is invalid, set it to first or last register.
|
||||||
(when (or (> index (- (length register-list) 1)) (< index 0))
|
(when (or (>= index (length register-list))
|
||||||
(setq index nil))
|
(< index 0))
|
||||||
(if next
|
(if next
|
||||||
(when (or (eq index nil) (eq index (length register-list)))
|
(setq index 0)
|
||||||
(setq index 0))
|
|
||||||
(when (eq index nil)
|
|
||||||
(setq index (- (length register-list) 1))))
|
(setq index (- (length register-list) 1))))
|
||||||
(register-to-point (car (nth index register-list)))
|
(register-to-point (car (nth index register-list)))
|
||||||
(register-quicknav--last-register (nth index register-list)))
|
(register-quicknav--last-register (nth index register-list)))
|
||||||
|
;; No suitable register found, jump to first or last register.
|
||||||
(register-to-point (car (car register-list)))
|
(register-to-point (car (car register-list)))
|
||||||
(register-quicknav--last-register (car register-list)))))
|
(register-quicknav--last-register (car register-list)))))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user