unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* [Eshell patch] Visual subcommands and options
@ 2013-05-31 10:58 Tassilo Horn
  2013-06-01  9:49 ` Tassilo Horn
  2013-06-01 21:41 ` Aidan Gauland
  0 siblings, 2 replies; 16+ messages in thread
From: Tassilo Horn @ 2013-05-31 10:58 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 894 bytes --]

Hi all,

eshell shows the output of commands in `eshell-visual-commands' in a
term buffer.  Those are typically interactive commands that show their
results in a pager or other interactive facility.  Typical commands like
that are top, less, more, etc.

However, until now you could only say "this command is visual".  But
there are many commands I use regularly that usually are not visual
except when they are called with some special option or subcommand.
Typical examples are several VCS commands such as "git log", "git show",
"git diff", or "hg log" which show their output with a pager by default
and thus are then visual in eshell's sense.

This patch adds two new defcustoms `eshell-visual-subcommands' and
`eshell-visual-options' that lets you also specifiy commands with
certain subcommands and options that make them visual.

Any objections to installing this patch?

Bye,
Tassilo


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: eshell-visual.patch --]
[-- Type: text/x-diff, Size: 6973 bytes --]

=== modified file 'lisp/ChangeLog'
--- lisp/ChangeLog	2013-05-31 07:34:56 +0000
+++ lisp/ChangeLog	2013-05-31 10:30:34 +0000
@@ -1,3 +1,22 @@
+2013-05-31  Tassilo Horn  <tsdh@gnu.org>
+
+	* eshell/esh-ext.el (eshell-external-command): Pass args to
+	`eshell-find-interpreter'.
+	(eshell-find-interpreter): Add new second parameter ARGS.
+
+	* eshell/em-script.el (eshell-script-initialize): Add second arg
+	to the function added as MATCH to `eshell-interpreter-alist'
+
+	* eshell/em-dirs.el (eshell-dirs-initialize): Add second arg to
+	the function added as MATCH to `eshell-interpreter-alist'
+
+	* eshell/em-term.el (eshell-visual-subcommands): New defcustom.
+	(eshell-visual-options): New defcustom.
+	(eshell-escape-control-x): Adapt docstring.
+	(eshell-term-initialize): Test `eshell-visual-subcommands' and
+	`eshell-visual-options' in addition to `eshell-visual-commands'.
+	(eshell-exec-visual): Pass args to `eshell-find-interpreter'.
+
 2013-05-31  Glenn Morris  <rgm@gnu.org>
 
 	* obsolete/sym-comp.el (symbol-complete):

=== modified file 'lisp/eshell/em-dirs.el'
--- lisp/eshell/em-dirs.el	2013-01-01 09:11:05 +0000
+++ lisp/eshell/em-dirs.el	2013-05-31 10:29:59 +0000
@@ -207,7 +207,8 @@
   (when eshell-cd-on-directory
     (make-local-variable 'eshell-interpreter-alist)
     (setq eshell-interpreter-alist
-	  (cons (cons 'eshell-lone-directory-p
+	  (cons (cons (lambda (file args)
+			(eshell-lone-directory-p file))
 		      'eshell-dirs-substitute-cd)
 		eshell-interpreter-alist)))
 

=== modified file 'lisp/eshell/em-script.el'
--- lisp/eshell/em-script.el	2013-01-01 09:11:05 +0000
+++ lisp/eshell/em-script.el	2013-05-31 10:27:19 +0000
@@ -61,7 +61,7 @@
   "Initialize the script parsing code."
   (make-local-variable 'eshell-interpreter-alist)
   (setq eshell-interpreter-alist
-	(cons '((lambda (file)
+	(cons '((lambda (file ignore-args)
 		  (string= (file-name-nondirectory file)
 			   "eshell")) . eshell/source)
 	      eshell-interpreter-alist))

=== modified file 'lisp/eshell/em-term.el'
--- lisp/eshell/em-term.el	2013-05-23 04:57:27 +0000
+++ lisp/eshell/em-term.el	2013-05-31 10:56:17 +0000
@@ -65,6 +65,39 @@
   :type '(repeat string)
   :group 'eshell-term)
 
+(defcustom eshell-visual-subcommands
+  nil
+  "An alist of the form
+
+  ((COMMAND1 (SUBCOMMAND1 SUBCOMMAND2...))
+   (COMMAND2 (SUBCOMMAND1 ...)))
+
+of commands with subcommands that present their output in a
+visual fashion.  A likely entry is
+
+  (\"git\" (\"log\" \"diff\" \"show\"))
+
+because git shows logs and diffs using a pager by default."
+  :type '(repeat (list (string :tag "Command")
+		       (repeat (string :tag "Subcommand")))))
+
+(defcustom eshell-visual-options
+  nil
+  "An alist of the form
+
+  ((COMMAND1 (OPTION1 OPTION2...))
+   (COMMAND2 (OPTION1 ...)))
+
+of commands with options that present their output in a visual
+fashion.  For example, an entry for a hypothetical foo command
+
+  (\"foo\" (\"--with-more\" \"--with-less\"))
+
+would show the foo output visually if it was called with the
+--with-more or --with-less option."
+  :type '(repeat (list (string :tag "Command")
+		       (repeat (string :tag "Option")))))
+
 ;; If you change this from term-term-name, you need to ensure that the
 ;; value you choose exists in the system's terminfo database.  (Bug#12485)
 (defcustom eshell-term-name term-term-name
@@ -77,8 +110,10 @@
 
 (defcustom eshell-escape-control-x t
   "If non-nil, allow <C-x> to be handled by Emacs key in visual buffers.
-See the variable `eshell-visual-commands'.  If this variable is set to
-nil, <C-x> will send that control character to the invoked process."
+See the variables `eshell-visual-commands',
+`eshell-visual-subcommands', and `eshell-visual-options'.  If
+this variable is set to nil, <C-x> will send that control
+character to the invoked process."
   :type 'boolean
   :group 'eshell-term)
 
