emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/git-commit 2276f6bcce 09/12: Move core bookmark support to


From: ELPA Syncer
Subject: [nongnu] elpa/git-commit 2276f6bcce 09/12: Move core bookmark support to magit-mode.el
Date: Fri, 13 May 2022 10:58:11 -0400 (EDT)

branch: elpa/git-commit
commit 2276f6bcce501d99bfa571fe19377a82151148aa
Author: Jonas Bernoulli <jonas@bernoul.li>
Commit: Jonas Bernoulli <jonas@bernoul.li>

    Move core bookmark support to magit-mode.el
    
    This helps avoiding circular dependencies.
    
    I am undecided what to do with the boilerplate code that implements
    support for individual derived modes.  For now I am not spreading
    that across files, but I might change my mind about that.
---
 lisp/magit-bookmark.el | 74 ----------------------------------------------
 lisp/magit-mode.el     | 79 ++++++++++++++++++++++++++++++++++++++++++++++----
 2 files changed, 73 insertions(+), 80 deletions(-)

diff --git a/lisp/magit-bookmark.el b/lisp/magit-bookmark.el
index 0a42741b83..c8780e9754 100644
--- a/lisp/magit-bookmark.el
+++ b/lisp/magit-bookmark.el
@@ -29,80 +29,6 @@
 ;;; Code:
 
 (require 'magit)
-(require 'bookmark)
-
-;;; Core
-
-(defun magit--make-bookmark ()
-  "Create a bookmark for the current Magit buffer.
-Input values are the major-mode's `magit-bookmark-name' method,
-and the buffer-local values of the variables referenced in its
-`magit-bookmark-variables' property."
-  (if (plist-member (symbol-plist major-mode) 'magit-bookmark-variables)
-      ;; `bookmark-make-record-default's return value does not match
-      ;; (NAME . ALIST), even though it is used as the default value
-      ;; of `bookmark-make-record-function', which states that such
-      ;; functions must do that.  See #4356.
-      (let ((bookmark (cons nil (bookmark-make-record-default 'no-file))))
-        (bookmark-prop-set bookmark 'handler  #'magit--handle-bookmark)
-        (bookmark-prop-set bookmark 'mode     major-mode)
-        (bookmark-prop-set bookmark 'filename (magit-toplevel))
-        (bookmark-prop-set bookmark 'defaults (list (magit-bookmark-name)))
-        (dolist (var (get major-mode 'magit-bookmark-variables))
-          (bookmark-prop-set bookmark var (symbol-value var)))
-        (bookmark-prop-set
-         bookmark 'magit-hidden-sections
-         (--keep (and (oref it hidden)
-                      (cons (oref it type)
-                            (if (derived-mode-p 'magit-stash-mode)
-                                (string-replace magit-buffer-revision
-                                                magit-buffer-revision-hash
-                                                (oref it value))
-                              (oref it value))))
-                 (oref magit-root-section children)))
-        bookmark)
-    (user-error "Bookmarking is not implemented for %s buffers" major-mode)))
-
-;;;###autoload
-(defun magit--handle-bookmark (bookmark)
-  "Open a bookmark created by `magit--make-bookmark'.
-Call the `magit-*-setup-buffer' function of the the major-mode
-with the variables' values as arguments, which were recorded by
-`magit--make-bookmark'.  Ignore `magit-display-buffer-function'."
-  (let ((buffer (let ((default-directory (bookmark-get-filename bookmark))
-                      (mode (bookmark-prop-get bookmark 'mode))
-                      (magit-display-buffer-function #'identity)
-                      (magit-display-buffer-noselect t))
-                  (apply (intern (format "%s-setup-buffer"
-                                         (substring (symbol-name mode) 0 -5)))
-                         (--map (bookmark-prop-get bookmark it)
-                                (get mode 'magit-bookmark-variables))))))
-    (set-buffer buffer) ; That is the interface we have to adhere to.
-    (when-let ((hidden (bookmark-prop-get bookmark 'magit-hidden-sections)))
-      (with-current-buffer buffer
-        (dolist (child (oref magit-root-section children))
-          (if (member (cons (oref child type)
-                            (oref child value))
-                      hidden)
-              (magit-section-hide child)
-            (magit-section-show child)))))
-    ;; Compatibility with `bookmark+' package.  See #4356.
-    (when (bound-and-true-p bmkp-jump-display-function)
-      (funcall bmkp-jump-display-function (current-buffer)))
-    nil))
-
-(cl-defgeneric magit-bookmark-name ()
-  "Return name for bookmark to current buffer."
-  (format "%s%s"
-          (substring (symbol-name major-mode) 0 -5)
-          (if-let ((vars (get major-mode 'magit-bookmark-variables)))
-              (cl-mapcan (lambda (var)
-                           (let ((val (symbol-value var)))
-                             (if (and val (atom val))
-                                 (list val)
-                               val)))
-                         vars)
-            "")))
 
 ;;; Diff
 ;;;; Diff
diff --git a/lisp/magit-mode.el b/lisp/magit-mode.el
index b0ac4671c5..132ea615f6 100644
--- a/lisp/magit-mode.el
+++ b/lisp/magit-mode.el
@@ -31,16 +31,11 @@
 (require 'magit-base)
 (require 'magit-git)
 
+(require 'bookmark)
 (require 'format-spec)
 (require 'help-mode)
 (require 'transient)
 
-;; For `magit-refresh-buffer'
-(declare-function magit-process-unset-mode-line-error-status "magit-process" 
())
-;; For `magit-mode'
-(defvar bookmark-make-record-function)
-(declare-function magit--make-bookmark "magit-bookmark" ())
-
 ;;; Options
 
 (defcustom magit-mode-hook
@@ -1483,6 +1478,78 @@ mentioned caches completely."
         (substring heading 0 (match-beginning 0)))
        (t heading)))))
 
+;;; Bookmark support
+
+(defun magit--make-bookmark ()
+  "Create a bookmark for the current Magit buffer.
+Input values are the major-mode's `magit-bookmark-name' method,
+and the buffer-local values of the variables referenced in its
+`magit-bookmark-variables' property."
+  (if (plist-member (symbol-plist major-mode) 'magit-bookmark-variables)
+      ;; `bookmark-make-record-default's return value does not match
+      ;; (NAME . ALIST), even though it is used as the default value
+      ;; of `bookmark-make-record-function', which states that such
+      ;; functions must do that.  See #4356.
+      (let ((bookmark (cons nil (bookmark-make-record-default 'no-file))))
+        (bookmark-prop-set bookmark 'handler  #'magit--handle-bookmark)
+        (bookmark-prop-set bookmark 'mode     major-mode)
+        (bookmark-prop-set bookmark 'filename (magit-toplevel))
+        (bookmark-prop-set bookmark 'defaults (list (magit-bookmark-name)))
+        (dolist (var (get major-mode 'magit-bookmark-variables))
+          (bookmark-prop-set bookmark var (symbol-value var)))
+        (bookmark-prop-set
+         bookmark 'magit-hidden-sections
+         (--keep (and (oref it hidden)
+                      (cons (oref it type)
+                            (if (derived-mode-p 'magit-stash-mode)
+                                (string-replace magit-buffer-revision
+                                                magit-buffer-revision-hash
+                                                (oref it value))
+                              (oref it value))))
+                 (oref magit-root-section children)))
+        bookmark)
+    (user-error "Bookmarking is not implemented for %s buffers" major-mode)))
+
+(defun magit--handle-bookmark (bookmark)
+  "Open a bookmark created by `magit--make-bookmark'.
+Call the `magit-*-setup-buffer' function of the the major-mode
+with the variables' values as arguments, which were recorded by
+`magit--make-bookmark'.  Ignore `magit-display-buffer-function'."
+  (let ((buffer (let ((default-directory (bookmark-get-filename bookmark))
+                      (mode (bookmark-prop-get bookmark 'mode))
+                      (magit-display-buffer-function #'identity)
+                      (magit-display-buffer-noselect t))
+                  (apply (intern (format "%s-setup-buffer"
+                                         (substring (symbol-name mode) 0 -5)))
+                         (--map (bookmark-prop-get bookmark it)
+                                (get mode 'magit-bookmark-variables))))))
+    (set-buffer buffer) ; That is the interface we have to adhere to.
+    (when-let ((hidden (bookmark-prop-get bookmark 'magit-hidden-sections)))
+      (with-current-buffer buffer
+        (dolist (child (oref magit-root-section children))
+          (if (member (cons (oref child type)
+                            (oref child value))
+                      hidden)
+              (magit-section-hide child)
+            (magit-section-show child)))))
+    ;; Compatibility with `bookmark+' package.  See #4356.
+    (when (bound-and-true-p bmkp-jump-display-function)
+      (funcall bmkp-jump-display-function (current-buffer)))
+    nil))
+
+(cl-defgeneric magit-bookmark-name ()
+  "Return name for bookmark to current buffer."
+  (format "%s%s"
+          (substring (symbol-name major-mode) 0 -5)
+          (if-let ((vars (get major-mode 'magit-bookmark-variables)))
+              (cl-mapcan (lambda (var)
+                           (let ((val (symbol-value var)))
+                             (if (and val (atom val))
+                                 (list val)
+                               val)))
+                         vars)
+            "")))
+
 ;;; Utilities
 
 (defun magit-toggle-verbose-refresh ()



reply via email to

[Prev in Thread] Current Thread [Next in Thread]