[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[O] [PATCH] org-src: allow `org-babel-edit-prep:.*' to mark region
From: |
Oleh |
Subject: |
[O] [PATCH] org-src: allow `org-babel-edit-prep:.*' to mark region |
Date: |
Sat, 29 Nov 2014 13:43:14 +0100 |
Hello,
Is it ok to apply the attached patch? I don't want to break anything.
I want to be able to denote my source blocks like so:
- *~* is the mark,
- *|* is the point
#+begin_src elisp
(~a b c| d e f g h i j k l m n o p q r s t u v w x y z)
#+end_src
- `org-edit-special' will automatically transform this markup into an
actual active region
- `org-edit-src-exit' will automatically transform an active region into markup
If anyone is interested, the implementation looks like this:
#+begin_src elisp
(defun org-src-denote-region (&optional context)
(when (and (memq major-mode '(emacs-lisp-mode))
(region-active-p))
(let ((pt (point))
(mk (mark)))
(deactivate-mark)
(insert "|")
(goto-char (if (> pt mk) mk (1+ mk)))
(insert "~"))))
(advice-add 'org-edit-src-exit :before #'org-src-denote-region)
(defun org-babel-edit-prep:elisp (info)
(when (string-match "[~|][^~|]+[|~]" (cadr info))
(let (mk pt deactivate-mark)
(goto-char (point-min))
(re-search-forward "[|~]")
(if (looking-back "~")
(progn
(backward-delete-char 1)
(setq mk (point))
(re-search-forward "|")
(backward-delete-char 1)
(set-mark mk))
(backward-delete-char 1)
(setq pt (point))
(re-search-forward "~")
(backward-delete-char 1)
(set-mark (point))
(goto-char pt)))))
#+end_src
The only thing left to do is to patch `org-edit-src-code'.
regards,
Oleh
0001-org-src-allow-org-babel-edit-prep-.-to-mark-region.patch
Description: Text Data
- [O] [PATCH] org-src: allow `org-babel-edit-prep:.*' to mark region,
Oleh <=