From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nicolas Goaziou Subject: Re: [PATCH] org-table-beginning/end-of-field Date: Wed, 10 Sep 2014 15:42:29 +0200 Message-ID: <87oauna8xm.fsf@nicolasgoaziou.fr> References: <87mwaaekp8.fsf@sophokles.streitblatt.de> <871trmbe92.fsf@nicolasgoaziou.fr> <87egvme27x.fsf_-_@sophokles.streitblatt.de> <87wq9e9lkn.fsf@nicolasgoaziou.fr> <87ppf59hjs.fsf@sophokles.streitblatt.de> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:48295) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XRi9n-0000LG-1a for emacs-orgmode@gnu.org; Wed, 10 Sep 2014 09:42:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XRi9e-0000D1-UB for emacs-orgmode@gnu.org; Wed, 10 Sep 2014 09:41:58 -0400 Received: from relay4-d.mail.gandi.net ([2001:4b98:c:538::196]:57097) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XRi9e-0000C5-LV for emacs-orgmode@gnu.org; Wed, 10 Sep 2014 09:41:50 -0400 In-Reply-To: <87ppf59hjs.fsf@sophokles.streitblatt.de> (Florian Beck's message of "Tue, 09 Sep 2014 13:09:27 +0200") 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: Florian Beck Cc: emacs-orgmode@gnu.org Hello, Florian Beck 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 "" in the string to avoid finding the correct position later. E.g., "| Cell:1 | Cell2 |Cell3|\n| Cell4 | | Cell5|" Regards, -- Nicolas Goaziou