From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nicolas Goaziou Subject: Re: [patch] extend org-meta-return to keywords Date: Sat, 22 Nov 2014 10:52:11 +0100 Message-ID: <87fvdb4l6c.fsf@nicolasgoaziou.fr> References: <87egszw8ui.fsf@gmx.us> <87wq6o3u57.fsf@gmx.us> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:49132) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xs7Lm-0004kg-JS for emacs-orgmode@gnu.org; Sat, 22 Nov 2014 04:51:38 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Xs7Le-0007iH-Gm for emacs-orgmode@gnu.org; Sat, 22 Nov 2014 04:51:30 -0500 Received: from relay3-d.mail.gandi.net ([2001:4b98:c:538::195]:43439) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xs7Le-0007hM-7Q for emacs-orgmode@gnu.org; Sat, 22 Nov 2014 04:51:22 -0500 In-Reply-To: <87wq6o3u57.fsf@gmx.us> (rasmus@gmx.us's message of "Sat, 22 Nov 2014 02:23:48 +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: Rasmus Cc: emacs-orgmode@gnu.org Hello, Rasmus writes: > Attached is a new version of the patch that will respect the variables > that also govern `org-insert-headline'. It's smarter and preserves the > layout better. Thanks for the patch. However there are already mechanisms to complete keywords faster (e.g., M-TAB, yasnippet). Of course, yours is more efficient, but also very specific. It makes sense on very few keywords. I have no strong opinion here, but I don't think it is general enough to go into core. Moreover, it can get in the way of expected M-RET behaviour, as in the following example - item | #+caption: test untenrsiu where M-RET is expected to insert an item. Anyway, some comments follow. > + (point-at-bol-p (looking-back "^[[:space:]]*")) (point-at-bol-p (save-excursion (skip-chars-backward " \t") (bolp))) See last paragraph in `looking-back' docstring. > + (end-of-keyword > + (save-excursion > + (beginning-of-line) > + (search-forward-regexp Nitpick: `re-search-forward' > + org-element--affiliated-re (point-at-eol) t) Nitpick: `line-end-position' Also, you're not supposed to use `org-element--affiliated-re', as suggested by the double hyphen. If you want to tell when point is at an affiliated keyword, use (< (point) (org-element-property :post-affiliated element)) where ELEMENT is returned by `org-element-at-point'. You can then extract its name with, e.g., (save-excursion (beginning-of-line) (looking-at "#\\+\\(.+?\\):") (upcase (org-match-string-no-properties 1))) > + (elm (org-element-at-point)) > + (key (and (eq 'keyword (org-element-type elm)) > + (org-element-property :key elm)))) > + (when key KEY is nil when at an affiliated keyword. So this function is a no-op on #+CAPTION: and alike. Try it on a real caption, e.g., #+CAPTION: caption Paragraph > + (when point-at-bol-p (open-line 1) > + ;; Open-line makes sometimes ruins indention of the > + ;; previous line. > + (save-excursion (forward-line 1) > + (org-indent-line))) Don't use `open-line' at all. Insert "\n" where appropriate. Also avoid using `org-indent-line' since you can already know what the expected indentation is (i.e., by storing it earlier). > + (unless may-split (end-of-line)) > + (unless point-at-bol-p > + (when (< (point) end-of-keyword) > + (goto-char end-of-keyword)) > + (insert "\n")) > + (insert (format "#+%s: " key)) > + (org-indent-line)))) Ditto. Use stored indentation. > + ((and (eq type 'keyword) > + ;; Keyword such as LATEX, ATTR_LATEX, CAPTION, and HEADER, > + ;; LATEX_HEADER, LATEX etc. can occur multiple times. > + (let ((key (org-element-property :key element))) > + (if (member key org-element-affiliated-keywords) > + (member key org-element-multiple-keywords) > + t))) KEY cannot belong to `org-element-affiliated-keywords'. See above. Also, (or (not (member key org-element-affiliated-keywords)) (member key org-element-multiple-keywords)) Regards, -- Nicolas Goaziou