emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Nicolas Goaziou <mail@nicolasgoaziou.fr>
To: Florian Beck <fb@miszellen.de>
Cc: emacs-orgmode@gnu.org
Subject: Re: [PATCH] org-table-beginning/end-of-field
Date: Wed, 10 Sep 2014 15:42:29 +0200	[thread overview]
Message-ID: <87oauna8xm.fsf@nicolasgoaziou.fr> (raw)
In-Reply-To: <87ppf59hjs.fsf@sophokles.streitblatt.de> (Florian Beck's message of "Tue, 09 Sep 2014 13:09:27 +0200")

Hello,

Florian Beck <fb@miszellen.de> writes:

> I hope the new version is an improvement.

Thanks for the update.

> But as long as I have a table cell ancestor, I should be fine. Am
> I missing something?

Yes. There are some place where `org-element-context' will return
a `table-row' or `table' object even though you can technically move to
the next (or maybe previous) cell. You may want to try
`org-element-context' in the following places, where X denotes cursor:

  | a | b |
  X c | d |

  X a | b |
  | c | d |

X | a | b |
  | c | d |

  | a | b | X
  | c | d |

  | a | b |
X | c | d |

> I added a function `org-element-get' to help with that. What do you
> think? (If `cl-labels' is a no-go, we could split out a helper
> function.)

I don't think `org-element-get' should go into "org-element.el" in its
current implementation. It is tied to a position, which implies to take
care of boring stuff like buffer narrowing. It doesn't allow to re-use
an already computed element or object either, which is sub-optimal.

However, the feature is useful enough that some function could provide
something similar. Maybe the following one:

  (defun org-element-parent (blob &optional types genealogy)
    "Return BLOB's parent, or nil.

  BLOB is an object or element.

  When optional argument TYPES is a list of symbols, return the
  first element or object between BLOB and its ancestors whose type
  belongs to that list.

  When optional argument GENEALOGY is non-nil, return a list of all
  ancestors, from closest to farthest.

  When BLOB is obtained through `org-element-context' or
  `org-element-at-point', only ancestors from its section can be
  found. There is no such limitation when BLOB belongs to a full
  parse tree."
    (if (not (or types genealogy)) (org-element-property :parent blob)
      (let ((up blob) ancestors)
        (while (and up (not (memq (org-element-type up) types)))
          (when genealogy (push up ancestors))
          (setq up (org-element-property :parent up)))
        (if genealogy (nreverse ancestors) up))))

Its name is a bit confusing since it can return BLOB under some optional
argument combination (i.e., if BLOB's type belongs to TYPES). However,
it covers most, if not all, needs about ancestors. WDYT?

> I added a couple of tests. Not really succinct, though.

Thanks.

> Also, I modified `org-element-table-cell-parser', because otherwise
> :contents-begin and :contents-end point to the end of the cell. Not sure
> if this breaks anything.

Usually, when an object has no contents (e.g., a link without
description), both :contents-begin and :contents-end are nil. It is less
confusing than providing an arbitrary buffer position.

> +    (let ((cell (or (org-element-get 'table-cell)
> +		    ;; Fuzzy matching when on a table border:
> +		    (org-element-get 'table-cell (1+ (point)))
> +		    (org-element-get 'table-cell (1- (point))))))

We need to be more careful here, as explained above.

> +  (should
> +   (org-test-with-temp-text
> +    "| Cell:1   | Cell2 |Cell3|\n| Cell4 |     | Cell5|"
> +    (search-forward ":")

Minor note: you can insert "<point>" in the string to avoid finding the
correct position later. E.g.,

  "| Cell:<point>1   | Cell2 |Cell3|\n| Cell4 |     | Cell5|"


Regards,

-- 
Nicolas Goaziou

  reply	other threads:[~2014-09-10 13:42 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-08  5:37 [BUG] org-table-beginning/end-of-field Florian Beck
2014-09-08 10:25 ` Nicolas Goaziou
2014-09-08 12:17   ` [PATCH] org-table-beginning/end-of-field Florian Beck
2014-09-08 15:30     ` Nicolas Goaziou
2014-09-09 11:09       ` Florian Beck
2014-09-10 13:42         ` Nicolas Goaziou [this message]
2014-09-10 17:08           ` Florian Beck
2014-09-12  8:29             ` Nicolas Goaziou

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=87oauna8xm.fsf@nicolasgoaziou.fr \
    --to=mail@nicolasgoaziou.fr \
    --cc=emacs-orgmode@gnu.org \
    --cc=fb@miszellen.de \
    /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).