[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] Make eshell ‘ls’ output clickable.

From: Matthew Bauer
Subject: [PATCH] Make eshell ‘ls’ output clickable.
Date: Wed, 5 Jul 2017 21:31:15 -0700

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 
     (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 
            (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)

reply via email to

[Prev in Thread] Current Thread [Next in Thread]