2021-04-19 10:21:01 +00:00
|
|
|
;;; ol-eshell.el --- Links to Working Directories in Eshell -*- lexical-binding: t; -*-
|
2012-01-05 08:43:21 +00:00
|
|
|
|
2024-01-02 01:47:10 +00:00
|
|
|
;; Copyright (C) 2011-2024 Free Software Foundation, Inc.
|
2012-01-05 08:43:21 +00:00
|
|
|
|
2011-01-04 15:06:09 +00:00
|
|
|
;; Author: Konrad Hinsen <konrad.hinsen AT fastmail.net>
|
2012-01-05 08:43:21 +00:00
|
|
|
|
2011-12-21 08:43:48 +00:00
|
|
|
;; This file is part of GNU Emacs.
|
2012-01-05 08:43:21 +00:00
|
|
|
|
|
|
|
;; GNU Emacs is free software: you can redistribute it and/or modify
|
2011-01-04 15:06:09 +00:00
|
|
|
;; it under the terms of the GNU General Public License as published by
|
2012-01-05 08:43:21 +00:00
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
;; (at your option) any later version.
|
2011-01-04 15:06:09 +00: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 22:52:52 +00:00
|
|
|
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
|
2012-01-05 08:43:21 +00:00
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
|
|
|
;;; Code:
|
2011-01-04 15:06:09 +00:00
|
|
|
|
2022-08-04 13:53:05 +00:00
|
|
|
(require 'org-macs)
|
|
|
|
(org-assert-version)
|
|
|
|
|
2011-01-04 15:06:09 +00:00
|
|
|
(require 'eshell)
|
|
|
|
(require 'esh-mode)
|
2018-11-26 23:04:41 +00:00
|
|
|
(require 'ol)
|
2011-01-04 15:06:09 +00:00
|
|
|
|
2019-08-21 05:26:30 +00:00
|
|
|
(declare-function eshell/pwd "em-dirs.el" (&rest args))
|
|
|
|
|
2016-07-05 14:27:03 +00:00
|
|
|
(org-link-set-parameters "eshell"
|
|
|
|
:follow #'org-eshell-open
|
|
|
|
:store #'org-eshell-store-link)
|
2011-01-04 15:06:09 +00:00
|
|
|
|
2020-02-17 10:28:50 +00:00
|
|
|
(defun org-eshell-open (link _)
|
2023-10-21 11:49:52 +00: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 10:32:43 +00:00
|
|
|
eshell buffer) or a command line prefixed by a buffer name
|
|
|
|
followed by a colon."
|
2011-01-04 15:06:09 +00:00
|
|
|
(let* ((buffer-and-command
|
2019-04-02 22:00:59 +00:00
|
|
|
(if (string-match "\\([A-Za-z0-9+*-]+\\):\\(.*\\)" link)
|
2012-08-11 17:10:44 +00:00
|
|
|
(list (match-string 1 link)
|
|
|
|
(match-string 2 link))
|
2011-01-04 15:06:09 +00:00
|
|
|
(list eshell-buffer-name link)))
|
|
|
|
(eshell-buffer-name (car buffer-and-command))
|
|
|
|
(command (cadr buffer-and-command)))
|
2012-08-11 17:10:44 +00:00
|
|
|
(if (get-buffer eshell-buffer-name)
|
2022-10-04 21:42:27 +00: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 17:10:44 +00:00
|
|
|
(eshell))
|
|
|
|
(goto-char (point-max))
|
|
|
|
(eshell-kill-input)
|
|
|
|
(insert command)
|
|
|
|
(eshell-send-input)))
|
2011-01-04 15:06:09 +00:00
|
|
|
|
|
|
|
(defun org-eshell-store-link ()
|
2023-10-21 11:49:52 +00:00
|
|
|
"Store eshell link.
|
|
|
|
When opened, the link switches back to the current eshell buffer and
|
|
|
|
the current working directory."
|
2011-01-04 15:06:09 +00:00
|
|
|
(when (eq major-mode 'eshell-mode)
|
2019-08-21 05:26:30 +00:00
|
|
|
(let* ((command (concat "cd " (eshell/pwd)))
|
2011-01-04 15:06:09 +00:00
|
|
|
(link (concat (buffer-name) ":" command)))
|
2018-11-26 23:04:41 +00:00
|
|
|
(org-link-store-props
|
2012-08-03 17:03:21 +00:00
|
|
|
:link (concat "eshell:" link)
|
2011-01-04 15:06:09 +00:00
|
|
|
:description command))))
|
|
|
|
|
2019-03-02 00:01:32 +00:00
|
|
|
(provide 'ol-eshell)
|
2011-01-04 15:06:09 +00:00
|
|
|
|
2019-03-02 00:01:32 +00:00
|
|
|
;;; ol-eshell.el ends here
|