@@ -93,9 +128,14 @@
   (make-local-variable 'eshell-interpreter-alist)
   (setq eshell-interpreter-alist
 	(cons (cons (function
-		     (lambda (command)
-		       (member (file-name-nondirectory command)
-			       eshell-visual-commands)))
+		     (lambda (command args)
+		       (or (member (file-name-nondirectory command)
+				   eshell-visual-commands)
+			   (member (car args)
+				   (cadr (assoc command eshell-visual-subcommands)))
+			   (intersection args
+					 (cadr (assoc command eshell-visual-options))
+					 :test 'string=))))
 		    'eshell-exec-visual)
 	      eshell-interpreter-alist)))
 
@@ -104,7 +144,7 @@
 ARGS are passed to the program.  At the moment, no piping of input is
 allowed."
   (let* (eshell-interpreter-alist
-	 (interp (eshell-find-interpreter (car args)))
+	 (interp (eshell-find-interpreter (car args) (cdr args)))
 	 (program (car interp))
 	 (args (eshell-flatten-list
 		(eshell-stringify-list (append (cdr interp)

=== modified file 'lisp/eshell/esh-ext.el'
--- lisp/eshell/esh-ext.el	2013-05-23 04:57:27 +0000
+++ lisp/eshell/esh-ext.el	2013-05-31 10:26:23 +0000
@@ -125,9 +125,10 @@
 
   (MATCH . INTERPRETER)
 
-MATCH should be a regexp, which is matched against the command name,
-or a function.  If either returns a non-nil value, then INTERPRETER
-will be used for that command.
+MATCH should be a regexp, which is matched against the command
+name, or a function receiving a command and its args.  If either
+returns a non-nil value, then INTERPRETER will be used for that
+command.
 
 If INTERPRETER is a string, it will be called as the command name,
 with the original command name passed as the first argument, with all
@@ -215,6 +216,7 @@
   (setq args (eshell-stringify-list (eshell-flatten-list args)))
   (let ((interp (eshell-find-interpreter
 		 command
+		 args
 		 ;; `eshell-find-interpreter' does not work correctly
 		 ;; for Tramp file name syntax.  But we don't need to
 		 ;; know the interpreter in that case, therefore the
@@ -267,7 +269,7 @@
 		(list (match-string 1)
 		      file)))))))
 
-(defun eshell-find-interpreter (file &optional no-examine-p)
+(defun eshell-find-interpreter (file args &optional no-examine-p)
   "Find the command interpreter with which to execute FILE.
 If NO-EXAMINE-P is non-nil, FILE will not be inspected for a script
 line of the form #!<interp>."
@@ -277,8 +279,9 @@
 	    (dolist (possible eshell-interpreter-alist)
 	      (cond
 	       ((functionp (car possible))
-		(and (funcall (car possible) file)
-		     (throw 'found (cdr possible))))
+		(let ((fn (car possible)))
+		  (and (funcall fn file args)
+		       (throw 'found (cdr possible)))))
 	       ((stringp (car possible))
 		(and (string-match (car possible) file)
 		     (throw 'found (cdr possible))))
@@ -312,7 +315,7 @@
 	    (setq interp (eshell-script-interpreter fullname))
 	    (if interp
 		(setq interp
-		      (cons (car (eshell-find-interpreter (car interp) t))
+		      (cons (car (eshell-find-interpreter (car interp) args t))
 			    (cdr interp)))))
 	  (or interp (list fullname)))))))
 


^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2013-06-10  8:20 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-05-31 10:58 [Eshell patch] Visual subcommands and options Tassilo Horn
2013-06-01  9:49 ` Tassilo Horn
2013-06-01 21:41 ` Aidan Gauland
2013-06-02  9:28   ` Tassilo Horn
2013-06-03  0:11     ` Aidan Gauland
2013-06-03  7:15       ` Tassilo Horn
2013-06-03 20:04         ` Aidan Gauland
     [not found]           ` <87hahel63t.fsf_-_@thinkpad.tsdh.de>
2013-06-07  3:56             ` Some more eshell problems Aidan Gauland
2013-06-07 11:38               ` Tassilo Horn
2013-06-07 12:39                 ` Thierry Volpiatto
2013-06-07 16:25                   ` Tassilo Horn
2013-06-09  7:07         ` Eshell visual commands with redirection bug Aidan Gauland
2013-06-09  9:47           ` Tassilo Horn
2013-06-10  1:41             ` Aidan Gauland
2013-06-10  7:21               ` Tassilo Horn
2013-06-10  8:20                 ` Aidan Gauland

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).