all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Matthew Bauer <mjbauer95@gmail.com>
To: emacs-devel@gnu.org
Subject: [PATCH] Make eshell ‘ls’ output clickable.
Date: Wed, 5 Jul 2017 21:31:15 -0700	[thread overview]
Message-ID: <595e6b24.c39f620a.f530.2881@mx.google.com> (raw)

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




             reply	other threads:[~2017-07-06  4:31 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-06  4:31 Matthew Bauer [this message]
2017-07-07 15:08 ` [PATCH] Make eshell ‘ls’ output clickable 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

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=595e6b24.c39f620a.f530.2881@mx.google.com \
    --to=mjbauer95@gmail.com \
    --cc=emacs-devel@gnu.org \
    /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.