Skip to content

Instantly share code, notes, and snippets.

@iani
Created January 29, 2014 20:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iani/8695954 to your computer and use it in GitHub Desktop.
Save iani/8695954 to your computer and use it in GitHub Desktop.
Extensions and key binding for using icicles in Org-mode. Org-mode refile with icicles, search heading with icicles and optionally open subtree in independent buffer etc.
(add-hook 'org-mode-hook
(lambda () (imenu-add-to-menubar "Imenu")))
(setq org-imenu-depth 3)
(defun org-icicle-occur ()
"In org-mode, show entire buffer contents before running icicle-occur.
Otherwise icicle-occur will not place cursor at found location,
if the location is hidden."
(interactive)
(show-all)
(icicle-occur (point-min) (point-max))
(recenter 3))
(eval-after-load 'org
'(define-key org-mode-map (kbd "C-c C-'") 'org-icicle-occur))
(eval-after-load 'org
'(define-key org-mode-map (kbd "C-c i o") 'org-icicle-occur))
(defun org-icicle-imenu (separate-buffer)
"In org-mode, show entire buffer contents before running icicle-imenu.
Otherwise icicle-occur will not place cursor at found location,
if the location is hidden.
If called with prefix argument (C-u), then:
- open the found section in an indirect buffer.
- go back to the position where the point was before the command, in the
original buffer."
(interactive "P")
(show-all)
(let ((mark (point)))
(icicle-imenu (point-min) (point-max) t)
(cond (separate-buffer
(org-tree-to-indirect-buffer)
(goto-char mark))
(t (recenter 4)))))
(eval-after-load 'org
'(define-key org-mode-map (kbd "C-c C-=") 'org-icicle-imenu))
(eval-after-load 'org
'(define-key org-mode-map (kbd "C-c i m") 'org-icicle-imenu))
;; install alternative for org-mode C-c = org-table-eval-formula
;; which is stubbornly overwritten by icy-mode.
(eval-after-load 'org
'(define-key org-mode-map (kbd "C-c C-x =") 'org-table-eval-formula))
;; this is a redundant second try for the above, to be removed after testing:
(add-hook 'org-mode-hook
(lambda ()
(local-set-key (kbd "C-c M-=") 'org-table-eval-formula)))
;;; ???? Adapt org-mode to icicle menus when refiling (C-c C-w)
;;; Still problems. Cannot use standard org refiling with icicles activated!
(setq org-outline-path-complete-in-steps nil)
(add-hook 'org-mode-hook (lambda () (prelude-mode -1)))
(defun org-refile-icy (as-subtree &optional do-copy-p)
"Alternative to org-refile using icicles.
Refile or copy current section, to a location in the file selected with icicles.
Without prefix argument: Place the copied/cut section it *after* the selected section.
With prefix argument: Make the copied/cut section *a subtree* of the selected section.
Note 1: If quit with C-g, this function will have removed the section that
is to be refiled. To get it back, one has to undo, or paste.
Note 2: Reason for this function is that icicles seems to break org-modes headline
buffer display, so onehas to use icicles for all headline navigation if it is loaded."
(interactive "P")
(outline-back-to-heading)
(if do-copy-p (org-copy-subtree) (org-cut-subtree))
(show-all)
(icicle-imenu (point-min) (point-max) t)
(outline-next-heading)
(unless (eq (current-column) 0) (insert "\n"))
(org-paste-subtree)
(if as-subtree (org-demote-subtree)))
(defun org-copy-icy (as-subtree)
"Copy section to another location in file, selecting the location with icicles.
See org-refile-icy."
(interactive "P")
(org-refile-icy as-subtree t))
(eval-after-load 'org
'(define-key org-mode-map (kbd "C-c i r") 'org-refile-icy))
(eval-after-load 'org
'(define-key org-mode-map (kbd "C-c i c") 'org-copy-icy))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment