diff options
| author | Jonas Bernoulli <jonas@bernoul.li> | 2020-01-17 16:14:00 +0100 |
|---|---|---|
| committer | Jonas Bernoulli <jonas@bernoul.li> | 2020-01-23 18:05:18 +0100 |
| commit | 9759eb1338e376012f1ea501fe17fe52db92995f (patch) | |
| tree | 470111561e036154adaded5532e7ca513cecddea | |
| parent | 769529d7b9b5f195ee383c9cc0419c3acb30881c (diff) | |
Move magit-specific code out of magit-section.el
| -rw-r--r-- | lisp/magit-diff.el | 59 | ||||
| -rw-r--r-- | lisp/magit-mode.el | 2 | ||||
| -rw-r--r-- | lisp/magit-section.el | 58 |
3 files changed, 62 insertions, 57 deletions
diff --git a/lisp/magit-diff.el b/lisp/magit-diff.el index 82e61fc..7503162 100644 --- a/lisp/magit-diff.el +++ b/lisp/magit-diff.el @@ -813,6 +813,27 @@ and `:slant'." (setq magit-buffer-diff-files files) (magit-refresh))) +;;; Section Classes + +(defclass magit-file-section (magit-section) + ((source :initform nil) + (header :initform nil))) + +(defclass magit-module-section (magit-file-section) + ()) + +(defclass magit-hunk-section (magit-section) + ((refined :initform nil) + (combined :initform nil) + (from-range :initform nil) + (from-ranges :initform nil) + (to-range :initform nil) + (about :initform nil))) + +(setf (alist-get 'hunk magit--section-type-alist) 'magit-hunk-section) +(setf (alist-get 'module magit--section-type-alist) 'magit-module-section) +(setf (alist-get 'file magit--section-type-alist) 'magit-file-section) + ;;; Commands ;;;; Prefix Commands @@ -1780,6 +1801,36 @@ commit or stash at point, then prompt for a commit." (funcall cmd rev)))) (call-interactively #'magit-show-commit)))) +;;;; Section Commands + +(defun magit-section-cycle-diffs () + "Cycle visibility of diff-related sections in the current buffer." + (interactive) + (when-let ((sections + (cond ((derived-mode-p 'magit-status-mode) + (--mapcat + (when it + (when (oref it hidden) + (magit-section-show it)) + (oref it children)) + (list (magit-get-section '((staged) (status))) + (magit-get-section '((unstaged) (status)))))) + ((derived-mode-p 'magit-diff-mode) + (-filter #'magit-file-section-p + (oref magit-root-section children)))))) + (if (--any-p (oref it hidden) sections) + (dolist (s sections) + (magit-section-show s) + (magit-section-hide-children s)) + (let ((children (--mapcat (oref it children) sections))) + (cond ((and (--any-p (oref it hidden) children) + (--any-p (oref it children) children)) + (mapc 'magit-section-show-headings sections)) + ((-any-p 'magit-section-hidden-body children) + (mapc 'magit-section-show-children sections)) + (t + (mapc 'magit-section-hide sections))))))) + ;;; Diff Mode (defvar magit-diff-mode-map @@ -2607,6 +2658,14 @@ or a ref which is not a branch, then it inserts nothing." ;;; Diff Sections +(defun magit-hunk-set-window-start (section) + "When SECTION is a `hunk', ensure that its beginning is visible. +It the SECTION has a different type, then do nothing." + (when (magit-hunk-section-p section) + (magit-section-set-window-start section))) + +(add-hook 'magit-section-movement-hook #'magit-hunk-set-window-start) + (defun magit-hunk-goto-successor (section arg) (and (magit-hunk-section-p section) (when-let ((parent (magit-get-section diff --git a/lisp/magit-mode.el b/lisp/magit-mode.el index 1da4656..47adbfa 100644 --- a/lisp/magit-mode.el +++ b/lisp/magit-mode.el @@ -50,6 +50,8 @@ (declare-function magit-auto-revert-buffers "magit-autorevert" ()) ;; For `magit-refresh-buffer' (declare-function magit-process-unset-mode-line-error-status "magit-process" ()) +;; For `magit-refresh-get-relative-position' +(declare-function magit-hunk-section-p "magit-diff" (obj)) ;; For `magit-mode-setup-internal' (declare-function magit-status-goto-initial-section "magit-status" ()) ;; For `magit-mode' from `bookmark' diff --git a/lisp/magit-section.el b/lisp/magit-section.el index 6f2e364..a037a91 100644 --- a/lisp/magit-section.el +++ b/lisp/magit-section.el @@ -280,12 +280,7 @@ but that ship has sailed, thus this option." (defvar magit--current-section-hook nil "Internal variable used for `magit-describe-section'.") -(defvar magit--section-type-alist - '( - (file . magit-file-section) - (hunk . magit-hunk-section) - (module . magit-module-section) - )) +(defvar magit--section-type-alist nil) (defclass magit-section () ((keymap :initform nil :allocation :class) @@ -302,21 +297,6 @@ but that ship has sailed, thus this option." (parent :initform nil :initarg :parent) (children :initform nil))) -(defclass magit-file-section (magit-section) - ((source :initform nil) - (header :initform nil))) - -(defclass magit-hunk-section (magit-section) - ((refined :initform nil) - (combined :initform nil) - (from-range :initform nil) - (from-ranges :initform nil) - (to-range :initform nil) - (about :initform nil))) - -(defclass magit-module-section (magit-file-section) - ()) - ;;; Mode (defvar symbol-overlay-inhibit-map) @@ -560,14 +540,6 @@ If there is no previous sibling section, then move to the parent." (unless (pos-visible-in-window-p (oref section end)) (set-window-start (selected-window) (oref section start)))) -(defun magit-hunk-set-window-start (section) - "When SECTION is a `hunk', ensure that its beginning is visible. -It the SECTION has a different type, then do nothing." - (when (magit-hunk-section-p section) - (magit-section-set-window-start section))) - -(add-hook 'magit-section-movement-hook #'magit-hunk-set-window-start) - (defmacro magit-define-section-jumper (name heading type &optional value) "Define an interactive function to go some section. Together TYPE and VALUE identify the section. @@ -717,34 +689,6 @@ hidden." (t (mapc 'magit-section-hide children))))) -(defun magit-section-cycle-diffs () - "Cycle visibility of diff-related sections in the current buffer." - (interactive) - (when-let ((sections - (cond ((derived-mode-p 'magit-status-mode) - (--mapcat - (when it - (when (oref it hidden) - (magit-section-show it)) - (oref it children)) - (list (magit-get-section '((staged) (status))) - (magit-get-section '((unstaged) (status)))))) - ((derived-mode-p 'magit-diff-mode) - (-filter #'magit-file-section-p - (oref magit-root-section children)))))) - (if (--any-p (oref it hidden) sections) - (dolist (s sections) - (magit-section-show s) - (magit-section-hide-children s)) - (let ((children (--mapcat (oref it children) sections))) - (cond ((and (--any-p (oref it hidden) children) - (--any-p (oref it children) children)) - (mapc 'magit-section-show-headings sections)) - ((-any-p 'magit-section-hidden-body children) - (mapc 'magit-section-show-children sections)) - (t - (mapc 'magit-section-hide sections))))))) - (defun magit-section-hidden-body (section &optional pred) (--if-let (oref section children) (funcall (or pred '-any-p) 'magit-section-hidden-body it) |
