Release 7.8.03
[org-mode.git] / lisp / org-eshell.el
blobc8754d76b9660273d9646d29d93eb1e1bd532fea
1 ;;; org-eshell.el - Support for links to working directories in eshell
2 ;; Copyright (C) 2011 Free Software Foundation, Inc.
3 ;;
4 ;; Author: Konrad Hinsen <konrad.hinsen AT fastmail.net>
5 ;; Version: 7.8.03
6 ;;
7 ;; This file is part of GNU Emacs.
8 ;;
9 ;; Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 3, or (at your option)
12 ;; any later version.
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
21 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 ;; Boston, MA 02110-1301, USA.
23 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
25 (require 'org)
26 (require 'eshell)
27 (require 'esh-mode)
29 (org-add-link-type "eshell" 'org-eshell-open)
30 (add-hook 'org-store-link-functions 'org-eshell-store-link)
32 (defun org-eshell-open (link)
33 "Switch to am eshell buffer and execute a command line.
34 The link can be just a command line (executed in the default
35 eshell buffer) or a command line prefixed by a buffer name
36 followed by a colon."
37 (let* ((buffer-and-command
38 (if (string-match "\\([A-Za-z0-9-+*]+\\):\\(.*\\)" link)
39 (list (match-string 1 link)
40 (match-string 2 link))
41 (list eshell-buffer-name link)))
42 (eshell-buffer-name (car buffer-and-command))
43 (command (cadr buffer-and-command)))
44 (if (get-buffer eshell-buffer-name)
45 (org-pop-to-buffer-same-window eshell-buffer-name)
46 (eshell))
47 (end-of-buffer)
48 (eshell-kill-input)
49 (insert command)
50 (eshell-send-input)))
52 (defun org-eshell-store-link ()
53 "Store a link that, when opened, switches back to the current eshell buffer
54 and the current working directory."
55 (when (eq major-mode 'eshell-mode)
56 (let* ((command (concat "cd " dired-directory))
57 (link (concat (buffer-name) ":" command)))
58 (org-store-link-props
59 :link (org-make-link "eshell:" link)
60 :description command))))
62 (provide 'org-eshell)
64 ;;; org-eshell.el ends here