summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJSDurand <mmemmew@gmail.com>2023-06-15 00:24:41 +0800
committerJSDurand <mmemmew@gmail.com>2023-06-15 00:24:41 +0800
commita5bd7a08189d5c7237be15bed0ddfcb7b1e1db54 (patch)
tree00b51d1e5fface6258d019ce38dc172dacbf95b3
parentb2db7ea907da4cec6b056166877214748ab97a13 (diff)
common: support bookmarks in registers
* common.el (register-val-jump-to, register-val-describe): Support bookmarks in registers via these two methods.
-rw-r--r--common.el94
1 files changed, 93 insertions, 1 deletions
diff --git a/common.el b/common.el
index aa90a88..860e031 100644
--- a/common.el
+++ b/common.el
@@ -313,6 +313,8 @@ mark at the end for the first yank."
;;; Don't ask me if I want to visit the file again.
+;; Also add a bookmark type to registers.
+
(require 'register)
;;;###autoload
@@ -326,12 +328,102 @@ mark at the end for the first yank."
(goto-char (cadr val)))
((eq (car val) 'file)
(find-file (cdr val)))
+ ((eq (car val) 'bookmark)
+ (require 'bookmark)
+ (bookmark-jump (cdr val)))
((eq (car val) 'file-query)
- (find-buffer-visiting (nth 1 val))
+ (or (find-buffer-visiting (nth 1 val))
+ (y-or-n-p (format "Visit file %s again? " (nth 1 val)))
+ (user-error "Register access aborted"))
(find-file (nth 1 val))
(goto-char (nth 2 val)))
(t (cl-call-next-method val delete))))
+(cl-defmethod register-val-describe ((val cons) verbose)
+ (cond
+ ((window-configuration-p (car val))
+ (let* ((stored-window-config (car val))
+ (window-config-frame
+ (window-configuration-frame stored-window-config))
+ (current-frame (selected-frame)))
+ (princ (format
+ "a window configuration: %s."
+ (if (frame-live-p window-config-frame)
+ (with-selected-frame window-config-frame
+ (save-window-excursion
+ (set-window-configuration
+ stored-window-config)
+ (concat
+ (mapconcat
+ (lambda (w)
+ (buffer-name (window-buffer w)))
+ (window-list (selected-frame)) ", ")
+ (unless (eq current-frame window-config-frame)
+ " in another frame"))))
+ "dead frame")))))
+
+ ((frame-configuration-p (car val))
+ (princ "a frame configuration."))
+
+ ((eq (car val) 'bookmark)
+ (princ "a bookmark:\n location ")
+ (require 'bookmark)
+ (princ
+ (or (bookmark-get-filename (cdr val))
+ (bookmark-prop-get (cdr val) 'location)))
+ (let ((position (bookmark-get-position (cdr val))))
+ (cond
+ (position
+ (princ ",\n position ")
+ (prin1 position))))
+ (cond
+ (verbose
+ (let ((front-string
+ (bookmark-get-front-context-string (cdr val)))
+ (rear-string
+ (bookmark-get-rear-context-string (cdr val))))
+ (cond
+ (front-string
+ (princ ",\n front: ")
+ (princ (replace-regexp-in-string
+ "\n\\|\r" "\\n" front-string
+ nil t))))
+ (cond
+ (rear-string
+ (princ ",\n rear: ")
+ (princ (replace-regexp-in-string
+ "\n\\|\r" "\\n" rear-string
+ nil t))))))))
+
+ ((eq (car val) 'file)
+ (princ "the file ")
+ (prin1 (cdr val))
+ (princ "."))
+
+ ((eq (car val) 'buffer)
+ (princ "the buffer ")
+ (prin1 (cdr val))
+ (princ "."))
+
+ ((eq (car val) 'file-query)
+ (princ "a file-query reference:\n file ")
+ (prin1 (car (cdr val)))
+ (princ ",\n position ")
+ (princ (car (cdr (cdr val))))
+ (princ "."))
+
+ (t
+ (if verbose
+ (progn
+ (princ "the rectangle:\n")
+ (while val
+ (princ " ")
+ (princ (car val))
+ (terpri)
+ (setq val (cdr val))))
+ (princ "a rectangle starting with ")
+ (princ (car val))))))
+
;;; Intentionally disable some key-bindings.
;; Using byte-code is fun.