From: Florian Beck <fb@miszellen.de>
To: emacs-orgmode@gnu.org
Subject: Re: [PATCH] org-table-beginning/end-of-field
Date: Mon, 08 Sep 2014 14:17:06 +0200 [thread overview]
Message-ID: <87egvme27x.fsf_-_@sophokles.streitblatt.de> (raw)
In-Reply-To: 871trmbe92.fsf@nicolasgoaziou.fr
[-- Attachment #1: Type: text/plain, Size: 194 bytes --]
Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:
> Thanks for the patch. Though, wouldn't it make more sense to properly
> handle a missing argument instead?
How about this?
--
Florian Beck
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org-table-fix-arguments-of-org-table-beginning-of-fi.patch --]
[-- Type: text/x-diff, Size: 3011 bytes --]
From 4fb2bbff2238d15ae7c896e0eb268b74ea4e56dc Mon Sep 17 00:00:00 2001
From: Florian Beck <fb@miszellen.de>
Date: Mon, 8 Sep 2014 14:08:56 +0200
Subject: [PATCH] org-table: fix arguments of `org-table-beginning-of-field'
and `org-table-end-of-field'. Also fix docstring and cleanup code.
* lisp/org-table.el (org-table--border-of-field): new function
(org-table-beginning-of-field): call it
(org-table-end-of-field): call it
---
lisp/org-table.el | 45 +++++++++++++++++++++------------------------
1 file changed, 21 insertions(+), 24 deletions(-)
diff --git a/lisp/org-table.el b/lisp/org-table.el
index 547f933..31fda57 100644
--- a/lisp/org-table.el
+++ b/lisp/org-table.el
@@ -1061,37 +1061,34 @@ Before doing so, re-align the table if necessary."
(if (looking-at "| ?")
(goto-char (match-end 0))))
-(defun org-table-beginning-of-field (&optional n)
- "Move to the end of the current table field.
-If already at or after the end, move to the end of the next table field.
-With numeric argument N, move N-1 fields forward first."
- (interactive "p")
+(defun org-table--border-of-field (n move-fn element cmp-fn)
(let ((pos (point)))
(while (> n 1)
(setq n (1- n))
- (org-table-previous-field))
- (if (not (re-search-backward "|" (point-at-bol 0) t))
- (user-error "No more table fields before the current")
- (goto-char (match-end 0))
- (and (looking-at " ") (forward-char 1)))
- (if (>= (point) pos) (org-table-beginning-of-field 2))))
+ (funcall move-fn))
+ (goto-char (org-element-property element (org-element-context)))
+ (if (and (> n 0) (funcall cmp-fn (point) pos))
+ (org-table--border-of-field 2 move-fn element cmp-fn))))
-(defun org-table-end-of-field (&optional n)
+(defun org-table-beginning-of-field (&optional n)
"Move to the beginning of the current table field.
-If already at or before the beginning, move to the beginning of the
-previous field.
+If already at or before the beginning and N is not 0, move to the
+beginning of the previous table field.
With numeric argument N, move N-1 fields backward first."
(interactive "p")
- (let ((pos (point)))
- (while (> n 1)
- (setq n (1- n))
- (org-table-next-field))
- (when (re-search-forward "|" (point-at-eol 1) t)
- (backward-char 1)
- (skip-chars-backward " ")
- (if (and (equal (char-before (point)) ?|) (looking-at " "))
- (forward-char 1)))
- (if (<= (point) pos) (org-table-end-of-field 2))))
+ (org-table--border-of-field (or n 1)
+ 'org-table-previous-field
+ :contents-begin '>=))
+
+(defun org-table-end-of-field (&optional n)
+ "Move to the end of the current table field.
+If already at or after the end and N is not 0, move to the end of the
+next field.
+With numeric argument N, move N-1 fields forward first."
+ (interactive "p")
+ (org-table--border-of-field (or n 1)
+ 'org-table-next-field
+ :contents-end '<=))
;;;###autoload
(defun org-table-next-row ()
--
1.9.1
next prev parent reply other threads:[~2014-09-08 12:17 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 ` Florian Beck [this message]
2014-09-08 15:30 ` [PATCH] org-table-beginning/end-of-field Nicolas Goaziou
2014-09-09 11:09 ` Florian Beck
2014-09-10 13:42 ` Nicolas Goaziou
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=87egvme27x.fsf_-_@sophokles.streitblatt.de \
--to=fb@miszellen.de \
--cc=emacs-orgmode@gnu.org \
/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).