emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Nicolas Goaziou <mail@nicolasgoaziou.fr>
To: Rasmus <rasmus@gmx.us>
Cc: emacs-orgmode@gnu.org
Subject: Re: [patch] extend org-meta-return to keywords
Date: Sat, 22 Nov 2014 10:52:11 +0100	[thread overview]
Message-ID: <87fvdb4l6c.fsf@nicolasgoaziou.fr> (raw)
In-Reply-To: <87wq6o3u57.fsf@gmx.us> (rasmus@gmx.us's message of "Sat, 22 Nov 2014 02:23:48 +0100")

Hello,

Rasmus <rasmus@gmx.us> 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

  reply	other threads:[~2014-11-22  9:51 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-19 14:41 [Prelim. patch] extend org-meta-return to keywords Rasmus
2014-11-22  1:23 ` [patch] " Rasmus
2014-11-22  9:52   ` Nicolas Goaziou [this message]
2014-11-22 12:19     ` Rasmus Pank Roulund
2014-11-22 19:26       ` Rasmus
2014-11-22 21:57         ` Thierry Banel
2014-11-22 23:20         ` Nicolas Goaziou
2014-11-23 11:08           ` Thierry Banel
2014-11-23 16:54             ` Nicolas Goaziou
2014-11-23 17:15               ` Rasmus
2014-11-23 17:54                 ` Nicolas Goaziou
2014-11-23 18:11                   ` Rasmus
2014-11-23 21:13                     ` Nicolas Goaziou
2014-11-23 21:54                       ` Rasmus
2014-11-25  9:00                         ` Nicolas Goaziou
2014-11-25 10:12                           ` M-RET vs C-RET Sebastien Vauban
2014-11-25 11:09                             ` Nicolas Goaziou
2014-11-25 11:16                             ` Rasmus
2014-11-26 23:50                               ` Nicolas Goaziou
2014-11-27  0:55                                 ` Rasmus
2014-11-27  9:19                                   ` Andreas Leha
2014-11-23 17:00           ` [patch] extend org-meta-return to keywords Rasmus
2014-11-23 17:46             ` Nicolas Goaziou
2014-11-22 13:53 ` [Prelim. patch] " Thierry Banel
2014-11-22 14:31   ` Rasmus
2014-11-22 17:09     ` Thierry Banel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87fvdb4l6c.fsf@nicolasgoaziou.fr \
    --to=mail@nicolasgoaziou.fr \
    --cc=emacs-orgmode@gnu.org \
    --cc=rasmus@gmx.us \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).