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