org.el: Fix `org-next-link' and use it for `org-previous-link'
[org-mode.git] / contrib / lisp / org-panel.el
bloba732027b8d0c179b42a0bcb2958f760abf88b814
1 ;;; org-panel.el --- Simple routines for us with bad memory
2 ;;
3 ;; Author: Lennart Borgman (lennart O borgman A gmail O com)
4 ;; Created: Thu Nov 15 15:35:03 2007
5 ;; Version: 0.21
6 ;; Lxast-Updated: Wed Nov 21 03:06:03 2007 (3600 +0100)
7 ;; URL:
8 ;; Keywords:
9 ;; Compatibility:
11 ;; Features that might be required by this library:
13 ;; `easymenu', `font-lock', `noutline', `org', `outline', `syntax',
14 ;; `time-date'.
16 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
18 ;;; Commentary:
20 ;; This defines a kind of control panel for `org-mode'. This control
21 ;; panel should make it fast to move around and edit structure etc.
23 ;; To bring up the control panel type
25 ;; M-x orgpan-panel
27 ;; Type ? there for help.
29 ;; I suggest you add the following to your .emacs for quick access of
30 ;; the panel:
32 ;; (eval-after-load 'org-mode
33 ;; (define-key org-mode-map [(control ?c) ?p] 'orgpan-panel))
35 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
37 ;;; Change log:
40 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
42 ;; This program is free software; you can redistribute it and/or
43 ;; modify it under the terms of the GNU General Public License as
44 ;; published by the Free Software Foundation; either version 2, or
45 ;; (at your option) any later version.
47 ;; This program is distributed in the hope that it will be useful,
48 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
49 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
50 ;; General Public License for more details.
52 ;; You should have received a copy of the GNU General Public License
53 ;; along with this program; see the file COPYING. If not, write to
54 ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth
55 ;; Floor, Boston, MA 02110-1301, USA.
57 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
59 ;;; Code:
61 (require 'org)
62 (require 'outline)
64 ;; Fix-me: this is for testing. A minor mode version interferes badly
65 ;; with emulation minor modes. On the other hand, the other version
66 ;; interferes badly with (interactive ...).
67 (defvar orgpan-minor-mode-version t)
69 (defface orgpan-field
70 '((t (:inherit 'widget-field)))
71 "Face for fields."
72 :group 'winsize)
73 (defvar orgpan-field-face 'orgpan-field)
75 (defface orgpan-active-field
76 '((t (:inherit 'highlight)))
77 "Face for fields."
78 :group 'winsize)
79 (defvar orgpan-active-field-face 'orgpan-active-field)
81 (defface orgpan-spaceline
82 '((t (:height 0.2)))
83 "Face for spacing lines."
84 :group 'winsize)
86 (defcustom orgpan-panel-buttons nil
87 "Panel style, if non-nil use buttons.
88 If there are buttons in the panel they are used to change the way
89 the arrow keys work. The panel looks something like this, with
90 the first button chosen:
92 [Navigate] [Restructure] [TODO/Priority]
93 ----------
94 up/down, left: Go to, right: Visibility
96 The line below the buttons try to give a short hint about what
97 the arrow keys does. \(Personally I prefer the version without
98 buttons since I then do not have to remember which button is
99 active.)"
100 :type 'boolean
101 :group 'winsize)
103 ;; Fix-me: add org-mode-map
104 (defconst orgpan-org-mode-commands nil)
105 (defconst orgpan-org-commands
107 orgpan-copy-subtree
108 orgpan-cut-subtree
109 orgpan-paste-subtree
110 undo
112 ;orgpan-occur
114 org-cycle
115 org-global-cycle
116 outline-up-heading
117 outline-next-visible-heading
118 outline-previous-visible-heading
119 outline-forward-same-level
120 outline-backward-same-level
121 org-todo
122 org-show-todo-tree
123 org-priority-up
124 org-priority-down
125 org-move-subtree-up
126 org-move-subtree-down
127 org-do-promote
128 org-do-demote
129 org-promote-subtree
130 org-demote-subtree))
133 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
134 ;;; Hook functions etc
136 (defun orgpan-delete-panel ()
137 "Remove the panel."
138 (interactive)
139 (when (buffer-live-p orgpan-panel-buffer)
140 (delete-windows-on orgpan-panel-buffer)
141 (kill-buffer orgpan-panel-buffer))
142 (setq orgpan-panel-buffer nil)
143 (setq orgpan-panel-window nil)
144 (orgpan-panel-minor-mode 0)
145 (remove-hook 'post-command-hook 'orgpan-minor-post-command)
146 (remove-hook 'post-command-hook 'orgpan-mode-post-command)
147 ;;(remove-hook 'window-configuration-change-hook 'orgpan-window-config-change)
150 (defvar orgpan-last-command-was-from-panel nil)
151 (defun orgpan-mode-pre-command ()
152 (setq orgpan-last-command-was-from-panel nil)
153 (condition-case err
154 (if (not (and (windowp orgpan-org-window)
155 (window-live-p orgpan-org-window)))
156 (progn
157 (setq this-command 'ignore)
158 (orgpan-delete-panel)
159 (message "The window belonging to the panel had disappeared, removed panel."))
160 (let ((buf (window-buffer orgpan-org-window)))
161 (when (with-current-buffer buf
162 (derived-mode-p 'org-mode))
163 (setq orgpan-last-org-buffer buf))
164 ;; Fix me: add a list of those commands that are not
165 ;; meaningful from the panel (for example org-time-stamp)
166 (when (or (memq this-command orgpan-org-commands)
167 (memq this-command orgpan-org-mode-commands)
168 ;; For some reason not all org commands are found above:
169 (string= "org-" (substring (format "%s" this-command) 0 4)))
170 (if (not (with-current-buffer buf
171 (derived-mode-p 'org-mode)))
172 (progn
173 (if (buffer-live-p orgpan-org-buffer)
174 (set-window-buffer orgpan-org-window orgpan-org-buffer)
175 (message "Please use `l' or `b' to choose an org-mode buffer"))
176 (setq this-command 'ignore))
177 (setq orgpan-org-buffer (window-buffer orgpan-org-window))
178 (setq orgpan-last-command-was-from-panel t)
179 (select-window orgpan-org-window)
180 ;;(when (active-minibuffer-window
181 ;;(set-buffer orgpan-org-buffer)
182 ))))
183 (error (lwarn 't :warning "orgpan-pre: %S" err))))
185 (defun orgpan-mode-post-command ()
186 (condition-case err
187 (progn
188 (unless (and (windowp orgpan-panel-window)
189 (window-live-p orgpan-panel-window)
190 (bufferp orgpan-panel-buffer)
191 (buffer-live-p orgpan-panel-buffer))
192 ;;(orgpan-delete-panel)
194 (when (and orgpan-last-command-was-from-panel
195 (windowp orgpan-panel-window)
196 (window-live-p orgpan-panel-window))
197 (select-window orgpan-panel-window)
198 (when (derived-mode-p 'orgpan-mode)
199 (setq deactivate-mark t)
200 (when orgpan-panel-buttons
201 (unless (and orgpan-point
202 (= (point) orgpan-point))
203 ;; Go backward so it is possible to click on a "button":
204 (orgpan-backward-field))))))
205 (error (lwarn 't :warning "orgpan-post: %S" err))))
207 ;; (defun orgpan-window-config-change ()
208 ;; "Check if any frame is displaying an orgpan panel.
209 ;; If not remove `orgpan-mode-post-command' and this function from
210 ;; the hooks."
211 ;; (condition-case err
212 ;; (unless (and (
213 ;; (let ((found-pan nil))
214 ;; (dolist (f (frame-list))
215 ;; (dolist (w (window-list f 'nomini))
216 ;; (with-current-buffer (window-buffer w)
217 ;; (when (derived-mode-p 'orgpan-mode)
218 ;; (setq found-pan t)))))
219 ;; (unless found-pan
220 ;; (remove-hook 'post-command-hook 'orgpan-mode-post-command)
221 ;; (remove-hook 'window-configuration-change-hook 'orgpan-window-config-change)))
222 ;; (error (lwarn 't :warning "Error in orgpan-config-change: %S" err))))
225 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
226 ;;; Commands
228 (defun orgpan-last-buffer ()
229 "Open last org-mode buffer in panels org window."
230 (interactive)
231 (let ((buf (window-buffer orgpan-org-window))
232 (last-buf orgpan-last-org-buffer))
233 (when (with-current-buffer buf
234 (derived-mode-p 'org-mode))
235 (setq orgpan-last-org-buffer buf))
236 (when (eq last-buf buf)
237 (setq last-buf nil))
238 (if (not last-buf)
239 (orgpan-switch-buffer)
240 (set-window-buffer orgpan-org-window last-buf))))
242 (defun orgpan-switch-buffer ()
243 "Switch to next org-mode buffer in panels org window."
244 (interactive)
245 (let ((buf (window-buffer orgpan-org-window))
246 (org-buffers nil))
247 (with-current-buffer buf
248 (when (derived-mode-p 'org-mode)
249 (bury-buffer buf)
250 (setq orgpan-last-org-buffer buf)))
251 (setq org-buffers (delq nil (mapcar (lambda (buf)
252 (when (with-current-buffer buf
253 (derived-mode-p 'org-mode))
254 buf))
255 (buffer-list))))
256 (setq org-buffers (delq buf org-buffers))
257 (set-window-buffer orgpan-org-window (car org-buffers))
258 (setq orgpan-org-buffer (car org-buffers))))
260 (defun orgpan-paste-subtree ()
261 (interactive)
262 (if (y-or-n-p "Paste subtree here? ")
263 (org-paste-subtree)
264 (message "Nothing was pasted")))
266 (defun orgpan-cut-subtree ()
267 (interactive)
268 (let ((heading (progn
269 (org-back-to-heading)
270 (buffer-substring (point) (line-end-position))
272 (if (y-or-n-p (format "Do you want to cut the subtree\n%s\n? " heading))
273 (org-cut-subtree)
274 (message "Nothing was cut"))))
276 (defun orgpan-copy-subtree ()
277 (interactive)
278 (let ((heading (progn
279 (org-back-to-heading)
280 (buffer-substring (point) (line-end-position))
282 (if (y-or-n-p (format "Do you want to copy the subtree\n%s\n? " heading))
283 (org-copy-subtree)
284 (message "Nothing was copied"))))
287 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
288 ;;; Buttons
290 (defvar orgpan-ovl-help nil)
292 (defun orgpan-check-panel-mode ()
293 (unless (derived-mode-p 'orgpan-mode)
294 (error "Not orgpan-mode in buffer: %s" major-mode)))
296 (defun orgpan-display-bindings-help ()
297 (orgpan-check-panel-mode)
298 (setq orgpan-point (point))
299 (let* ((ovls (overlays-at (point)))
300 (ovl (car ovls))
301 (help (when ovl (overlay-get ovl 'orgpan-explain))))
302 (dolist (o (overlays-in (point-min) (point-max)))
303 (overlay-put o 'face orgpan-field-face))
304 (overlay-put ovl 'face orgpan-active-field-face)
305 (overlay-put orgpan-ovl-help 'before-string help)))
307 (defun orgpan-forward-field ()
308 (interactive)
309 (orgpan-check-panel-mode)
310 (let ((pos (next-overlay-change (point))))
311 (unless (overlays-at pos)
312 (setq pos (next-overlay-change pos)))
313 (when (= pos (point-max))
314 (setq pos (point-min))
315 (unless (overlays-at pos)
316 (setq pos (next-overlay-change pos))))
317 (goto-char pos))
318 (orgpan-display-bindings-help))
320 (defun orgpan-backward-field ()
321 (interactive)
322 (orgpan-check-panel-mode)
323 (when (= (point) (point-min))
324 (goto-char (point-max)))
325 (let ((pos (previous-overlay-change (point))))
326 (unless (overlays-at pos)
327 (setq pos (previous-overlay-change pos)))
328 (goto-char pos))
329 (orgpan-display-bindings-help))
332 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
333 ;;; Mode
335 (defconst orgpan-mode-map
336 ;; Fix-me: clean up here!
337 ;; Fix-me: viper support
338 (let ((map (make-sparse-keymap)))
339 (define-key map [?q] 'orgpan-delete-panel)
340 (define-key map [??] 'orgpan-help)
341 ;; Copying etc
342 (define-key map [?c] 'orgpan-copy-subtree)
343 (define-key map [?x] 'orgpan-cut-subtree)
344 (define-key map [?p] 'orgpan-paste-subtree)
345 (define-key map [?z] 'undo)
346 ;; Buffers:
347 (define-key map [?b] 'orgpan-switch-buffer)
348 (define-key map [?l] 'orgpan-last-buffer)
349 ;; Some keys for moving between headings. Emacs keys for next/prev
350 ;; line seems ok:
351 (define-key map [(control ?p)] 'outline-previous-visible-heading)
352 (define-key map [(control ?n)] 'outline-next-visible-heading)
353 (define-key map [(shift control ?p)] 'outline-backward-same-level)
354 (define-key map [(shift control ?n)] 'outline-forward-same-level)
355 ;; A mnemunic for up:
356 (define-key map [(control ?u)] 'outline-up-heading)
357 ;; Search sparse tree:
359 ;; Fix-me: Search does not work, some problem with
360 ;; interactive. Probably have to turn the whole thing around and
361 ;; always be in the org buffer, but with a minor mode running
362 ;; there.
364 ;;(define-key map [?s] 'org-sparse-tree)
365 (define-key map [?s] 'orgpan-occur)
366 ;; Same as in org-mode:
367 ;;(define-key map [(control ?c)(control ?v)] 'org-show-todo-tree)
368 ;; Fix-me: This leads to strange problems:
369 ;;(define-key map [t] 'ignore)
370 map))
372 (defun orgpan-occur ()
373 "Replacement for `org-occur'.
374 Technical reasons."
375 (interactive)
376 (let ((rgx (read-from-minibuffer "my mini Regexp: ")))
377 (setq orgpan-last-command-was-from-panel t)
378 (select-window orgpan-org-window)
379 (org-occur rgx)))
381 (defvar orgpan-panel-window nil
382 "The window showing `orgpan-panel-buffer'.")
384 (defvar orgpan-panel-buffer nil
385 "The panel buffer.
386 There can be only one such buffer at any time.")
388 (defvar orgpan-org-window nil)
389 ;;(make-variable-buffer-local 'orgpan-org-window)
391 ;; Fix-me: used?
392 (defvar orgpan-org-buffer nil)
393 ;;(make-variable-buffer-local 'orgpan-org-buffer)
395 (defvar orgpan-last-org-buffer nil)
396 ;;(make-variable-buffer-local 'orgpan-last-org-buffer)
398 (defvar orgpan-point nil)
399 ;;(make-variable-buffer-local 'orgpan-point)
401 (defvar viper-emacs-state-mode-list)
402 (defvar viper-new-major-mode-buffer-list)
404 (defun orgpan-avoid-viper-in-buffer ()
405 ;; Fix-me: This is ugly. However see `this-major-mode-requires-vi-state':
406 (set (make-local-variable 'viper-emacs-state-mode-list) '(orgpan-mode))
407 (set (make-local-variable 'viper-new-major-mode-buffer-list) nil)
408 (local-set-key [?\ ] 'ignore))
410 (define-derived-mode orgpan-mode nil "Org-Panel"
411 "Mode for org-simple.el control panel."
412 (setq buffer-read-only t)
413 (unless orgpan-minor-mode-version
414 (add-hook 'pre-command-hook 'orgpan-mode-pre-command nil t)
415 (add-hook 'post-command-hook 'orgpan-mode-post-command t))
416 (orgpan-avoid-viper-in-buffer)
417 (setq cursor-type nil))
420 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
421 ;;; Panel layout
423 (defun orgpan-insert-field (text keymap explain)
424 (insert text)
425 (let* ((end (point))
426 (len (length text))
427 (beg (- end len))
428 (ovl (make-overlay beg end)))
429 (overlay-put ovl 'face orgpan-field-face)
430 (overlay-put ovl 'keymap keymap)
431 (overlay-put ovl 'orgpan-explain explain)))
433 (defconst orgpan-with-keymap
434 (let ((map (make-sparse-keymap)))
435 (set-keymap-parent map org-mode-map)
436 ;; Users are used to tabbing between fields:
437 (define-key map [(tab)] 'orgpan-forward-field)
438 (define-key map [(shift tab)] 'orgpan-backward-field)
439 ;; Now we must use something else for visibility (first does not work if Viper):
440 (define-key map [(meta tab)] 'org-cycle)
441 (define-key map [(control meta tab)] 'org-global-cycle)
442 map))
444 (defconst orgpan-without-keymap
445 (let ((map (make-sparse-keymap)))
446 (set-keymap-parent map org-mode-map)
447 ;; Visibility (those are in org-mode-map):
448 ;;(define-key map [tab] 'org-cycle)
449 ;;(define-key map [(shift tab)] 'org-global-cycle)
450 ;; Navigate:
451 (define-key map [left] 'outline-up-heading)
452 (define-key map [right] 'org-cycle)
453 (define-key map [up] 'outline-previous-visible-heading)
454 (define-key map [down] 'outline-next-visible-heading)
455 (define-key map [(shift down)] 'outline-forward-same-level)
456 (define-key map [(shift up)] 'outline-backward-same-level)
457 ;; Restructure:
458 (define-key map [(control up)] 'org-move-subtree-up)
459 (define-key map [(control down)] 'org-move-subtree-down)
460 (define-key map [(control left)] 'org-do-promote)
461 (define-key map [(control right)] 'org-do-demote)
462 (define-key map [(control shift left)] 'org-promote-subtree)
463 (define-key map [(control shift right)] 'org-demote-subtree)
464 ;; Todo etc
465 (define-key map [?+] 'org-priority-up)
466 (define-key map [?-] 'org-priority-down)
467 (define-key map [?t] 'org-todo)
468 map))
470 (defun orgpan-make-panel-without-buttons (buf)
471 (with-current-buffer buf
472 (insert (propertize "Org Panel" 'face 'orgpan-active-field))
473 (insert " ? for help, q quit\n")
474 (insert (propertize "arrows" 'face 'font-lock-keyword-face)
475 ": Go to, "
476 (propertize "C-arrows" 'face 'font-lock-keyword-face)
477 ": Edit tree\n"
478 (propertize "cxpz" 'face 'font-lock-keyword-face)
479 ": copy cut paste undo, "
480 (propertize "tT+-" 'face 'font-lock-keyword-face)
481 ": todo priority, "
482 (propertize "s" 'face 'font-lock-keyword-face)
483 " search"
485 (set-keymap-parent orgpan-mode-map orgpan-without-keymap)
488 (defun orgpan-make-panel-with-buttons (buf)
489 (with-current-buffer buf
490 (let* ((base-map (make-sparse-keymap))
491 (space-line (propertize "\n\n" 'face 'orgpan-spaceline))
492 (arrow-face 'font-lock-keyword-face)
493 (L (propertize "left" 'face arrow-face))
494 (R (propertize "right" 'face arrow-face))
495 (U (propertize "up" 'face arrow-face))
496 (D (propertize "down" 'face arrow-face)))
497 ;;(message D)(sit-for 2)
498 (define-key base-map [left] 'ignore)
499 (define-key base-map [right] 'ignore)
500 (define-key base-map [up] 'ignore)
501 (define-key base-map [down] 'ignore)
502 (define-key base-map [?q] 'delete-window)
503 (define-key base-map [??] 'orgpan-help)
504 ;; Navigating
505 (let ((map (copy-keymap base-map)))
506 (define-key map [left] 'outline-up-heading)
507 (define-key map [right] 'org-cycle)
508 (define-key map [up] 'outline-previous-visible-heading)
509 (define-key map [down] 'outline-next-visible-heading)
510 (define-key map [(shift down)] 'outline-forward-same-level)
511 (define-key map [(shift up)] 'outline-backward-same-level)
512 (orgpan-insert-field "Navigate" map (concat U "/" D ", " L ": Go to, " R ": Visibility")))
513 (insert " ")
514 (let ((map (copy-keymap base-map)))
515 (define-key map [up] 'org-move-subtree-up)
516 (define-key map [down] 'org-move-subtree-down)
517 (define-key map [left] 'org-do-promote)
518 (define-key map [right] 'org-do-demote)
519 (define-key map [(shift left)] 'org-promote-subtree)
520 (define-key map [(shift right)] 'org-demote-subtree)
521 (orgpan-insert-field
522 "Restructure" map
523 (concat U "/" D ": "
524 (propertize "Move" 'face 'font-lock-warning-face)
525 ", " L "/" R ": "
526 (propertize "Level (w S: Subtree Level)" 'face 'font-lock-warning-face))))
527 (insert " ")
528 (let ((map (copy-keymap base-map)))
529 (define-key map [up] 'org-priority-up)
530 (define-key map [down] 'org-priority-down)
531 (define-key map [right] 'org-todo)
532 (orgpan-insert-field "TODO/priority" map
533 (concat R ": TODO, " U "/" D ": Priority")))
535 (insert " ? for help, q quit\n")
536 (orgpan-display-bindings-help)
537 (setq orgpan-ovl-help (make-overlay (point) (point)))
540 (defun orgpan-make-panel-buffer ()
541 "Make the panel buffer."
542 (let* ((buf-name "*Org Panel*"))
543 (when orgpan-panel-buffer (kill-buffer orgpan-panel-buffer))
544 (setq orgpan-panel-buffer (get-buffer-create buf-name))
545 (if orgpan-panel-buttons
546 (orgpan-make-panel-with-buttons orgpan-panel-buffer)
547 (orgpan-make-panel-without-buttons orgpan-panel-buffer))
548 (with-current-buffer orgpan-panel-buffer
549 (orgpan-mode)
550 (goto-char (point-min)))
551 orgpan-panel-buffer))
553 (defun orgpan-help ()
554 (interactive)
555 (set-keymap-parent orgpan-with-keymap nil)
556 (set-keymap-parent orgpan-without-keymap nil)
557 (describe-function 'orgpan-panel)
558 (set-keymap-parent orgpan-with-keymap org-mode-map)
559 (set-keymap-parent orgpan-without-keymap org-mode-map)
560 (message "Use 'l' to remove help window")
563 (defun orgpan-panel ()
564 "Create a control panel for current `org-mode' buffer.
565 The control panel may be used to quickly move around and change
566 the headings. The idea is that when you want to to a lot of this
567 kind of editing you should be able to do that with few
568 keystrokes (and without having to remember the complicated
569 keystrokes). A typical situation when this perhaps can be useful
570 is when you are looking at your notes file \(usually ~/.notes,
571 see `remember-data-file') where you have saved quick notes with
572 `remember'.
574 The keys below are defined in the panel. Note that the commands
575 are carried out in the `org-mode' buffer that belongs to the
576 panel.
578 \\{orgpan-mode-map}
580 In addition to the keys above most of the keys in `org-mode' can
581 also be used from the panel.
583 Note: There are two forms of the control panel, one with buttons
584 and one without. The default is without, see
585 `orgpan-panel-buttons'. If buttons are used choosing a different
586 button changes the binding of the arrow keys."
587 (interactive)
588 (unless (derived-mode-p 'org-mode)
589 (error "Buffer is not in org-mode"))
590 (orgpan-delete-panel)
591 (unless orgpan-org-mode-commands
592 (map-keymap (lambda (ev def)
593 (when (and def
594 (symbolp def)
595 (fboundp def))
596 (setq orgpan-org-mode-commands
597 (cons def orgpan-org-mode-commands))))
598 org-mode-map))
599 ;;(org-back-to-heading)
600 ;;(remove-hook 'window-configuration-change-hook 'orgpan-window-config-change)
601 (setq orgpan-org-window (selected-window))
602 (setq orgpan-panel-window (split-window nil -4 'below))
603 (select-window orgpan-panel-window)
604 (set-window-buffer (selected-window) (orgpan-make-panel-buffer))
605 ;;(set-window-dedicated-p (selected-window) t)
606 ;; The minor mode version starts here:
607 (when orgpan-minor-mode-version
608 (select-window orgpan-org-window)
609 (orgpan-panel-minor-mode 1)
610 (add-hook 'post-command-hook 'orgpan-minor-post-command t)))
612 (defun orgpan-minor-post-command ()
613 (unless (and
614 ;; Check org window and buffer
615 (windowp orgpan-org-window)
616 (window-live-p orgpan-org-window)
617 (eq orgpan-org-window (selected-window))
618 (derived-mode-p 'org-mode)
619 ;; Check panel window and buffer
620 (windowp orgpan-panel-window)
621 (window-live-p orgpan-panel-window)
622 (bufferp orgpan-panel-buffer)
623 (buffer-live-p orgpan-panel-buffer)
624 (eq (window-buffer orgpan-panel-window) orgpan-panel-buffer)
625 ;; Check minor mode
626 orgpan-panel-minor-mode)
627 (orgpan-delete-panel)))
629 (define-minor-mode orgpan-panel-minor-mode
630 "Minor mode used in `org-mode' buffer when showing panel."
631 :keymap orgpan-mode-map
632 :lighter " PANEL"
633 :group 'orgpan
637 (provide 'org-panel)
638 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
640 ;;; org-panel.el ends here