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