emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* orgmode add-on that implements links to eshell buffers
@ 2011-01-03 12:07 Konrad Hinsen
  2011-01-04 12:26 ` Carsten Dominik
  0 siblings, 1 reply; 5+ messages in thread
From: Konrad Hinsen @ 2011-01-03 12:07 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 578 bytes --]

The attached file implements a new link type "eshell". An eshell link consists of an optional buffer name followed by a colon, and of an eshell command line. Opening the link switches to the indicated buffer, creating it if necessary, or to the default *eshell* buffer, and executes the command line exactly as if it were entered from the keyboard. Inside an eshell buffer, org-store-link stores a link that switches back to the same buffer and does a  cd to the current working directory.

I'd be happy to contribute this file to org-mode if there is interest.

Konrad.


[-- Attachment #2: org-eshell.el --]
[-- Type: application/octet-stream, Size: 2410 bytes --]

;;; org-eshell.el - Support for links to working directories in eshell
;; Copyright (C) 2011 Free Software Foundation, Inc.
;;
;; Author: Konrad Hinsen <konrad.hinsen AT fastmail.net>
;; Version: 0.1
;;
;; This file is not part of GNU Emacs.
;;
;; 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, 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; see the file COPYING.  If not, write to the
;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
;; Boston, MA 02110-1301, USA.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(require 'org)
(require 'eshell)
(require 'esh-mode)

(org-add-link-type "eshell" 'org-eshell-open)
(add-hook 'org-store-link-functions 'org-eshell-store-link)

(defun org-eshell-open (link)
  "Switch to am 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)
       (switch-to-buffer eshell-buffer-name)
       (eshell))
     (end-of-buffer)
     (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 (org-make-link "eshell:" link)
       :description command))))
  

(provide 'org-eshell)

;;; org-eshell.el ends here

[-- Attachment #3: Type: text/plain, Size: 201 bytes --]

_______________________________________________
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2011-01-06 11:18 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-01-03 12:07 orgmode add-on that implements links to eshell buffers Konrad Hinsen
2011-01-04 12:26 ` Carsten Dominik
2011-01-04 14:44   ` Konrad Hinsen
2011-01-04 15:02     ` Carsten Dominik
2011-01-06 10:33       ` Carsten Dominik

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).