Skip to content

Commit 7ce1d66

Browse files
committed
emacs: add ediff hook for org files
1 parent 2199b0f commit 7ce1d66

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

modules/home/emacs/org-mode.nix

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,28 @@
303303
(mermaid . t)
304304
(sql . t)
305305
(shell . t)))
306+
307+
;; Check for org mode and existence of buffer
308+
(defun f-ediff-org-showhide (buf command &rest cmdargs)
309+
"If buffer exists and is orgmode then execute command"
310+
(when buf
311+
(when (eq (buffer-local-value 'major-mode (get-buffer buf)) 'org-mode)
312+
(save-excursion (set-buffer buf) (apply command cmdargs)))))
313+
314+
(defun f-ediff-org-unfold-tree-element ()
315+
"Unfold tree at diff location"
316+
(f-ediff-org-showhide ediff-buffer-A 'org-reveal)
317+
(f-ediff-org-showhide ediff-buffer-B 'org-reveal)
318+
(f-ediff-org-showhide ediff-buffer-C 'org-reveal))
319+
320+
(defun f-ediff-org-fold-tree ()
321+
"Fold tree back to top level"
322+
(f-ediff-org-showhide ediff-buffer-A 'hide-sublevels 1)
323+
(f-ediff-org-showhide ediff-buffer-B 'hide-sublevels 1)
324+
(f-ediff-org-showhide ediff-buffer-C 'hide-sublevels 1))
325+
326+
(add-hook 'ediff-select-hook 'f-ediff-org-unfold-tree-element)
327+
(add-hook 'ediff-unselect-hook 'f-ediff-org-fold-tree)
306328
'';
307329
# bindLocal = {
308330
# org-mode-map = {

0 commit comments

Comments
 (0)