forked from knu/elscreen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
elscreen-howm.el
119 lines (102 loc) · 4.38 KB
/
elscreen-howm.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
;; -*- Mode: Emacs-Lisp -*-
;;
;; elscreen-howm.el
;;
(defconst elscreen-howm-version "0.1.3 (September 14, 2008)")
;;
;; Author: Naoto Morishima <[email protected]>
;; Created: November 06, 2005
;; Revised: September 14, 2008
;; This program 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 2, or (at your option)
;; any later version.
;;
;; This program 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 this program; see the file COPYING. If not, write to
;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
(provide 'elscreen-howm)
(require 'elscreen)
;;; User Customizable Variables:
(defcustom elscreen-howm-mode-to-nickname-alist
'(("^howm-\\(menu-mode$\\|view-\\)" . "howm(menu)"))
"*Alist composed of the pair of mode-name and corresponding screen-name."
:type '(alist :key-type string :value-type (choice string function))
:tag "Howm major-mode to nickname alist"
:set (lambda (symbol value)
(custom-set-default symbol value)
(elscreen-rebuild-mode-to-nickname-alist))
:group 'howm)
(elscreen-set-mode-to-nickname-alist 'elscreen-howm-mode-to-nickname-alist)
(defcustom elscreen-howm-buffer-to-nickname-alist
'(("\\.howm$" . elscreen-howm-mode-buffer-to-nickname))
"*Alist composed of the pair of regular expression of
buffer-name and corresponding screen-name."
:type '(alist :key-type string :value-type (choice string function))
:tag "Howm buffer to nickname alist"
:set (lambda (symbol value)
(custom-set-default symbol value)
(elscreen-rebuild-buffer-to-nickname-alist))
:group 'howm)
(elscreen-set-buffer-to-nickname-alist 'elscreen-howm-buffer-to-nickname-alist)
;;; Code:
;; delete other windows when howm-menu is invoked
(defadvice howm-menu (around elscreen-howm-menu activate)
(delete-other-windows)
ad-do-it)
;; create new page with new screen
(defadvice howm-create-file-with-title (around elscreen-howm-create-file-with-title activate)
(save-current-buffer
(elscreen-create))
ad-do-it)
;; open existing page with new screen
(defadvice howm-view-open-item (around elscreen-howm-view-open-item activate)
(let ((window-configuration (elscreen-current-window-configuration))
howm-item-buffer)
ad-do-it
(setq howm-item-buffer (current-buffer))
(elscreen-apply-window-configuration window-configuration)
(elscreen-find-and-goto-by-buffer howm-item-buffer 'create)))
(eval-after-load "howm-view"
'(unless (fboundp 'howm-view-open-item)
(elscreen-message "This version of elscreen-howm does not work well with your howm. Upgrade howm to version 1.3.3 or later, or downgrade elscreen-howm to version 0.0.1.")))
;; screen nickname
(defun elscreen-howm-mode-buffer-to-nickname ()
(format "howm(%s%s%s)"
elscreen-howm-title
(if (zerop (length elscreen-howm-title)) "" ":")
(substring (buffer-name (current-buffer)) 0 -5)))
(defun elscreen-howm-mode-update-title ()
(let ((title (howm-title-at-current-point)))
(when (not (string-equal elscreen-howm-title title))
(setq elscreen-howm-title title)
(elscreen-notify-screen-modification 'force-immediately))))
(defun elscreen-howm-mode-initialize ()
(set (make-local-variable 'elscreen-howm-title)
(howm-title-at-current-point))
(add-hook 'post-command-hook 'elscreen-howm-mode-update-title t t))
(add-hook 'howm-mode-on-hook 'elscreen-howm-mode-initialize)
;; kill screen when exiting from howm-mode
(defun howm-save-and-kill-buffer/screen ()
(interactive)
(let* ((file-name (buffer-file-name)))
(if (save-excursion
(goto-char (point-min))
(re-search-forward "[^ \t\r\n]" nil t))
(howm-save-buffer)
(set-buffer-modified-p nil)
(when (file-exists-p file-name)
(delete-file file-name)
(message "(Deleted %s)" (file-name-nondirectory file-name))))
(kill-buffer nil)
(unless (elscreen-one-screen-p)
(elscreen-kill))))
(eval-after-load "howm-mode"
'(progn
(define-key howm-mode-map
"\C-c\C-c" 'howm-save-and-kill-buffer/screen)))