Merge branch 'maint'
[org-mode.git] / contrib / lisp / org-screen.el
blob6b870f229d0a365ddc0a8a9c0aac616bb1ffb8d3
1 ;;; org-screen.el --- Integreate Org-mode with screen.
3 ;; Copyright (c) 2008-2014 Andrew Hyatt
4 ;;
5 ;; Author: Andrew Hyatt <ahyatt at gmail dot com>
6 ;; Maintainer: Carsten Dominik <carsten at orgmode dot org>
7 ;;
8 ;; This file is not yet part of GNU Emacs.
9 ;;
10 ;; This program is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 3, or (at your option)
13 ;; any later version.
15 ;; This program 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.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
22 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
24 ;;; Commentary:
26 ;; This file contains functionality to integrate screen and org-mode.
27 ;; When using org-mode, it is often useful to take tasks that have
28 ;; some command-line work associated with them, and associate them
29 ;; with a screen session. Screen is used rather than a direct
30 ;; terminal to facilitate portability of the resulting session.
32 ;; To use screen in org, in your .emacs file, simply put this file in
33 ;; a directory in your load-path and write:
35 ;; (require 'org-screen)
37 ;; When have a task and want to start some command-line activity
38 ;; associated with that task, go to the end of your item and type:
40 ;; M-x org-screen
42 ;; This will prompt you for a name of a screen session. Type in a
43 ;; name and it will insert a link into your org file at your current
44 ;; location.
46 ;; When you want to visit the link, go to the link and type C-c C-o to
47 ;; open the link.
49 ;; You may want to get rid of the constant queries about whether you
50 ;; really want to execute lisp code. Do so by adding to your .emacs:
52 ;; (setq org-confirm-elisp-link-function nil)
54 (require 'term)
55 (require 'org)
57 (defcustom org-screen-program-name "/usr/bin/screen"
58 "Full location of the screen executable."
59 :group 'org-screen
60 :type 'string)
62 (defun org-screen (name)
63 "Start a screen session with name"
64 (interactive "MScreen name: ")
65 (save-excursion
66 (org-screen-helper name "-S"))
67 (insert-string (concat "[[screen:" name "]]")))
69 (defun org-screen-buffer-name (name)
70 "Returns the buffer name corresponding to the screen name given."
71 (concat "*screen " name "*"))
73 (defun org-screen-helper (name arg)
74 "This method will create a screen session with a specified name
75 and taking the specified screen arguments. Much of this function
76 is copied from ansi-term method."
78 ;; Pick the name of the new buffer.
79 (let ((term-ansi-buffer-name
80 (generate-new-buffer-name
81 (org-screen-buffer-name name))))
82 (setq term-ansi-buffer-name
83 (term-ansi-make-term
84 term-ansi-buffer-name org-screen-program-name nil arg name))
85 (set-buffer term-ansi-buffer-name)
86 (term-mode)
87 (term-char-mode)
88 (term-set-escape-char ?\C-x)
89 term-ansi-buffer-name))
91 (defun org-screen-goto (name)
92 "Open the screen with the specified name in the window"
93 (interactive "MScreen name: ")
94 (let ((screen-buffer-name (org-screen-buffer-name name)))
95 (if (member screen-buffer-name
96 (mapcar 'buffer-name (buffer-list)))
97 (org-pop-to-buffer-same-window screen-buffer-name)
98 (org-pop-to-buffer-same-window (org-screen-helper name "-dr")))))
100 (if org-link-abbrev-alist
101 (add-to-list 'org-link-abbrev-alist
102 '("screen" . "elisp:(org-screen-goto \"%s\")"))
103 (setq org-link-abbrev-alist
104 '(("screen" . "elisp:(org-screen-goto \"%s\")"))))
106 (provide 'org-screen)