emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Konrad Hinsen <konrad.hinsen@fastmail.net>
To: emacs-orgmode@gnu.org
Subject: orgmode add-on that implements links to eshell buffers
Date: Mon, 3 Jan 2011 13:07:36 +0100	[thread overview]
Message-ID: <9064DFD4-95F5-45F4-9F55-F92D03FC1B68@fastmail.net> (raw)

[-- 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

             reply	other threads:[~2011-01-03 12:07 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-03 12:07 Konrad Hinsen [this message]
2011-01-04 12:26 ` orgmode add-on that implements links to eshell buffers Carsten Dominik
2011-01-04 14:44   ` Konrad Hinsen
2011-01-04 15:02     ` Carsten Dominik
2011-01-06 10:33       ` Carsten Dominik

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9064DFD4-95F5-45F4-9F55-F92D03FC1B68@fastmail.net \
    --to=konrad.hinsen@fastmail.net \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).