org-screen.el 3.7 KB

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