From mboxrd@z Thu Jan 1 00:00:00 1970 From: Rasmus Subject: [Prelim. patch] extend org-meta-return to keywords Date: Wed, 19 Nov 2014 15:41:57 +0100 Message-ID: <87egszw8ui.fsf@gmx.us> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:35992) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xr6Sb-0002kk-J0 for emacs-orgmode@gnu.org; Wed, 19 Nov 2014 09:42:27 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Xr6SV-0004Bk-7H for emacs-orgmode@gnu.org; Wed, 19 Nov 2014 09:42:21 -0500 Received: from plane.gmane.org ([80.91.229.3]:46774) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xr6SV-0004BY-0q for emacs-orgmode@gnu.org; Wed, 19 Nov 2014 09:42:15 -0500 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1Xr6ST-0008Kv-BJ for emacs-orgmode@gnu.org; Wed, 19 Nov 2014 15:42:13 +0100 Received: from 109.201.154.183 ([109.201.154.183]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 19 Nov 2014 15:42:13 +0100 Received: from rasmus by 109.201.154.183 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 19 Nov 2014 15:42:13 +0100 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: emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Hi, Something I have wanted for a while is to have M-RET work "as expected"(?) on keyword lines such as #+LATEX_HEADER, #+CAPTION etc. An "animation" to illustrate, where '|' is point: #+CAPTION: this is a |long caption # click ⇒ #+CAPTION: this is a #+CAPTION: |long caption Would anyone else like this? Attached is a quick patch that works surprisingly well. I would work more on it if you guys agree this would be useful. It probably need much more work for corner-cases (any ideas what these are)? Thanks, Rasmus -- When the facts change, I change my mind. What do you do, sir? --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-org.el-Add-keyword-support-to-M-RET.patch >From 60a9cefcc2997cc53a448d1c57ca71935ea6426f Mon Sep 17 00:00:00 2001 From: rasmus Date: Wed, 19 Nov 2014 15:39:19 +0100 Subject: [PATCH] org.el: Add keyword-support to M-RET * org.el (org-insert-keyword): New function. (org-meta-return): May call `org-insert-keyword'. --- lisp/org.el | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/lisp/org.el b/lisp/org.el index dbd2cb7..627c409 100755 --- a/lisp/org.el +++ b/lisp/org.el @@ -21286,6 +21286,18 @@ number of stars to add." (forward-line))))))) (unless toggled (message "Cannot toggle heading from here")))) +(defun org-insert-keyword (&optional arg) + "Insert a new keyword at point. + +ARG may be used to specify a keyword. Otherwise the keyword is determined from the context. + +Mainly used for `org-meta-return'." + (interactive "P") + (let* ((elm (org-element-at-point)) + (key (or arg (and (eq 'keyword (org-element-type elm)) + (org-element-property :key elm))))) + (and key (insert (format "\n#+%s: " key))))) + (defun org-meta-return (&optional arg) "Insert a new heading or wrap a region in a table. Calls `org-insert-heading' or `org-table-wrap-region', depending @@ -21298,12 +21310,13 @@ on context. See the individual commands for more information." (when (eq type 'table-row) (setq element (org-element-property :parent element)) (setq type 'table)) - (if (and (eq type 'table) - (eq (org-element-property :type element) 'org) - (>= (point) (org-element-property :contents-begin element)) - (< (point) (org-element-property :contents-end element))) - (call-interactively 'org-table-wrap-region) - (call-interactively 'org-insert-heading))))) + (cond ((and (eq type 'table) + (eq (org-element-property :type element) 'org) + (>= (point) (org-element-property :contents-begin element)) + (< (point) (org-element-property :contents-end element))) + (call-interactively 'org-table-wrap-region)) + ((eq type 'keyword) (call-interactively 'org-insert-keyword)) + (t (call-interactively 'org-insert-heading)))))) ;;; Menu entries -- 2.1.3 --=-=-=--