Skip to content

Commit

Permalink
adds drawers and fixes headlines
Browse files Browse the repository at this point in the history
  • Loading branch information
agzam committed Sep 9, 2022
1 parent f146d1b commit 62894ac
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 15 deletions.
58 changes: 48 additions & 10 deletions README.org
Original file line number Diff line number Diff line change
@@ -1,21 +1,59 @@
**** Extends ~org-edit-special~ so it can be used to edit (almost) anything in Org-mode, things like: ~quote~, ~verse~, ~comment~ blocks, etc.
***** Installation
The package has not been published yet, use your package manager (or whatever you usually do to get it in your config)
By default, Org-mode doesn't let you edit things in an indirect buffer except for source blocks.

Doom users:
This package extends ~org-edit-special~ so it can be used to edit (almost) any type of block in Org-mode, things like ~quote~, ~verse~, ~comment~ blocks, etc.

packages.el:
** Installation
It's on MELPA. Load it using your preferred way.

*** Doom users:
~packages.el:~
#+begin_src emacs-lisp
(package! org-edit-indirect :recipe (:host github :repo "agzam/org-edit-indirect.el"))
(package! org-edit-indirect)
#+end_src

config.el:
~config.el:~
#+begin_src emacs-lisp
(use-package! org-edit-indirect
:hook (org-mode . org-edit-indirect-mode))
#+end_src

***** Usage
** Usage
- Move the cursor to any source, verse, comment, quote block; drawer; or a paragraph, headline, property drawer, or a plain list
- ~<C-c '>~ (or whatever ~org-edit-special~ normally binds to)

** Advanced usage
It's possible to set the major mode of the indirect buffer, based on the type of the block. I didn't want this package to be too intrusive, so I didn't implement this feature as part of the package. Here's an example of how that can be achieved:

- Move cursor to any source, verse, comment, quote block; or a paragraph, headline, property drawer, or a plain list
- ~<C-c '>~ (or whatever ~org-edit-special~ is normally bound to)
#+begin_src emacs-lisp
(defun edit-indirect-guess-mode-fn+ (parent-buffer beg _end)
"Guess the major mode for an edit-indirect buffer."
(let* ((type (with-current-buffer parent-buffer
(cond
;; set markdown-mode for quote & verse blocks
((and (eq major-mode 'org-mode)
(when-let ((s (save-mark-and-excursion
(goto-char (- beg 1))
(thing-at-point 'symbol))))
(string-match-p
"+begin_quote\\|+begin_verse" s)))
:quote)
;; json-mode for results drawer blocks,
;; src blocks like:
;; #+begin_src sh :results drawer
((and (eq major-mode 'org-mode)
(when-let ((s (save-mark-and-excursion
(goto-char (- beg 1))
(backward-word)
(thing-at-point 'word))))
(string-match-p "results" s)))
:results-drawer)
;; fallback to org-mode for the rest
((eq major-mode 'org-mode) :org-mode)))))
(cl-case type
(:quote (markdown-mode))
(:results-drawer (json-mode))
(:org-mode (org-mode))
(t (normal-mode)))))

(setq edit-indirect-guess-mode-function #'edit-indirect-guess-mode-fn+)
#+end_src
10 changes: 5 additions & 5 deletions org-edit-indirect.el
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
;; Author: Ag Ibragimomv <https://github.com/agzam>
;; Maintainer: Ag Ibragimomv <agzam.ibragimov@gmail.com>
;; Created: May, 2021
;; Version: 1.0.0
;; Version: 1.1.0
;; Keywords: convenience extensions outlines
;; Homepage: https://github.com/agzam/org-edit-indirect.el
;; Package-Requires: ((emacs "25.1") (edit-indirect "0.1.6") (org "9.0"))
;; Package-Requires: ((emacs "27") (edit-indirect "0.1.10") (org "9.0"))
;;
;; This file is not part of GNU Emacs

Expand Down Expand Up @@ -47,11 +47,11 @@
(let* ((el-type (org-element-type (org-element-context org-element)))
(parent (org-element-property :parent org-element))
(beg (pcase el-type
((or `quote-block `verse-block `comment-block `plain-list)
((or `quote-block `verse-block `comment-block `plain-list 'drawer 'paragraph 'headline)
(org-element-property :contents-begin org-element))
(_ (org-element-property :begin (or parent org-element)))))
(end (pcase el-type
((or `quote-block `verse-block `comment-block `plain-list)
((or `quote-block `verse-block `comment-block `plain-list 'drawer 'paragraph 'headline)
(org-element-property :contents-end org-element))
(_ (org-element-property :end (or parent org-element))))))
(edit-indirect-region beg end :display)))
Expand All @@ -69,7 +69,7 @@ ARG is passed to `org-edit-special'."
(pcase (org-element-type context)
((or `quote-block `verse-block `comment-block
`paragraph `headline `property-drawer
`plain-list `item)
`plain-list `item 'drawer 'link)
(org-edit-indirect-generic-block element))
(_ (org-edit-special arg)))))

Expand Down

0 comments on commit 62894ac

Please sign in to comment.