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 _)
|
Many small code improvements
* lisp/org-capture.el (org-capture-member): Make obsolete; the old
definition was identical to ‘org-capture-get’ anyway.
(org-capture-mode-map): Move the calls to ‘define-key’ up to where the
variable is defined.
(org-capture-mode-hook): Small docstring tweak.
(org-capture-mode): Fix typo in mode lighter.
(org-capture-set-target-location, org-capture-place-item):
(org-capture-place-plain-text, org-capture-narrow):
(org-capture-empty-lines-after):
(org-capture-import-remember-templates): ‘if’ without else -> ‘when’
* lisp/org-colview.el (org-columns-edit-value): Change an error to a
user-error.
(org-columns-uncompile-format): Improve docstring.
* lisp/org-compat.el (org-remove-from-invisibility-spec): Make
obsolete, the underlying emacs function exists since 1997, commit 31aa282e.
(org-in-invisibility-spec-p, org-count-lines): ‘if’ without else -> ‘when’.
* lisp/org-element.el (org-element-swap-A-B):
* lisp/org-entities.el (org-entities-create-table):
* lisp/org-list.el (org-insert-item):
* lisp/org-macs.el (org-with-point-at, org-base-buffer):
(org-preserve-local-variables, org-overlay-display):
(org-overlay-before-string): ‘if’ without else -> ‘when’.
* lisp/org-eshell.el (org-eshell-open): Fix docstring typo.
* lisp/org-pcomplete.el (pcomplete/org-mode/file-option/language):
(pcomplete/org-mode/file-option/startup):
(pcomplete/org-mode/file-option/options):
(pcomplete/org-mode/file-option/infojs_opt):
(pcomplete/org-mode/link, pcomplete/org-mode/tex):
(pcomplete/org-mode/todo, pcomplete/org-mode/searchhead):
(pcomplete/org-mode/tag, pcomplete/org-mode/prop): Avoid the formerly
misspelled ‘pcomplete-uniqify-list’ function. It has a defalias in
emacs >= 27; we add our own for older emacsen.
(pcomplete/org-mode/file-option/bind): ‘if’ without else -> ‘when’.
* lisp/org-protocol.el (org-protocol-capture):
(org-protocol-convert-query-to-plist): ‘if’ without else -> ‘when’.
(org-protocol-do-capture): Pacify byte compiler, simplify conditional
logic.
* lisp/org-table.el (org-table-create-with-table.el): Simplify conditional
logic.
(org-table-create, org-table-convert-region, org-table-next-field):
(org-table-beginning-of-field, org-table-end-of-field):
* lisp/org-w3m.el (org-w3m-copy-for-org-mode): ‘if’ without else ->
‘when’.
* lisp/org.el (org-babel-do-load-languages, org-previous-link):
(org-refile): Use ‘(foo ...)’ instead of ‘(funcall 'foo ...)’.
(org-add-log-note): Convert a long cond into a cl-case.
(org-priority): Improve docstring, show a deprecation warning if the
‘show’ argument is passed (which was previously silently ignored).
Also, use ?\s instead of ?\ as a character literal for space.
(org-fast-tag-insert): Fix docstring typo.
(org-fill-element): ‘if’ without else -> ‘when’.
(org-on-target-p): Remove ancient compatibility alias.
2018-05-10 01:02:35 +00:00
|
|
|
"Switch to an eshell buffer and execute a command line.
|
2021-09-16 10:32:43 +00:00
|
|
|
The link can be just a command line (executed in the default
|
|
|
|
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 ()
|
|
|
|
"Store a link that, when opened, switches back to the current eshell buffer
|
2021-09-16 10:32:43 +00:00
|
|
|
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
|