From mboxrd@z Thu Jan 1 00:00:00 1970 From: Kaushal Modi Subject: org-table-mark-field Date: Fri, 13 May 2016 23:15:45 +0000 Message-ID: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=001a113cf2f6e7beff0532c1745f Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:50837) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b1MJK-0001To-FN for emacs-orgmode@gnu.org; Fri, 13 May 2016 19:15:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b1MJI-0006yz-0A for emacs-orgmode@gnu.org; Fri, 13 May 2016 19:15:57 -0400 Received: from mail-oi0-x232.google.com ([2607:f8b0:4003:c06::232]:36798) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b1MJH-0006yp-Oq for emacs-orgmode@gnu.org; Fri, 13 May 2016 19:15:55 -0400 Received: by mail-oi0-x232.google.com with SMTP id x201so193801147oif.3 for ; Fri, 13 May 2016 16:15:55 -0700 (PDT) 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 --001a113cf2f6e7beff0532c1745f Content-Type: text/plain; charset=UTF-8 Hi all, At times I need to copy content of the current field or few fields around the field in the current row. I realized that we do not have a function that selects fields. We have function that blanks a field but not one that selects. Please point me to the right function if I missed it. But as I couldn't find anything like that, I came up with the below. Please advise if there's a better way to do the same or if I this could be added to org. ===== (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) ;; Check if the point is already at the beginning of the current field. (when (looking-back "|\\s-*" bol-point) (setq bof-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) (org-table-end-of-field eof-arg) (exchange-point-and-mark))) ==== Using bind-key (use-package), I bind the above to S-SPC only as long as the point is in a table. More on context-aware key bindings[1]. ===== (bind-keys :map org-mode-map :filter (org-at-table-p) ("S-SPC" . org-table-mark-field)) ===== [1]: http://endlessparentheses.com/define-context-aware-keys-in-emacs.html -- -- Kaushal Modi --001a113cf2f6e7beff0532c1745f Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Hi all,

At times I need to copy content= of the current field or few fields around the field in the current row. I = realized that we do not have a function that selects fields. We have functi= on that blanks a field but not one that selects. Please point me to the rig= ht function if I missed it.

But as I couldn't = find anything like that, I came up with the below. Please advise if there&#= 39;s a better way to do the same or if I this could be added to org.
<= div>
=3D=3D=3D=3D=3D
(defun org-table-mark-fie= ld (n)
=C2=A0 "Mark the current table field.

<= /div>
If N is negative, select (- N) fields to the left of the current = field,
including the current field.
If N >=3D 2, sel= ect (1- N) fields to the right of the current field,
including th= e current field.
If N is 0 or 1 (default), only the current field= is selected."
=C2=A0 (interactive "p")
= =C2=A0 (let ((bol-point (save-excursion
=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-arg 1)
=C2=A0 =C2=A0 =C2=A0= =C2=A0 (p (point))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 bof-p)
=
=C2=A0 =C2=A0 ;; Check if the point is already at the beginn= ing 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 ;; When selecting current field plus fi= elds 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 selecti= ng current field plus fields to the left
=C2=A0 =C2=A0 (when (<= ;=3D n -1)
=C2=A0 =C2=A0 =C2=A0 (setq bof-arg (- n)))
<= br>
=C2=A0 =C2=A0 (org-table-beginning-of-field 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 nil)
=C2=A0 =C2= =A0 (goto-char p)
=C2=A0 =C2=A0 (org-table-end-of-field eof-arg)<= /div>
=C2=A0 =C2=A0 (exchange-point-and-mark)))
=3D=3D=3D=3D<= /div>

Using bind-key (use-package), I bind the above to = S-SPC only as long as the point is in a table. More on context-aware key bi= ndings[1].

=3D=3D=3D=3D=3D
(bind-keys
=C2=A0:map org-mode-map
=C2=A0:filter (org-at-table-p)
=C2=A0 ("S-SPC" . org-table-mark-field))
= =3D=3D=3D=3D=3D

--

--
Kaushal Modi

--001a113cf2f6e7beff0532c1745f--