* bug#60385: patch to shell.el: sticky-shell-mode
@ 2022-12-28 15:42 Andrew De Angelis
0 siblings, 0 replies; only message in thread
From: Andrew De Angelis @ 2022-12-28 15:42 UTC (permalink / raw)
To: 60385
[-- Attachment #1.1: Type: text/plain, Size: 574 bytes --]
I wrote a minor mode to allow shells to always show the previous prompt in
a "sticky" header.
This makes it easy to keep track of which commands have been run (even when
the commands trigger many lines of output).
I originally intended to publish this as a package. I emailed
emacs-devel@gnu.org with this intent (check the thread "New Package:
sticky-shell"). It was pointed out that this could just be added to
shell.el: it's just a few lines and the utility could be useful.
Let me know your thoughts, and if you'd like me to make any changes to the
code.
Best,
Andrew
[-- Attachment #1.2: Type: text/html, Size: 763 bytes --]
[-- Attachment #2: 0001-sticky-shell-mode.patch --]
[-- Type: application/octet-stream, Size: 3261 bytes --]
From a0a1798f818fa7339301c1d695bd00f0e8f630b4 Mon Sep 17 00:00:00 2001
From: andyjda <bobodeangelis@gmail.com>
Date: Wed, 28 Dec 2022 10:23:26 -0500
Subject: [PATCH] sticky-shell-mode
typo
better documentation
---
lisp/shell.el | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 65 insertions(+)
diff --git a/lisp/shell.el b/lisp/shell.el
index 727f2aa0dd..5121091644 100644
--- a/lisp/shell.el
+++ b/lisp/shell.el
@@ -96,6 +96,7 @@
;;; Code:
(require 'comint)
+(require 'eshell)
(require 'pcomplete)
(eval-when-compile (require 'files-x)) ;with-connection-local-variables
(require 'subr-x)
@@ -372,6 +373,17 @@ shell-kill-buffer-on-exit
:group 'shell
:version "29.1")
+(defcustom sticky-shell-get-prompt
+ #'sticky-shell-prompt-above-visible
+ "Function used by `sticky-shell-mode' to pick the prompt to show in the header.
+Available values are: `sticky-shell-latest-prompt',
+`sticky-shell-prompt-above-visible',
+`sticky-shell-prompt-above-cursor',
+or you can write your own function and assign it to this variable."
+ :group 'shell
+ :type 'function)
+
+
(defvar shell-mode-map
(let ((map (make-sparse-keymap)))
(define-key map "\C-c\C-f" 'shell-forward-command)
@@ -1770,6 +1782,59 @@ shell-highlight-undef-mode-restart
(when shell-highlight-undef-mode
(shell-highlight-undef-mode 1)))
+;;; Show a header with relevant prompt
+(defun sticky-shell-current-line-trimmed ()
+ "Return the current line and remove trailing whitespace."
+ (let ((prompt (or (thing-at-point 'line) "")))
+ (string-trim-right prompt "[ \t\n\r]+"))) ; remove the newline ending char
+
+(defun shell-previous-prompt (n)
+ "Move to end of Nth previous prompt in the buffer.
+Depending on the current mode, call `comint-previous-prompt'
+or `eshell-previous-prompt'."
+ (if (derived-mode-p 'eshell-mode)
+ (eshell-previous-prompt n)
+ (comint-previous-prompt n)))
+
+(defun sticky-shell-latest-prompt ()
+ "Get the latest prompt that was run."
+ (interactive)
+ (save-excursion
+ (goto-char (point-max))
+ (forward-line -1)
+ (shell-previous-prompt 1)
+ (sticky-shell-current-line-trimmed)))
+
+(defun sticky-shell-prompt-above-visible ()
+ "Get the prompt above the top visible line in the current window.
+This ensures that the prompt in the header corresponds to top output-line"
+ (interactive)
+ (save-excursion
+ (goto-char (window-start))
+ (shell-previous-prompt 1)
+ (sticky-shell-current-line-trimmed)))
+
+(defun sticky-shell-prompt-above-cursor ()
+ "Get the prompt above the cursor's current line."
+ (interactive)
+ (save-excursion
+ (move-beginning-of-line 1)
+ (shell-previous-prompt 1)
+ (sticky-shell-current-line-trimmed)))
+
+;;;###autoload
+(define-minor-mode sticky-shell-mode
+ "Minor mode to show the previous prompt as a sticky header.
+Which prompt to pick depends on the value of `sticky-shell-get-prompt'."
+ :group 'comint
+ :global nil
+ :lighter nil
+ (if sticky-shell-mode
+ (setq-local header-line-format
+ (list '(:eval
+ (funcall sticky-shell-get-prompt))))
+ (setq-local header-line-format nil)))
+
(provide 'shell)
;;; shell.el ends here
--
2.37.1 (Apple Git-137.1)
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2022-12-28 15:42 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-28 15:42 bug#60385: patch to shell.el: sticky-shell-mode Andrew De Angelis
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.