2021-04-19 06:21:01 -04:00
|
|
|
;;; ol-eshell.el --- Links to Working Directories in Eshell -*- lexical-binding: t; -*-
|
2012-01-05 03:43:21 -05:00
|
|
|
|
2023-01-01 05:31:12 -05:00
|
|
|
;; Copyright (C) 2011-2023 Free Software Foundation, Inc.
|
2012-01-05 03:43:21 -05:00
|
|
|
|
2011-01-04 10:06:09 -05:00
|
|
|
;; Author: Konrad Hinsen <konrad.hinsen AT fastmail.net>
|
2012-01-05 03:43:21 -05:00
|
|
|
|
2011-12-21 03:43:48 -05:00
|
|
|
;; This file is part of GNU Emacs.
|
2012-01-05 03:43:21 -05:00
|
|
|
|
|
|
|
;; GNU Emacs is free software: you can redistribute it and/or modify
|
2011-01-04 10:06:09 -05:00
|
|
|
;; it under the terms of the GNU General Public License as published by
|
2012-01-05 03:43:21 -05:00
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
;; (at your option) any later version.
|
2011-01-04 10:06:09 -05:00
|
|
|
|
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
2017-09-13 18:52:52 -04:00
|
|
|
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
|
2012-01-05 03:43:21 -05:00
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
|
|
|
;;; Code:
|
2011-01-04 10:06:09 -05:00
|
|
|
|
2022-08-04 09:53:05 -04:00
|
|
|
(require 'org-macs)
|
|
|
|
(org-assert-version)
|
|
|
|
|
2011-01-04 10:06:09 -05:00
|
|
|
(require 'eshell)
|
|
|
|
(require 'esh-mode)
|
2018-11-26 18:04:41 -05:00
|
|
|
(require 'ol)
|
2011-01-04 10:06:09 -05:00
|
|
|
|
2019-08-21 01:26:30 -04:00
|
|
|
(declare-function eshell/pwd "em-dirs.el" (&rest args))
|
|
|
|
|
2016-07-05 10:27:03 -04:00
|
|
|
(org-link-set-parameters "eshell"
|
|
|
|
:follow #'org-eshell-open
|
|
|
|
:store #'org-eshell-store-link)
|
2011-01-04 10:06:09 -05:00
|
|
|
|
2020-02-17 05:28:50 -05:00
|
|
|
(defun org-eshell-open (link _)
|
2023-10-21 07:49:52 -04:00
|
|
|
"Switch to an eshell buffer and execute a command line for LINK.
|
|
|
|
The LINK can be just a command line (executed in the default
|
2021-09-16 06:32:43 -04:00
|
|
|
eshell buffer) or a command line prefixed by a buffer name
|
|
|
|
followed by a colon."
|
2011-01-04 10:06:09 -05:00
|
|
|
(let* ((buffer-and-command
|
2019-04-02 18:00:59 -04:00
|
|
|
(if (string-match "\\([A-Za-z0-9+*-]+\\):\\(.*\\)" link)
|
2012-08-11 13:10:44 -04:00
|
|
|
(list (match-string 1 link)
|
|
|
|
(match-string 2 link))
|
2011-01-04 10:06:09 -05:00
|
|
|
(list eshell-buffer-name link)))
|
|
|
|
(eshell-buffer-name (car buffer-and-command))
|
|
|
|
(command (cadr buffer-and-command)))
|
2012-08-11 13:10:44 -04:00
|
|
|
(if (get-buffer eshell-buffer-name)
|
2022-10-04 17:42:27 -04:00
|
|
|
(pop-to-buffer
|
|
|
|
eshell-buffer-name
|
|
|
|
(if (boundp 'display-comint-buffer-action) ; Emacs >= 29
|
|
|
|
display-comint-buffer-action
|
|
|
|
'(display-buffer-same-window (inhibit-same-window))))
|
2012-08-11 13:10:44 -04:00
|
|
|
(eshell))
|
|
|
|
(goto-char (point-max))
|
|
|
|
(eshell-kill-input)
|
|
|
|
(insert command)
|
|
|
|
(eshell-send-input)))
|
2011-01-04 10:06:09 -05:00
|
|
|
|
|
|
|
(defun org-eshell-store-link ()
|
2023-10-21 07:49:52 -04:00
|
|
|
"Store eshell link.
|
|
|
|
When opened, the link switches back to the current eshell buffer and
|
|
|
|
the current working directory."
|
2011-01-04 10:06:09 -05:00
|
|
|
(when (eq major-mode 'eshell-mode)
|
2019-08-21 01:26:30 -04:00
|
|
|
(let* ((command (concat "cd " (eshell/pwd)))
|
2011-01-04 10:06:09 -05:00
|
|
|
(link (concat (buffer-name) ":" command)))
|
2018-11-26 18:04:41 -05:00
|
|
|
(org-link-store-props
|
2012-08-03 13:03:21 -04:00
|
|
|
:link (concat "eshell:" link)
|
2011-01-04 10:06:09 -05:00
|
|
|
:description command))))
|
|
|
|
|
2019-03-01 19:01:32 -05:00
|
|
|
(provide 'ol-eshell)
|
2011-01-04 10:06:09 -05:00
|
|
|
|
2019-03-01 19:01:32 -05:00
|
|
|
;;; ol-eshell.el ends here
|