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

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

[elpa] externals/hyperbole aad4494 40/50: Add smart-magit-tab: Do what T


From: Stefan Monnier
Subject: [elpa] externals/hyperbole aad4494 40/50: Add smart-magit-tab: Do what TAB or RET does
Date: Wed, 17 Mar 2021 18:44:21 -0400 (EDT)

branch: externals/hyperbole
commit aad4494633bc32cfeb71978f141e500094a52f55
Author: Bob Weiner <rsw@gnu.org>
Commit: Bob Weiner <rsw@gnu.org>

    Add smart-magit-tab: Do what TAB or RET does
---
 hib-social.el |  6 +++---
 hui-mouse.el  | 42 +++++++++++++++++++++++++++---------------
 hypb.el       | 19 ++++++++++++++++---
 3 files changed, 46 insertions(+), 21 deletions(-)

diff --git a/hib-social.el b/hib-social.el
index 1d32247..5a54ac1 100644
--- a/hib-social.el
+++ b/hib-social.el
@@ -610,10 +610,10 @@ PROJECT value is provided, it defaults to the value of
   "Display the diff for a git commit reference, e.g. \"commit a55e21\", 
typically produced by git log."
   (when (save-excursion
          (beginning-of-line)
-         (looking-at "\\s-*\\(commit 
\\([0-9a-f][0-9a-f][0-9a-f][0-9a-f]+\\)\\)\\s-"))
+         (looking-at "\\(^\\|\\s-+\\)\\(commit 
#?\\([0-9a-f][0-9a-f][0-9a-f][0-9a-f]+\\)\\)\\(\\s-\\|$\\)"))
     (save-match-data
-      (ibut:label-set (match-string-no-properties 1) (match-beginning 1) 
(match-end 1)))
-    (hact #'git-reference (match-string-no-properties 2))))
+      (ibut:label-set (match-string-no-properties 2) (match-beginning 2) 
(match-end 2)))
+    (hact #'git-reference (match-string-no-properties 3))))
 
 (defvar hibtypes-git-repos-cache
   (expand-file-name "Local-Git-Repos" hbmap:dir-user)
diff --git a/hui-mouse.el b/hui-mouse.el
index 02ad2ce..8fef759 100644
--- a/hui-mouse.el
+++ b/hui-mouse.el
@@ -55,11 +55,6 @@
 (defun assist-key-error ()
   (hypb:error "(Hyperbole Assist Key): No action defined for this context; try 
another location"))
 
-(defcustom smart-magit-listing-modes '(magit-blame-mode magit-log-mode)
-  "*List of major modes for which the Action Key should run RET instead of 
TAB."
-  :type '(group 'function)
-  :group 'hyperbole)
-
 (defcustom action-key-default-function #'action-key-error
   "*Function run by the Action Key in an unspecified context.
 Set it to #'hyperbole if you want it to display the Hyperbole minibuffer menu."
@@ -1274,20 +1269,17 @@ selected buffer.
 If key is pressed:
  (1) on the last line, quit from the magit mode (\"q\" key binding);
  (2) at the end of a line, scroll up a windowful;
- (3) on a line within a `smart-magit-listing-modes' buffer, jump to
-     the thing at point (\"RET\" key binding).
- (4) anywhere else, hide/show the thing at point (\"TAB\" key binding)."
+ (3) anywhere else, hide/show the thing at point (\"TAB\" key binding)
+     unless that does nothing in the mode, then jump to the thing at
+     point (\"RET\" key binding)."
   (interactive)
   (cond ((last-line-p)
         (call-interactively (key-binding "q")))
        ((eolp)
         (smart-scroll-up))
-       ((memq major-mode smart-magit-listing-modes)
-        (setq current-prefix-arg 1)
-        (let ((magit-display-file-buffer-function #'hpath:display-buffer))
-          (call-interactively (key-binding "\r"))))
        (t
-        (call-interactively (key-binding "\t")))))
+        (let ((magit-display-file-buffer-function #'hpath:display-buffer))
+          (call-interactively #'smart-magit-tab)))))
 
 (defun smart-magit-assist ()
   "Use an assist key or mouse key to jump to source and to hide/show changes.
@@ -1307,10 +1299,30 @@ If assist-key is pressed:
        ((eolp)
         (smart-scroll-down))
        (t
-        (setq current-prefix-arg 1)
-        (let ((magit-display-file-buffer-function #'hpath:display-buffer))
+        (let ((magit-display-file-buffer-function #'hpath:display-buffer)
+              (current-prefix-arg))
           (call-interactively (key-binding "\r"))))))
 
+;; Thanks to Jonas Bernoulli <tarsius>, magit author, for this code.
+(defun smart-magit-tab (section)
+  ;; Usage: (define-key magit-section-mode-map "TAB" 'smart-magit-tab
+  "Toggle visibility of the body of the current section."
+  (interactive (list (magit-current-section)))
+  (cond ((eq section magit-root-section)
+         (user-error "Cannot hide root section"))
+        ((or (oref section content)
+             (oref section washer))
+         (goto-char (oref section start))
+         (if (oref section hidden)
+             (magit-section-show section)
+           (magit-section-hide section)))
+        (t
+        (if-let ((command (key-binding (kbd "RET"))))
+             (progn (setq last-command-event ?\()
+                    (setq this-command command)
+                    (call-interactively command))
+           (user-error "Nothing to visit either")))))
+
 ;;; ************************************************************************
 ;;; smart-man functions
 ;;; ************************************************************************
diff --git a/hypb.el b/hypb.el
index 520ce18..bd48db5 100644
--- a/hypb.el
+++ b/hypb.el
@@ -16,7 +16,7 @@
 ;;; Other required Elisp libraries
 ;;; ************************************************************************
 
-(eval-and-compile (mapc #'require '(hversion hact locate)))
+(eval-and-compile (mapc #'require '(compile hversion hact locate)))
 
 ;;; ************************************************************************
 ;;; Public variables
@@ -245,8 +245,21 @@ Global keymap is used unless optional KEYMAP is given."
     (error msg)))
 
 (defun hypb:fgrep-git-log (string)
-  "Asynchronously list git log entries whose changesets include `string'."
-  (compile (format "git log -S'%s' --line-prefix='commit ' --oneline" string)))
+  "Asynchronously list git log entries whose changesets include `string' for 
selection and display.
+The current commit entry may be displayed with a press of RET, the Action Key 
or the Assist Key."
+  (compile (format "git log -S'%s' --line-prefix='commit ' --oneline" string)
+          #'hypb:fgrep-git-log-mode))
+
+(defun hypb:fgrep-git-log-activate (ignore1 &optional ignore2)
+  "Display git commit for the current line when `compile-goto-error' {RET} is 
used.
+Does not support use of next and previous error; simply displays the current 
one."
+  (interactive '(nil))
+  (hkey-either nil))
+
+(define-derived-mode hypb:fgrep-git-log-mode compilation-mode "Fgrep-Git-Log"
+  "Major mode (derived from `compilation-mode' for listing a matching set of 
git commits for selection and display.
+Turning on Fgrep-Git-Log mode runs the normal hook `compilation-mode-hook'."
+  (setq-local next-error-function #'hypb:fgrep-git-log-activate))
 
 (defun hypb:file-major-mode (file)
   "Return the major mode used by FILE.



reply via email to

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