From mboxrd@z Thu Jan 1 00:00:00 1970 From: Oleh Subject: [PATCH] org-src: allow `org-babel-edit-prep:.*' to mark region Date: Sat, 29 Nov 2014 13:43:14 +0100 Message-ID: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary=089e0102f88493b7cb0508feb8ed Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:40646) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XuhMq-000808-Pg for emacs-orgmode@gnu.org; Sat, 29 Nov 2014 07:43:17 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XuhMp-0003EC-Rm for emacs-orgmode@gnu.org; Sat, 29 Nov 2014 07:43:16 -0500 Received: from mail-wg0-x22a.google.com ([2a00:1450:400c:c00::22a]:46966) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XuhMp-0003E4-Jr for emacs-orgmode@gnu.org; Sat, 29 Nov 2014 07:43:15 -0500 Received: by mail-wg0-f42.google.com with SMTP id z12so10642886wgg.1 for ; Sat, 29 Nov 2014 04:43:15 -0800 (PST) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: org mode --089e0102f88493b7cb0508feb8ed Content-Type: text/plain; charset=UTF-8 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 --089e0102f88493b7cb0508feb8ed Content-Type: text/x-patch; charset=US-ASCII; name="0001-org-src-allow-org-babel-edit-prep-.-to-mark-region.patch" Content-Disposition: attachment; filename="0001-org-src-allow-org-babel-edit-prep-.-to-mark-region.patch" Content-Transfer-Encoding: base64 X-Attachment-Id: f_i32ylaje0 RnJvbSA2NmYxMTdkM2JhYjNiZTY4MmYxMzZhNzQzNzZhYzhlNWNhOTI4NzZhIE1vbiBTZXAgMTcg MDA6MDA6MDAgMjAwMQpGcm9tOiBPbGVoIEtyZWhlbCA8b2h3b2Vvd2hvQGdtYWlsLmNvbT4KRGF0 ZTogU2F0LCAyOSBOb3YgMjAxNCAxMzoyMDo0MSArMDEwMApTdWJqZWN0OiBbUEFUQ0hdIG9yZy1z cmM6IGFsbG93IGBvcmctYmFiZWwtZWRpdC1wcmVwOi4qJyB0byBtYXJrIHJlZ2lvbgoKKiBsaXNw L29yZy1zcmMuZWwgKG9yZy1lZGl0LXNyYy1jb2RlKTogTGV0IGBkZWFjdGl2YXRlLW1hcmsnIG5p bC4KLS0tCiBsaXNwL29yZy1zcmMuZWwgfCAzICsrLQogMSBmaWxlIGNoYW5nZWQsIDIgaW5zZXJ0 aW9ucygrKSwgMSBkZWxldGlvbigtKQoKZGlmZiAtLWdpdCBhL2xpc3Avb3JnLXNyYy5lbCBiL2xp c3Avb3JnLXNyYy5lbAppbmRleCA2YmMyMTcxLi5hZjUzMzZkID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