all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Jonathan Kyle Mitchell <kyle@jonathanmitchell.org>
To: Noam Postavsky <npostavs@gmail.com>
Cc: 30724@debbugs.gnu.org, Yegor Timoshenko <yegortimoshenko@riseup.net>
Subject: bug#30724: eshell: escaped tilde is not treated as such
Date: Sun, 15 Jul 2018 12:18:26 -0500	[thread overview]
Message-ID: <88c6e336a6a9a5362a1e878b2df9d7ffffc61f7a.camel@jonathanmitchell.org> (raw)
In-Reply-To: <87zhz2dfed.fsf@gmail.com>

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

On Sat, 2018-07-07 at 15:17 -0400, Noam Postavsky wrote:
> Perhaps we should distinguish between file and non-numeric arguments
> though?  E.g., I think the file-name-quote might not make sense for
> the
> commands below:
> 
> > ./esh-proc.el\0202:(put 'eshell/kill 'eshell-no-numeric-conversions 
> > t)
> > ./em-unix.el\0167:(put 'eshell/man 'eshell-no-numeric-conversions
> > t)
> > ./em-unix.el\0664:(put 'eshell/make 'eshell-no-numeric-conversions
> > t)
> > ./em-unix.el\01050:(put 'eshell/locate 'eshell-no-numeric-
> > conversions 
> > ./em-unix.el\01059:(put 'eshell/occur 'eshell-no-numeric-
> > conversions t)
> > ./esh-cmd.el\01185:(put 'eshell/which 'eshell-no-numeric-
> > conversions t)
> > ./em-tramp.el\097:(put 'eshell/su 'eshell-no-numeric-conversions t)
> > ./em-tramp.el\0139:(put 'eshell/sudo 'eshell-no-numeric-conversions 
> > t)

After tracing through the execution of eshell some more, I noticed that
eshell sets an escaped text property on the arguments when the user
escaped them with `\' or quote characters but there is nothing in
eshell that does anything with it apparently.

I've attached a new patch that checks for the escaped text property on
any single character argumentand.  I've also added a new symbol
property to the following functions that take filename arguments and
use that to check instead of the eshell-no-numeric-conversions
property.

(eshell/cd)
(eshell/pushd)
(eshell/popd)
(eshell/ls)
(eshell/rm)
(eshell/mkdir)
(eshell/rmdir)
(eshell/mv)
(eshell/cp)
(eshell/ln)
(eshell/cat)
(eshell/du)
(eshell/diff)
(eshell/addpath)

> 
> The ChangeLog item should at the beginning, as in,
> 
> * lisp/eshell/esh-cmd.el (eshell-lisp-command): Fix bug#30724 by
> checking if "*" and "~" are arguments to the current command ...

Thanks for the comments and suggestions, I fixed the commit message in the new patch.

--
Jonathan Kyle Mitchell

[-- Attachment #2: 0001-Check-for-special-filenames-in-eshell-Bug-30724.patch --]
[-- Type: text/x-patch, Size: 6833 bytes --]

From 98c15a273b0fff39447427a47442856ce1161bad Mon Sep 17 00:00:00 2001
From: Jonathan Kyle Mitchell <kyle@jonathanmitchell.org>
Date: Sun, 15 Jul 2018 10:57:23 -0500
Subject: [PATCH] Check for special filenames in eshell (Bug#30724)

	* lisp/eshell/em-dirs.el (eshell/cd): Add
	eshell-escape-special-filenames to symbol plist.
	(eshell/pushd): Likewise.
	(eshell/popd): Likewise.

	* lisp/eshell/em-ls.el (eshell/ls): Add
	eshell-escape-special-filenames to symbol plist.

	* lisp/eshell/em-unix.el (eshell/rm): Add
	eshell-escape-special-filenames to symbol plist.
	(eshell/mkdir): Likewise.
	(eshell/rmdir): Likewise.
	(eshell/mv): Likewise.
	(eshell/cp): Likewise.
	(eshell/ln): Likewise.
	(eshell/cat): Likewise.
	(eshell/du): Likewise.
	(eshell/diff): Likewise.

	* lisp/eshell/esh-cmd.el (eshell-lisp-command):	Check for
	single character escaped string arguments (Bug#30724).

	* lisp/eshell/esh-ext.el (eshell/addpath): Add
	eshell-escape-special-filenames to symbol plist.
---
 lisp/eshell/em-dirs.el |  3 +++
 lisp/eshell/em-ls.el   |  1 +
 lisp/eshell/em-unix.el | 10 ++++++++++
 lisp/eshell/esh-cmd.el | 32 +++++++++++++++++++++-----------
 lisp/eshell/esh-ext.el |  1 +
 5 files changed, 36 insertions(+), 11 deletions(-)

diff --git a/lisp/eshell/em-dirs.el b/lisp/eshell/em-dirs.el
index ec380e6701..25dd6e0887 100644
--- a/lisp/eshell/em-dirs.el
+++ b/lisp/eshell/em-dirs.el
@@ -407,6 +407,7 @@ eshell/cd
 	nil))))
 
 (put 'eshell/cd 'eshell-no-numeric-conversions t)
+(put 'eshell/cd 'eshell-escape-special-filenames t)
 
 (defun eshell-add-to-dir-ring (path)
   "Add PATH to the last-dir-ring, if applicable."
@@ -470,6 +471,7 @@ eshell/pushd
   nil)
 
 (put 'eshell/pushd 'eshell-no-numeric-conversions t)
+(put 'eshell/pushd 'eshell-escape-special-filenames t)
 
 ;;; popd [+n]
 (defun eshell/popd (&rest args)
@@ -500,6 +502,7 @@ eshell/popd
   nil)
 
 (put 'eshell/popd 'eshell-no-numeric-conversions t)
+(put 'eshell/popd 'eshell-escape-special-filenames t)
 
 (defun eshell/dirs (&optional if-verbose)
   "Implementation of dirs in Lisp."
diff --git a/lisp/eshell/em-ls.el b/lisp/eshell/em-ls.el
index 900b28905b..3995bd9c61 100644
--- a/lisp/eshell/em-ls.el
+++ b/lisp/eshell/em-ls.el
@@ -334,6 +334,7 @@ eshell/ls
     (apply 'eshell-do-ls args)))
 
 (put 'eshell/ls 'eshell-no-numeric-conversions t)
+(put 'eshell/ls 'eshell-escape-special-filenames t)
 
 (declare-function eshell-glob-regexp "em-glob" (pattern))
 
diff --git a/lisp/eshell/em-unix.el b/lisp/eshell/em-unix.el
index a18fb85507..e821b315b8 100644
--- a/lisp/eshell/em-unix.el
+++ b/lisp/eshell/em-unix.el
@@ -307,6 +307,7 @@ eshell/rm
    nil))
 
 (put 'eshell/rm 'eshell-no-numeric-conversions t)
+(put 'eshell/rm 'eshell-escape-special-filenames t)
 
 (defun eshell/mkdir (&rest args)
   "Implementation of mkdir in Lisp."
@@ -324,6 +325,7 @@ eshell/mkdir
    nil))
 
 (put 'eshell/mkdir 'eshell-no-numeric-conversions t)
+(put 'eshell/mkdir 'eshell-escape-special-filenames t)
 
 (defun eshell/rmdir (&rest args)
   "Implementation of rmdir in Lisp."
@@ -340,6 +342,7 @@ eshell/rmdir
    nil))
 
 (put 'eshell/rmdir 'eshell-no-numeric-conversions t)
+(put 'eshell/rmdir 'eshell-escape-special-filenames t)
 
 (defvar no-dereference)
 
@@ -524,6 +527,7 @@ eshell/mv
 			     eshell-mv-overwrite-files))))
 
 (put 'eshell/mv 'eshell-no-numeric-conversions t)
+(put 'eshell/mv 'eshell-escape-special-filenames t)
 
 (defun eshell/cp (&rest args)
   "Implementation of cp in Lisp."
@@ -561,6 +565,7 @@ eshell/cp
 			   eshell-cp-overwrite-files preserve)))
 
 (put 'eshell/cp 'eshell-no-numeric-conversions t)
+(put 'eshell/cp 'eshell-escape-special-filenames t)
 
 (defun eshell/ln (&rest args)
   "Implementation of ln in Lisp."
@@ -593,6 +598,7 @@ eshell/ln
 			     eshell-ln-overwrite-files))))
 
 (put 'eshell/ln 'eshell-no-numeric-conversions t)
+(put 'eshell/ln 'eshell-escape-special-filenames t)
 
 (defun eshell/cat (&rest args)
   "Implementation of cat in Lisp.
@@ -645,6 +651,7 @@ eshell/cat
      (setq eshell-ensure-newline-p nil))))
 
 (put 'eshell/cat 'eshell-no-numeric-conversions t)
+(put 'eshell/cat 'eshell-escape-special-filenames t)
 
 ;; special front-end functions for compilation-mode buffers
 
@@ -927,6 +934,8 @@ eshell/du
 	     (eshell-print (concat (eshell-du-size-string size)
 				   "total\n"))))))))
 
+(put 'eshell/du 'eshell-escape-special-filenames t)
+
 (defvar eshell-time-start nil)
 
 (defun eshell-show-elapsed-time ()
@@ -1029,6 +1038,7 @@ eshell/diff
   nil)
 
 (put 'eshell/diff 'eshell-no-numeric-conversions t)
+(put 'eshell/diff 'eshell-escape-special-filenames t)
 
 (defvar locate-history-list)
 
diff --git a/lisp/eshell/esh-cmd.el b/lisp/eshell/esh-cmd.el
index 61c0ebc71d..8d52b9fc9c 100644
--- a/lisp/eshell/esh-cmd.el
+++ b/lisp/eshell/esh-cmd.el
@@ -1310,17 +1310,27 @@ eshell-lisp-command
 		  (setq eshell-last-arguments args
 			eshell-last-command-name
 			(concat "#<function " (symbol-name object) ">"))
-		  ;; if any of the arguments are flagged as numbers
-		  ;; waiting for conversion, convert them now
-		  (unless (get object 'eshell-no-numeric-conversions)
-		    (while args
-		      (let ((arg (car args)))
-			(if (and (stringp arg)
-				 (> (length arg) 0)
-				 (not (text-property-not-all
-				       0 (length arg) 'number t arg)))
-			    (setcar args (string-to-number arg))))
-		      (setq args (cdr args))))
+		  (let ((numeric (not (get object
+                                           'eshell-no-numeric-conversions)))
+			(escaped (get object 'eshell-escape-special-filenames)))
+		    (when (or numeric escaped)
+		      (while args
+			(let ((arg (car args)))
+			  (cond ((and numeric (stringp arg) (> (length arg) 0)
+				      (text-property-any 0 (length arg)
+							 'number t arg))
+				 ;; if any of the arguments are flagged as
+				 ;; numbers waiting for conversion, convert
+				 ;; them now
+				 (setcar args (string-to-number arg)))
+				((and escaped (stringp arg) (= (length arg) 1)
+				      (text-property-any 0 (length arg)
+							 'escaped t arg))
+				 ;; if any of the arguments are single
+				 ;; character escaped filenames,
+				 ;; prepend "./"
+				 (setcar args (concat "./" arg)))))
+			(setq args (cdr args)))))
 		  (eshell-apply object eshell-last-arguments))
 	      (setq eshell-last-arguments args
 		    eshell-last-command-name "#<Lisp object>")
diff --git a/lisp/eshell/esh-ext.el b/lisp/eshell/esh-ext.el
index ba5182deb4..8cb0f685a4 100644
--- a/lisp/eshell/esh-ext.el
+++ b/lisp/eshell/esh-ext.el
@@ -259,6 +259,7 @@ eshell/addpath
        (eshell-printn dir)))))
 
 (put 'eshell/addpath 'eshell-no-numeric-conversions t)
+(put 'eshell/addpath 'eshell-escape-special-filenames t)
 
 (defun eshell-script-interpreter (file)
   "Extract the script to run from FILE, if it has #!<interp> in it.
-- 
2.17.1


  reply	other threads:[~2018-07-15 17:18 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-06  4:30 bug#30724: eshell: escaped tilde is not treated as such Yegor Timoshenko
2018-03-09  1:15 ` Noam Postavsky
2018-07-06  7:24 ` Jonathan Kyle Mitchell
2018-07-07 19:17   ` Noam Postavsky
2018-07-15 17:18     ` Jonathan Kyle Mitchell [this message]
2018-07-17  0:14       ` Noam Postavsky
2018-07-18  3:54         ` Jonathan Kyle Mitchell
2018-07-22  1:34           ` Noam Postavsky

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=88c6e336a6a9a5362a1e878b2df9d7ffffc61f7a.camel@jonathanmitchell.org \
    --to=kyle@jonathanmitchell.org \
    --cc=30724@debbugs.gnu.org \
    --cc=npostavs@gmail.com \
    --cc=yegortimoshenko@riseup.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.