emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] org-table-mark-field


From: Kaushal Modi
Subject: Re: [O] org-table-mark-field
Date: Fri, 13 May 2016 23:38:40 +0000

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


reply via email to

[Prev in Thread] Current Thread [Next in Thread]