all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [PATCH] Make eshell ‘ls’ output clickable.
@ 2017-07-06  4:31 Matthew Bauer
  2017-07-07 15:08 ` Nicolas Petton
  2017-07-07 15:15 ` Nicolas Petton
  0 siblings, 2 replies; 8+ messages in thread
From: Matthew Bauer @ 2017-07-06  4:31 UTC (permalink / raw)
  To: emacs-devel

When the option ‘eshell-ls-make-clickable’ is set to t, the output of
list can be clicked with <mouse-1>. This provides a more dired-like
experience for Eshell. ‘eshell-ls-make-clickable’ defaults to nil.

It's debatable whether this is should be included in Eshell because it can fairlhy easily be provided with advising (see link below). My opinion, though, is that it's a fairly useful feature with fairly little cost and gives Eshell a more Dired-like feel.

This is based on the work of Edward O’Connor and Patrick Anderson from
the EmacsWiki (https://www.emacswiki.org/emacs/EshellEnhancedLS). The
original code was made for advising eshell-ls-decorated-name while
this patch just modifies it directly.

NOTE: this probably requires permission from both Edward and Patrick to get includes. I'm not sure what the process is for that but I've CC'd them in this email. This is my first patch submission to Emacs so hopefully I've done everything appropriately.

* lisp/eshell/em-ls.el: add functions ‘eshell-ls-find-file-at-point’,
  and ‘eshell-ls-find-file-at-mouse-click’; add customizable boolean
  setting ‘eshell-ls-make-clickable’; add keymap ‘eshell-ls-keymap’
  for decorated names
---
 lisp/eshell/em-ls.el | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/lisp/eshell/em-ls.el b/lisp/eshell/em-ls.el
index 79799db30b..93f14b4fb3 100644
--- a/lisp/eshell/em-ls.el
+++ b/lisp/eshell/em-ls.el
@@ -96,6 +96,10 @@ faster and conserves more memory."
   "If non-nil, use colors in file listings."
   :type 'boolean)
 
+(defcustom eshell-ls-make-clickable nil
+  "If non-nil, make ls output clickable."
+  :type 'boolean)
+
 (defface eshell-ls-directory
   '((((class color) (background light)) (:foreground "Blue" :weight bold))
     (((class color) (background dark)) (:foreground "SkyBlue" :weight bold))
@@ -787,6 +791,26 @@ to use, and each member of which is the width of that column
 
     (cons (or col-widths (vector max-width)) files)))
 
+(defun eshell-ls-find-file-at-point (point)
+  "RET on Eshell's `ls' output to open files.
+POINT is the point that the file is available at."
+  (interactive "d")
+  (find-file (buffer-substring-no-properties
+              (previous-single-property-change point 'help-echo)
+              (next-single-property-change point 'help-echo))))
+
+(defun eshell-ls-find-file-at-mouse-click (event)
+  "Middle click on Eshell's `ls' output to open files.
+EVENT refers to the mouse event that triggers the click."
+  (interactive "e")
+  (eshell-ls-find-file-at-point (posn-point (event-end event))))
+
+(defvar eshell-ls-keymap
+  (let ((map (make-sparse-keymap)))
+    (define-key map (kbd "<return>") 'eshell-ls-find-file-at-point)
+    (define-key map (kbd "<mouse-1>") 'eshell-ls-find-file-at-mouse-click)
+    map))
+
 (defun eshell-ls-find-column-lengths (files)
   "Find the best fitting column lengths for FILES.
 It will be returned as a vector, whose length is the number of columns
@@ -907,6 +931,12 @@ to use, and each member of which is the width of that column
 	    (add-text-properties 0 (length (car file))
 				 (list 'font-lock-face face)
 				 (car file)))))
+  (when eshell-ls-make-clickable
+    (add-text-properties 0 (length (car file))
+                         (list 'help-echo "RET, mouse-1: visit this file"
+                               'mouse-face 'highlight
+                               'keymap eshell-ls-keymap)
+                         (car file)))
   (car file))
 
 (provide 'em-ls)
-- 
2.13.2




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

end of thread, other threads:[~2017-07-08  1:54 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-07-06  4:31 [PATCH] Make eshell ‘ls’ output clickable Matthew Bauer
2017-07-07 15:08 ` Nicolas Petton
2017-07-07 16:10   ` Ted Zlatanov
2017-07-07 16:30     ` Yuri Khan
2017-07-07 18:25       ` Drew Adams
2017-07-08  1:54       ` Ted Zlatanov
2017-07-07 15:15 ` Nicolas Petton
2017-07-07 15:47   ` Eli Zaretskii

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.