org-panel.el 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639
  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:
  10. ;;
  11. ;; Features that might be required by this library:
  12. ;;
  13. ;; `easymenu', `font-lock', `noutline', `org', `outline', `syntax',
  14. ;; `time-date'.
  15. ;;
  16. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  17. ;;
  18. ;;; Commentary:
  19. ;;
  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.
  22. ;;
  23. ;; To bring up the control panel type
  24. ;;
  25. ;; M-x orgpan-panel
  26. ;;
  27. ;; Type ? there for help.
  28. ;;
  29. ;; I suggest you add the following to your .emacs for quick access of
  30. ;; the panel:
  31. ;;
  32. ;; (eval-after-load 'org-mode
  33. ;; (define-key org-mode-map [(control ?c) ?p] 'orgpan-panel))
  34. ;;
  35. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  36. ;;
  37. ;;; Change log:
  38. ;;
  39. ;;
  40. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  41. ;;
  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.
  46. ;;
  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.
  51. ;;
  52. ;; You should have received a copy of the GNU General Public License
  53. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  54. ;;
  55. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  56. ;;
  57. ;;; Code:
  58. (require 'org)
  59. (require 'outline)
  60. ;; Fix-me: this is for testing. A minor mode version interferes badly
  61. ;; with emulation minor modes. On the other hand, the other version
  62. ;; interferes badly with (interactive ...).
  63. (defvar orgpan-minor-mode-version t)
  64. (defface orgpan-field
  65. '((t (:inherit 'widget-field)))
  66. "Face for fields."
  67. :group 'winsize)
  68. (defvar orgpan-field-face 'orgpan-field)
  69. (defface orgpan-active-field
  70. '((t (:inherit 'highlight)))
  71. "Face for fields."
  72. :group 'winsize)
  73. (defvar orgpan-active-field-face 'orgpan-active-field)
  74. (defface orgpan-spaceline
  75. '((t (:height 0.2)))
  76. "Face for spacing lines."
  77. :group 'winsize)
  78. (defcustom orgpan-panel-buttons nil
  79. "Panel style, if non-nil use buttons.
  80. If there are buttons in the panel they are used to change the way
  81. the arrow keys work. The panel looks something like this, with
  82. the first button chosen:
  83. [Navigate] [Restructure] [TODO/Priority]
  84. ----------
  85. up/down, left: Go to, right: Visibility
  86. The line below the buttons try to give a short hint about what
  87. the arrow keys does. \(Personally I prefer the version without
  88. buttons since I then do not have to remember which button is
  89. active.)"
  90. :type 'boolean
  91. :group 'winsize)
  92. ;; Fix-me: add org-mode-map
  93. (defconst orgpan-org-mode-commands nil)
  94. (defconst orgpan-org-commands
  95. '(
  96. orgpan-copy-subtree
  97. orgpan-cut-subtree
  98. orgpan-paste-subtree
  99. undo
  100. ;;
  101. ;orgpan-occur
  102. ;;
  103. org-cycle
  104. org-global-cycle
  105. outline-up-heading
  106. outline-next-visible-heading
  107. outline-previous-visible-heading
  108. outline-forward-same-level
  109. outline-backward-same-level
  110. org-todo
  111. org-show-todo-tree
  112. org-priority-up
  113. org-priority-down
  114. org-move-subtree-up
  115. org-move-subtree-down
  116. org-do-promote
  117. org-do-demote
  118. org-promote-subtree
  119. org-demote-subtree))
  120. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  121. ;;; Hook functions etc
  122. (defun orgpan-delete-panel ()
  123. "Remove the panel."
  124. (interactive)
  125. (when (buffer-live-p orgpan-panel-buffer)
  126. (delete-windows-on orgpan-panel-buffer)
  127. (kill-buffer orgpan-panel-buffer))
  128. (setq orgpan-panel-buffer nil)
  129. (setq orgpan-panel-window nil)
  130. (orgpan-panel-minor-mode 0)
  131. (remove-hook 'post-command-hook 'orgpan-minor-post-command)
  132. (remove-hook 'post-command-hook 'orgpan-mode-post-command)
  133. ;;(remove-hook 'window-configuration-change-hook 'orgpan-window-config-change)
  134. )
  135. (defvar orgpan-last-command-was-from-panel nil)
  136. (defun orgpan-mode-pre-command ()
  137. (setq orgpan-last-command-was-from-panel nil)
  138. (condition-case err
  139. (if (not (and (windowp orgpan-org-window)
  140. (window-live-p orgpan-org-window)))
  141. (progn
  142. (setq this-command 'ignore)
  143. (orgpan-delete-panel)
  144. (message "The window belonging to the panel had disappeared, removed panel."))
  145. (let ((buf (window-buffer orgpan-org-window)))
  146. (when (with-current-buffer buf
  147. (derived-mode-p 'org-mode))
  148. (setq orgpan-last-org-buffer buf))
  149. ;; Fix me: add a list of those commands that are not
  150. ;; meaningful from the panel (for example org-time-stamp)
  151. (when (or (memq this-command orgpan-org-commands)
  152. (memq this-command orgpan-org-mode-commands)
  153. ;; For some reason not all org commands are found above:
  154. (string= "org-" (substring (format "%s" this-command) 0 4)))
  155. (if (not (with-current-buffer buf
  156. (derived-mode-p 'org-mode)))
  157. (progn
  158. (if (buffer-live-p orgpan-org-buffer)
  159. (set-window-buffer orgpan-org-window orgpan-org-buffer)
  160. (message "Please use `l' or `b' to choose an org-mode buffer"))
  161. (setq this-command 'ignore))
  162. (setq orgpan-org-buffer (window-buffer orgpan-org-window))
  163. (setq orgpan-last-command-was-from-panel t)
  164. (select-window orgpan-org-window)
  165. ;;(when (active-minibuffer-window
  166. ;;(set-buffer orgpan-org-buffer)
  167. ))))
  168. (error (lwarn 't :warning "orgpan-pre: %S" err))))
  169. (defun orgpan-mode-post-command ()
  170. (condition-case err
  171. (progn
  172. (unless (and (windowp orgpan-panel-window)
  173. (window-live-p orgpan-panel-window)
  174. (bufferp orgpan-panel-buffer)
  175. (buffer-live-p orgpan-panel-buffer))
  176. ;;(orgpan-delete-panel)
  177. )
  178. (when (and orgpan-last-command-was-from-panel
  179. (windowp orgpan-panel-window)
  180. (window-live-p orgpan-panel-window))
  181. (select-window orgpan-panel-window)
  182. (when (derived-mode-p 'orgpan-mode)
  183. (setq deactivate-mark t)
  184. (when orgpan-panel-buttons
  185. (unless (and orgpan-point
  186. (= (point) orgpan-point))
  187. ;; Go backward so it is possible to click on a "button":
  188. (orgpan-backward-field))))))
  189. (error (lwarn 't :warning "orgpan-post: %S" err))))
  190. ;; (defun orgpan-window-config-change ()
  191. ;; "Check if any frame is displaying an orgpan panel.
  192. ;; If not remove `orgpan-mode-post-command' and this function from
  193. ;; the hooks."
  194. ;; (condition-case err
  195. ;; (unless (and (
  196. ;; (let ((found-pan nil))
  197. ;; (dolist (f (frame-list))
  198. ;; (dolist (w (window-list f 'nomini))
  199. ;; (with-current-buffer (window-buffer w)
  200. ;; (when (derived-mode-p 'orgpan-mode)
  201. ;; (setq found-pan t)))))
  202. ;; (unless found-pan
  203. ;; (remove-hook 'post-command-hook 'orgpan-mode-post-command)
  204. ;; (remove-hook 'window-configuration-change-hook 'orgpan-window-config-change)))
  205. ;; (error (lwarn 't :warning "Error in orgpan-config-change: %S" err))))
  206. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  207. ;;; Commands
  208. (defun orgpan-last-buffer ()
  209. "Open last org-mode buffer in panels org window."
  210. (interactive)
  211. (let ((buf (window-buffer orgpan-org-window))
  212. (last-buf orgpan-last-org-buffer))
  213. (when (with-current-buffer buf
  214. (derived-mode-p 'org-mode))
  215. (setq orgpan-last-org-buffer buf))
  216. (when (eq last-buf buf)
  217. (setq last-buf nil))
  218. (if (not last-buf)
  219. (orgpan-switch-buffer)
  220. (set-window-buffer orgpan-org-window last-buf))))
  221. (defun orgpan-switch-buffer ()
  222. "Switch to next org-mode buffer in panels org window."
  223. (interactive)
  224. (let ((buf (window-buffer orgpan-org-window))
  225. (org-buffers nil))
  226. (with-current-buffer buf
  227. (when (derived-mode-p 'org-mode)
  228. (bury-buffer buf)
  229. (setq orgpan-last-org-buffer buf)))
  230. (setq org-buffers (delq nil (mapcar (lambda (buf)
  231. (when (with-current-buffer buf
  232. (derived-mode-p 'org-mode))
  233. buf))
  234. (buffer-list))))
  235. (setq org-buffers (delq buf org-buffers))
  236. (set-window-buffer orgpan-org-window (car org-buffers))
  237. (setq orgpan-org-buffer (car org-buffers))))
  238. (defun orgpan-paste-subtree ()
  239. (interactive)
  240. (if (y-or-n-p "Paste subtree here? ")
  241. (org-paste-subtree)
  242. (message "Nothing was pasted")))
  243. (defun orgpan-cut-subtree ()
  244. (interactive)
  245. (let ((heading (progn
  246. (org-back-to-heading)
  247. (buffer-substring (point) (line-end-position))
  248. )))
  249. (if (y-or-n-p (format "Do you want to cut the subtree\n%s\n? " heading))
  250. (org-cut-subtree)
  251. (message "Nothing was cut"))))
  252. (defun orgpan-copy-subtree ()
  253. (interactive)
  254. (let ((heading (progn
  255. (org-back-to-heading)
  256. (buffer-substring (point) (line-end-position))
  257. )))
  258. (if (y-or-n-p (format "Do you want to copy the subtree\n%s\n? " heading))
  259. (org-copy-subtree)
  260. (message "Nothing was copied"))))
  261. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  262. ;;; Buttons
  263. (defvar orgpan-ovl-help nil)
  264. (defun orgpan-check-panel-mode ()
  265. (unless (derived-mode-p 'orgpan-mode)
  266. (error "Not orgpan-mode in buffer: %s" major-mode)))
  267. (defun orgpan-display-bindings-help ()
  268. (orgpan-check-panel-mode)
  269. (setq orgpan-point (point))
  270. (let* ((ovls (overlays-at (point)))
  271. (ovl (car ovls))
  272. (help (when ovl (overlay-get ovl 'orgpan-explain))))
  273. (dolist (o (overlays-in (point-min) (point-max)))
  274. (overlay-put o 'face orgpan-field-face))
  275. (overlay-put ovl 'face orgpan-active-field-face)
  276. (overlay-put orgpan-ovl-help 'before-string help)))
  277. (defun orgpan-forward-field ()
  278. (interactive)
  279. (orgpan-check-panel-mode)
  280. (let ((pos (next-overlay-change (point))))
  281. (unless (overlays-at pos)
  282. (setq pos (next-overlay-change pos)))
  283. (when (= pos (point-max))
  284. (setq pos (point-min))
  285. (unless (overlays-at pos)
  286. (setq pos (next-overlay-change pos))))
  287. (goto-char pos))
  288. (orgpan-display-bindings-help))
  289. (defun orgpan-backward-field ()
  290. (interactive)
  291. (orgpan-check-panel-mode)
  292. (when (= (point) (point-min))
  293. (goto-char (point-max)))
  294. (let ((pos (previous-overlay-change (point))))
  295. (unless (overlays-at pos)
  296. (setq pos (previous-overlay-change pos)))
  297. (goto-char pos))
  298. (orgpan-display-bindings-help))
  299. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  300. ;;; Mode
  301. (defconst orgpan-mode-map
  302. ;; Fix-me: clean up here!
  303. ;; Fix-me: viper support
  304. (let ((map (make-sparse-keymap)))
  305. (define-key map [?q] 'orgpan-delete-panel)
  306. (define-key map [??] 'orgpan-help)
  307. ;; Copying etc
  308. (define-key map [?c] 'orgpan-copy-subtree)
  309. (define-key map [?x] 'orgpan-cut-subtree)
  310. (define-key map [?p] 'orgpan-paste-subtree)
  311. (define-key map [?z] 'undo)
  312. ;; Buffers:
  313. (define-key map [?b] 'orgpan-switch-buffer)
  314. (define-key map [?l] 'orgpan-last-buffer)
  315. ;; Some keys for moving between headings. Emacs keys for next/prev
  316. ;; line seems ok:
  317. (define-key map [(control ?p)] 'outline-previous-visible-heading)
  318. (define-key map [(control ?n)] 'outline-next-visible-heading)
  319. (define-key map [(shift control ?p)] 'outline-backward-same-level)
  320. (define-key map [(shift control ?n)] 'outline-forward-same-level)
  321. ;; A mnemunic for up:
  322. (define-key map [(control ?u)] 'outline-up-heading)
  323. ;; Search sparse tree:
  324. ;;
  325. ;; Fix-me: Search does not work, some problem with
  326. ;; interactive. Probably have to turn the whole thing around and
  327. ;; always be in the org buffer, but with a minor mode running
  328. ;; there.
  329. ;;
  330. ;;(define-key map [?s] 'org-sparse-tree)
  331. (define-key map [?s] 'orgpan-occur)
  332. ;; Same as in org-mode:
  333. ;;(define-key map [(control ?c)(control ?v)] 'org-show-todo-tree)
  334. ;; Fix-me: This leads to strange problems:
  335. ;;(define-key map [t] 'ignore)
  336. map))
  337. (defun orgpan-occur ()
  338. "Replacement for `org-occur'.
  339. Technical reasons."
  340. (interactive)
  341. (let ((rgx (read-from-minibuffer "my mini Regexp: ")))
  342. (setq orgpan-last-command-was-from-panel t)
  343. (select-window orgpan-org-window)
  344. (org-occur rgx)))
  345. (defvar orgpan-panel-window nil
  346. "The window showing `orgpan-panel-buffer'.")
  347. (defvar orgpan-panel-buffer nil
  348. "The panel buffer.
  349. There can be only one such buffer at any time.")
  350. (defvar orgpan-org-window nil)
  351. ;;(make-variable-buffer-local 'orgpan-org-window)
  352. ;; Fix-me: used?
  353. (defvar orgpan-org-buffer nil)
  354. ;;(make-variable-buffer-local 'orgpan-org-buffer)
  355. (defvar orgpan-last-org-buffer nil)
  356. ;;(make-variable-buffer-local 'orgpan-last-org-buffer)
  357. (defvar orgpan-point nil)
  358. ;;(make-variable-buffer-local 'orgpan-point)
  359. (defvar viper-emacs-state-mode-list)
  360. (defvar viper-new-major-mode-buffer-list)
  361. (defun orgpan-avoid-viper-in-buffer ()
  362. ;; Fix-me: This is ugly. However see `this-major-mode-requires-vi-state':
  363. (set (make-local-variable 'viper-emacs-state-mode-list) '(orgpan-mode))
  364. (set (make-local-variable 'viper-new-major-mode-buffer-list) nil)
  365. (local-set-key [?\ ] 'ignore))
  366. (define-derived-mode orgpan-mode nil "Org-Panel"
  367. "Mode for org-simple.el control panel."
  368. (setq buffer-read-only t)
  369. (unless orgpan-minor-mode-version
  370. (add-hook 'pre-command-hook 'orgpan-mode-pre-command nil t)
  371. (add-hook 'post-command-hook 'orgpan-mode-post-command t))
  372. (orgpan-avoid-viper-in-buffer)
  373. (setq cursor-type nil))
  374. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  375. ;;; Panel layout
  376. (defun orgpan-insert-field (text keymap explain)
  377. (insert text)
  378. (let* ((end (point))
  379. (len (length text))
  380. (beg (- end len))
  381. (ovl (make-overlay beg end)))
  382. (overlay-put ovl 'face orgpan-field-face)
  383. (overlay-put ovl 'keymap keymap)
  384. (overlay-put ovl 'orgpan-explain explain)))
  385. (defconst orgpan-with-keymap
  386. (let ((map (make-sparse-keymap)))
  387. (set-keymap-parent map org-mode-map)
  388. ;; Users are used to tabbing between fields:
  389. (define-key map [(tab)] 'orgpan-forward-field)
  390. (define-key map [(shift tab)] 'orgpan-backward-field)
  391. ;; Now we must use something else for visibility (first does not work if Viper):
  392. (define-key map [(meta tab)] 'org-cycle)
  393. (define-key map [(control meta tab)] 'org-global-cycle)
  394. map))
  395. (defconst orgpan-without-keymap
  396. (let ((map (make-sparse-keymap)))
  397. (set-keymap-parent map org-mode-map)
  398. ;; Visibility (those are in org-mode-map):
  399. ;;(define-key map [tab] 'org-cycle)
  400. ;;(define-key map [(shift tab)] 'org-global-cycle)
  401. ;; Navigate:
  402. (define-key map [left] 'outline-up-heading)
  403. (define-key map [right] 'org-cycle)
  404. (define-key map [up] 'outline-previous-visible-heading)
  405. (define-key map [down] 'outline-next-visible-heading)
  406. (define-key map [(shift down)] 'outline-forward-same-level)
  407. (define-key map [(shift up)] 'outline-backward-same-level)
  408. ;; Restructure:
  409. (define-key map [(control up)] 'org-move-subtree-up)
  410. (define-key map [(control down)] 'org-move-subtree-down)
  411. (define-key map [(control left)] 'org-do-promote)
  412. (define-key map [(control right)] 'org-do-demote)
  413. (define-key map [(control shift left)] 'org-promote-subtree)
  414. (define-key map [(control shift right)] 'org-demote-subtree)
  415. ;; Todo etc
  416. (define-key map [?+] 'org-priority-up)
  417. (define-key map [?-] 'org-priority-down)
  418. (define-key map [?t] 'org-todo)
  419. map))
  420. (defun orgpan-make-panel-without-buttons (buf)
  421. (with-current-buffer buf
  422. (insert (propertize "Org Panel" 'face 'orgpan-active-field))
  423. (insert " ? for help, q quit\n")
  424. (insert (propertize "arrows" 'face 'font-lock-keyword-face)
  425. ": Go to, "
  426. (propertize "C-arrows" 'face 'font-lock-keyword-face)
  427. ": Edit tree\n"
  428. (propertize "cxpz" 'face 'font-lock-keyword-face)
  429. ": copy cut paste undo, "
  430. (propertize "tT+-" 'face 'font-lock-keyword-face)
  431. ": todo priority, "
  432. (propertize "s" 'face 'font-lock-keyword-face)
  433. " search"
  434. )
  435. (set-keymap-parent orgpan-mode-map orgpan-without-keymap)
  436. ))
  437. (defun orgpan-make-panel-with-buttons (buf)
  438. (with-current-buffer buf
  439. (let* ((base-map (make-sparse-keymap))
  440. (space-line (propertize "\n\n" 'face 'orgpan-spaceline))
  441. (arrow-face 'font-lock-keyword-face)
  442. (L (propertize "left" 'face arrow-face))
  443. (R (propertize "right" 'face arrow-face))
  444. (U (propertize "up" 'face arrow-face))
  445. (D (propertize "down" 'face arrow-face)))
  446. ;;(message D)(sit-for 2)
  447. (define-key base-map [left] 'ignore)
  448. (define-key base-map [right] 'ignore)
  449. (define-key base-map [up] 'ignore)
  450. (define-key base-map [down] 'ignore)
  451. (define-key base-map [?q] 'delete-window)
  452. (define-key base-map [??] 'orgpan-help)
  453. ;; Navigating
  454. (let ((map (copy-keymap base-map)))
  455. (define-key map [left] 'outline-up-heading)
  456. (define-key map [right] 'org-cycle)
  457. (define-key map [up] 'outline-previous-visible-heading)
  458. (define-key map [down] 'outline-next-visible-heading)
  459. (define-key map [(shift down)] 'outline-forward-same-level)
  460. (define-key map [(shift up)] 'outline-backward-same-level)
  461. (orgpan-insert-field "Navigate" map (concat U "/" D ", " L ": Go to, " R ": Visibility")))
  462. (insert " ")
  463. (let ((map (copy-keymap base-map)))
  464. (define-key map [up] 'org-move-subtree-up)
  465. (define-key map [down] 'org-move-subtree-down)
  466. (define-key map [left] 'org-do-promote)
  467. (define-key map [right] 'org-do-demote)
  468. (define-key map [(shift left)] 'org-promote-subtree)
  469. (define-key map [(shift right)] 'org-demote-subtree)
  470. (orgpan-insert-field
  471. "Restructure" map
  472. (concat U "/" D ": "
  473. (propertize "Move" 'face 'font-lock-warning-face)
  474. ", " L "/" R ": "
  475. (propertize "Level (w S: Subtree Level)" 'face 'font-lock-warning-face))))
  476. (insert " ")
  477. (let ((map (copy-keymap base-map)))
  478. (define-key map [up] 'org-priority-up)
  479. (define-key map [down] 'org-priority-down)
  480. (define-key map [right] 'org-todo)
  481. (orgpan-insert-field "TODO/priority" map
  482. (concat R ": TODO, " U "/" D ": Priority")))
  483. )
  484. (insert " ? for help, q quit\n")
  485. (orgpan-display-bindings-help)
  486. (setq orgpan-ovl-help (make-overlay (point) (point)))
  487. ))
  488. (defun orgpan-make-panel-buffer ()
  489. "Make the panel buffer."
  490. (let* ((buf-name "*Org Panel*"))
  491. (when orgpan-panel-buffer (kill-buffer orgpan-panel-buffer))
  492. (setq orgpan-panel-buffer (get-buffer-create buf-name))
  493. (if orgpan-panel-buttons
  494. (orgpan-make-panel-with-buttons orgpan-panel-buffer)
  495. (orgpan-make-panel-without-buttons orgpan-panel-buffer))
  496. (with-current-buffer orgpan-panel-buffer
  497. (orgpan-mode)
  498. (goto-char (point-min)))
  499. orgpan-panel-buffer))
  500. (defun orgpan-help ()
  501. (interactive)
  502. (set-keymap-parent orgpan-with-keymap nil)
  503. (set-keymap-parent orgpan-without-keymap nil)
  504. (describe-function 'orgpan-panel)
  505. (set-keymap-parent orgpan-with-keymap org-mode-map)
  506. (set-keymap-parent orgpan-without-keymap org-mode-map)
  507. (message "Use 'l' to remove help window")
  508. )
  509. (defun orgpan-panel ()
  510. "Create a control panel for current `org-mode' buffer.
  511. The control panel may be used to quickly move around and change
  512. the headings. The idea is that when you want to to a lot of this
  513. kind of editing you should be able to do that with few
  514. keystrokes (and without having to remember the complicated
  515. keystrokes). A typical situation when this perhaps can be useful
  516. is when you are looking at your notes file \(usually ~/.notes,
  517. see `remember-data-file') where you have saved quick notes with
  518. `remember'.
  519. The keys below are defined in the panel. Note that the commands
  520. are carried out in the `org-mode' buffer that belongs to the
  521. panel.
  522. \\{orgpan-mode-map}
  523. In addition to the keys above most of the keys in `org-mode' can
  524. also be used from the panel.
  525. Note: There are two forms of the control panel, one with buttons
  526. and one without. The default is without, see
  527. `orgpan-panel-buttons'. If buttons are used choosing a different
  528. button changes the binding of the arrow keys."
  529. (interactive)
  530. (unless (derived-mode-p 'org-mode)
  531. (error "Buffer is not in org-mode"))
  532. (orgpan-delete-panel)
  533. (unless orgpan-org-mode-commands
  534. (map-keymap (lambda (ev def)
  535. (when (and def
  536. (symbolp def)
  537. (fboundp def))
  538. (setq orgpan-org-mode-commands
  539. (cons def orgpan-org-mode-commands))))
  540. org-mode-map))
  541. ;;(org-back-to-heading)
  542. ;;(remove-hook 'window-configuration-change-hook 'orgpan-window-config-change)
  543. (setq orgpan-org-window (selected-window))
  544. (setq orgpan-panel-window (split-window nil -4 'below))
  545. (select-window orgpan-panel-window)
  546. (set-window-buffer (selected-window) (orgpan-make-panel-buffer))
  547. ;;(set-window-dedicated-p (selected-window) t)
  548. ;; The minor mode version starts here:
  549. (when orgpan-minor-mode-version
  550. (select-window orgpan-org-window)
  551. (orgpan-panel-minor-mode 1)
  552. (add-hook 'post-command-hook 'orgpan-minor-post-command t)))
  553. (defun orgpan-minor-post-command ()
  554. (unless (and
  555. ;; Check org window and buffer
  556. (windowp orgpan-org-window)
  557. (window-live-p orgpan-org-window)
  558. (eq orgpan-org-window (selected-window))
  559. (derived-mode-p 'org-mode)
  560. ;; Check panel window and buffer
  561. (windowp orgpan-panel-window)
  562. (window-live-p orgpan-panel-window)
  563. (bufferp orgpan-panel-buffer)
  564. (buffer-live-p orgpan-panel-buffer)
  565. (eq (window-buffer orgpan-panel-window) orgpan-panel-buffer)
  566. ;; Check minor mode
  567. orgpan-panel-minor-mode)
  568. (orgpan-delete-panel)))
  569. (define-minor-mode orgpan-panel-minor-mode
  570. "Minor mode used in `org-mode' buffer when showing panel."
  571. :keymap orgpan-mode-map
  572. :lighter " PANEL"
  573. :group 'orgpan
  574. )
  575. (provide 'org-panel)
  576. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  577. ;;; org-panel.el ends here