org-mode/lisp/org-eshell.el

67 lines
2.2 KiB
EmacsLisp
Raw Normal View History

2016-06-21 20:34:25 +00:00
;;; org-eshell.el - Support for Links to Working Directories in Eshell -*- lexical-binding: t; -*-
2019-01-01 10:50:56 +00:00
;; Copyright (C) 2011-2019 Free Software Foundation, Inc.
;; Author: Konrad Hinsen <konrad.hinsen AT fastmail.net>
;; This file is part of GNU Emacs.
;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; 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
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;;; Code:
(require 'org)
(require 'eshell)
(require 'esh-mode)
(org-link-set-parameters "eshell"
:follow #'org-eshell-open
:store #'org-eshell-store-link)
(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.
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."
(let* ((buffer-and-command
(if (string-match "\\([A-Za-z0-9-+*]+\\):\\(.*\\)" link)
(list (match-string 1 link)
(match-string 2 link))
(list eshell-buffer-name link)))
(eshell-buffer-name (car buffer-and-command))
(command (cadr buffer-and-command)))
(if (get-buffer eshell-buffer-name)
(pop-to-buffer-same-window eshell-buffer-name)
(eshell))
(goto-char (point-max))
(eshell-kill-input)
(insert command)
(eshell-send-input)))
(defun org-eshell-store-link ()
"Store a link that, when opened, switches back to the current eshell buffer
and the current working directory."
(when (eq major-mode 'eshell-mode)
(let* ((command (concat "cd " dired-directory))
(link (concat (buffer-name) ":" command)))
(org-store-link-props
:link (concat "eshell:" link)
:description command))))
(provide 'org-eshell)
;;; org-eshell.el ends here