org-screen.el 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. ;;; org-screen.el --- Integreate Org-mode with screen.
  2. ;; Copyright (c) 2008-2012 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. ;; GNU Emacs 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. ;; GNU Emacs 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; see the file COPYING. If not, write to the
  19. ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  20. ;; Boston, MA 02110-1301, USA.
  21. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  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. (require 'term)
  53. (require 'org)
  54. (defcustom org-screen-program-name "/usr/bin/screen"
  55. "Full location of the screen executable."
  56. :group 'org-screen
  57. :type 'string)
  58. (defun org-screen (name)
  59. "Start a screen session with name"
  60. (interactive "MScreen name: ")
  61. (save-excursion
  62. (org-screen-helper name "-S"))
  63. (insert-string (concat "[[screen:" name "]]")))
  64. (defun org-screen-buffer-name (name)
  65. "Returns the buffer name corresponding to the screen name given."
  66. (concat "*screen " name "*"))
  67. (defun org-screen-helper (name arg)
  68. "This method will create a screen session with a specified name
  69. and taking the specified screen arguments. Much of this function
  70. is copied from ansi-term method."
  71. ;; Pick the name of the new buffer.
  72. (let ((term-ansi-buffer-name
  73. (generate-new-buffer-name
  74. (org-screen-buffer-name name))))
  75. (setq term-ansi-buffer-name
  76. (term-ansi-make-term
  77. term-ansi-buffer-name org-screen-program-name nil arg name))
  78. (set-buffer term-ansi-buffer-name)
  79. (term-mode)
  80. (term-char-mode)
  81. (term-set-escape-char ?\C-x)
  82. term-ansi-buffer-name))
  83. (defun org-screen-goto (name)
  84. "Open the screen with the specified name in the window"
  85. (interactive "MScreen name: ")
  86. (let ((screen-buffer-name (org-screen-buffer-name name)))
  87. (if (member screen-buffer-name
  88. (mapcar 'buffer-name (buffer-list)))
  89. (org-pop-to-buffer-same-window screen-buffer-name)
  90. (org-pop-to-buffer-same-window (org-screen-helper name "-dr")))))
  91. (if org-link-abbrev-alist
  92. (add-to-list 'org-link-abbrev-alist
  93. '("screen" . "elisp:(org-screen-goto \"%s\")"))
  94. (setq org-link-abbrev-alist
  95. '(("screen" . "elisp:(org-screen-goto \"%s\")"))))
  96. (provide 'org-screen)