From mboxrd@z Thu Jan 1 00:00:00 1970 From: Kaushal Modi Subject: Re: org-table-mark-field Date: Fri, 13 May 2016 23:38:40 +0000 Message-ID: References: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=94eb2c0441f4ec2f430532c1c66d Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:52643) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b1MfV-0001HL-S4 for emacs-orgmode@gnu.org; Fri, 13 May 2016 19:38:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b1MfT-00026M-N5 for emacs-orgmode@gnu.org; Fri, 13 May 2016 19:38:52 -0400 Received: from mail-oi0-x22b.google.com ([2607:f8b0:4003:c06::22b]:35857) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b1MfT-00026H-H2 for emacs-orgmode@gnu.org; Fri, 13 May 2016 19:38:51 -0400 Received: by mail-oi0-x22b.google.com with SMTP id x201so194360374oif.3 for ; Fri, 13 May 2016 16:38:51 -0700 (PDT) In-Reply-To: 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" To: emacs-org list --94eb2c0441f4ec2f430532c1c66d Content-Type: text/plain; charset=UTF-8 Here's a minor update with a bug fix (to handle the case when the point is at the end of a table field initially): (defun org-table-mark-field (n) "Mark the current table field. If N is negative, select (- N) fields to the left of the current field, including the current field. If N >= 2, select (1- N) fields to the right of the current field, including the current field. If N is 0 or 1 (default), only the current field is selected." (interactive "p") (let ((bol-point (save-excursion (beginning-of-line) (point))) (bof-arg 1) (eof-arg 1) (p (point)) bof-p eof-p) ;; Check if the point is already at the beginning of the current field. (when (looking-back "|\\s-?" bol-point) (setq bof-p t)) ;; Check if the point is already at the end of the current field. (when (looking-at "\\s-?|") (setq eof-p t)) ;; When selecting current field plus fields to the right (when (>= n 2) (setq eof-arg n)) ;; When selecting current field plus fields to the left (when (<= n -1) (setq bof-arg (- n))) (org-table-beginning-of-field bof-arg) (when bof-p (org-table-next-field)) (set-mark-command nil) (goto-char p) (when eof-p (org-table-beginning-of-field 1)) (org-table-end-of-field eof-arg) (exchange-point-and-mark))) -- -- Kaushal Modi --94eb2c0441f4ec2f430532c1c66d Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Here's a minor update with a bug fix (to handle the ca= se when the point is at the end of a table field initially):

=
(defun org-table-mark-field (n)
=C2=A0 "Mark the c= urrent table field.

If N is negative, select (- N)= fields to the left of the current field,
including the current f= ield.
If N >=3D 2, select (1- N) fields to the right of the cu= rrent field,
including the current field.
If N is 0 or = 1 (default), only the current field is selected."
=C2=A0 (in= teractive "p")
=C2=A0 (let ((bol-point (save-excursion<= /div>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0(beginning-of-line)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(point)))
=C2=A0 =C2= =A0 =C2=A0 =C2=A0 (bof-arg 1)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (eof-ar= g 1)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (p (point))
=C2=A0 =C2= =A0 =C2=A0 =C2=A0 bof-p eof-p)

=C2=A0 =C2=A0 ;; Ch= eck if the point is already at the beginning of the current field.
=C2=A0 =C2=A0 (when (looking-back "|\\s-?" bol-point)
=C2=A0 =C2=A0 =C2=A0 (setq bof-p t))
=C2=A0 =C2=A0 ;; Check if t= he point is already at the end of the current field.
=C2=A0 =C2= =A0 (when (looking-at "\\s-?|")
=C2=A0 =C2=A0 =C2=A0 (s= etq eof-p t))

=C2=A0 =C2=A0 ;; When selecting curr= ent field plus fields to the right
=C2=A0 =C2=A0 (when (>=3D n= 2)
=C2=A0 =C2=A0 =C2=A0 (setq eof-arg n))
=C2=A0 =C2= =A0 ;; When selecting current field plus fields to the left
=C2= =A0 =C2=A0 (when (<=3D n -1)
=C2=A0 =C2=A0 =C2=A0 (setq bof-ar= g (- n)))

=C2=A0 =C2=A0 (org-table-beginning-of-fi= eld bof-arg)
=C2=A0 =C2=A0 (when bof-p
=C2=A0 =C2=A0 = =C2=A0 (org-table-next-field))
=C2=A0 =C2=A0 (set-mark-command ni= l)
=C2=A0 =C2=A0 (goto-char p)
=C2=A0 =C2=A0 (when eof-= p
=C2=A0 =C2=A0 =C2=A0 (org-table-beginning-of-field 1))
=C2=A0 =C2=A0 (org-table-end-of-field eof-arg)
=C2=A0 =C2=A0 (e= xchange-point-and-mark)))
--
--
Kaushal Modi

--94eb2c0441f4ec2f430532c1c66d--