From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Tassilo Horn Newsgroups: gmane.emacs.devel Subject: Re: [Eshell patch] Visual subcommands and options Date: Sat, 01 Jun 2013 11:49:35 +0200 Message-ID: <8761xyb1ow.fsf@thinkpad.tsdh.de> References: <87ehcn4drw.fsf@thinkpad.tsdh.de> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1370080184 22926 80.91.229.3 (1 Jun 2013 09:49:44 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 1 Jun 2013 09:49:44 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Jun 01 11:49:44 2013 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1UiiRU-0000lw-3t for ged-emacs-devel@m.gmane.org; Sat, 01 Jun 2013 11:49:44 +0200 Original-Received: from localhost ([::1]:36107 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UiiRT-0004VR-IJ for ged-emacs-devel@m.gmane.org; Sat, 01 Jun 2013 05:49:43 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:36647) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UiiRO-0004Tl-Sm for emacs-devel@gnu.org; Sat, 01 Jun 2013 05:49:41 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UiiRN-00025G-Dy for emacs-devel@gnu.org; Sat, 01 Jun 2013 05:49:38 -0400 Original-Received: from out1-smtp.messagingengine.com ([66.111.4.25]:45841) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UiiRN-00025B-9h for emacs-devel@gnu.org; Sat, 01 Jun 2013 05:49:37 -0400 Original-Received: from compute4.internal (compute4.nyi.mail.srv.osa [10.202.2.44]) by gateway1.nyi.mail.srv.osa (Postfix) with ESMTP id 1A64D20905 for ; Sat, 1 Jun 2013 05:49:37 -0400 (EDT) Original-Received: from frontend2.nyi.mail.srv.osa ([10.202.2.161]) by compute4.internal (MEProxy); Sat, 01 Jun 2013 05:49:37 -0400 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=from:to:subject:references:date :in-reply-to:message-id:mime-version:content-type; s=smtpout; bh=f51ZlXkOKGwJ0xZ9detLOefosko=; b=F/gho+GKKieZQF4fX6vdvnBtLSYB twuDj5Aox6VX6qRfuadCflzqIbCWEKixT33oIAI45cwZsK1/h7u0RLz6i/4CfuFY QePPnv57Z1nf62L4VvehuPq5vI2DdmFsS7f1DlxsMtNyV56NfTJQ5hpLyHT2XN6x zckf43J0/j9QEww= X-Sasl-enc: lI3lm5Xxv+V35fRDWbB4UB9VFTfPPY3+WpOmVBzExLIX 1370080176 Original-Received: from thinkpad.tsdh.de (unknown [91.67.10.84]) by mail.messagingengine.com (Postfix) with ESMTPA id 7E6452001E0 for ; Sat, 1 Jun 2013 05:49:36 -0400 (EDT) Mail-Followup-To: emacs-devel@gnu.org In-Reply-To: <87ehcn4drw.fsf@thinkpad.tsdh.de> (Tassilo Horn's message of "Fri, 31 May 2013 12:58:11 +0200") User-Agent: Gnus/5.130008 (Ma Gnus v0.8) Emacs/24.3.50 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 66.111.4.25 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:159964 Archived-At: --=-=-= Content-Type: text/plain Hi, here's a slightly updated version. The most prominent change is that the new variables are now usual alists with entries (COMMAND SUBCOMMAND...) and (COMMAND OPTION...) instead of the subcommands and options wrapped into yet another list. The reason it was that way previously was that I didn't find the `cons' custom type. ;-) Bye, Tassilo --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=eshell-visual.patch === modified file 'lisp/ChangeLog' --- lisp/ChangeLog 2013-06-01 03:38:36 +0000 +++ lisp/ChangeLog 2013-06-01 09:07:09 +0000 @@ -1,3 +1,22 @@ +2013-06-01 Tassilo Horn + + * 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-06-01 Leo Liu * progmodes/octave.el (octave-mode-syntax-table): Give `.' === 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 11:02:17 +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 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-06-01 09:16:43 +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 (cons (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, a sensible entry would be + + (\"git\" \"--help\") + +because \"git --help\" shows the command's +documentation with a pager." + :type '(repeat (cons (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 to be handled by Emacs key in visual buffers. -See the variable `eshell-visual-commands'. If this variable is set to -nil, 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, 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) + (let ((command (file-name-nondirectory command))) + (or (member command eshell-visual-commands) + (member (car args) + (cdr (assoc command eshell-visual-subcommands))) + (intersection args + (cdr (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 14:48:30 +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 of arity 2 receiving the COMMAND and its +ARGS (a list). 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 #!." @@ -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))))))) --=-=-=--