Sfoglia il codice sorgente

Tables: Make M-a and M-e go to beginning and end of table field

This commit overloads the sentence commands M-a and M-e so that they
will work on table fields in tables.
Carsten Dominik 16 anni fa
parent
commit
c7718a1999
6 ha cambiato i file con 93 aggiunte e 11 eliminazioni
  1. 8 0
      doc/ChangeLog
  2. 7 0
      doc/org.texi
  3. 9 9
      doc/orgcard.tex
  4. 9 0
      lisp/ChangeLog
  5. 39 2
      lisp/org-table.el
  6. 21 0
      lisp/org.el

+ 8 - 0
doc/ChangeLog

@@ -1,3 +1,11 @@
+2009-03-21  Carsten Dominik  <carsten.dominik@gmail.com>
+
+	* orgcard.tex:  Document M-e and M-a navigate
+	inside table field.  Fix a number of typos.
+
+	* org.texi (Built-in table editor): Document M-e and M-a navigate
+	inside table field.
+
 2009-03-19  Carsten Dominik  <carsten.dominik@gmail.com>
 
 	* org.texi (Stuck projects): Docment that projects identified as

+ 7 - 0
doc/org.texi

@@ -1656,6 +1656,13 @@ Re-align, move to previous field.
 Re-align the table and move down to next row.  Creates a new row if
 necessary.  At the beginning or end of a line, @key{RET} still does
 NEWLINE, so it can be used to split a table.
+@c
+@kindex M-a
+@item M-a
+Move to beginning of the current table field, or on to the previous field.
+@kindex M-e
+@item M-e
+Move to end of the current table field, or on to the next field.
 
 @tsubheading{Column and row editing}
 @kindex M-@key{left}

+ 9 - 9
doc/orgcard.tex

@@ -363,6 +363,7 @@ Outside of tables, the same keys may have other functionality.
 \key{re-align the table, move to next field}{TAB}
 \key{move to previous field}{S-TAB}
 \key{re-align the table, move to next row}{RET}
+\key{move to beginning/end of field}{M-a/e}
 
 {\bf Row and column editing}
 
@@ -418,8 +419,7 @@ formula, \kbd{:=} a field formula.
 \key{iterate table to stability}{C-u C-u C-c *}
 \key{rotate calculation mark through \# * ! \^ \_ \$}{C-\#}
 \key{show line, column, formula reference}{C-c ?}
-\key{toggle coordinate grid}{C-c \}}
-\key{toggle formula debugger}{C-c \{}
+\key{toggle grid / debugger}{C-c \}/\{}
 
 \newcolumn
 {\it Formula Editor}
@@ -507,7 +507,7 @@ In-buffer completion completes TODO keywords at headline start, TeX
 macros after ``{\tt \\}'', option keywords after ``{\tt \#-}'', TAGS
 after  ``{\tt :}'', and dictionary words elsewhere.
 
-\key{Complete word at point}{M-TAB}
+\key{complete word at point}{M-TAB}
 
 
 \newcolumn
@@ -569,7 +569,7 @@ after  ``{\tt :}'', and dictionary words elsewhere.
 
 \key{prompt for date and insert timestamp}{C-c .}
 \key{like \kbd{C-c} . but insert date and time format}{C-u C-c .}
-\key{Like \kbd{C-c .} but make stamp inactive}{C-c !} % FIXME
+\key{like \kbd{C-c .} but make stamp inactive}{C-c !} % FIXME
 \key{insert DEADLINE timestamp}{C-c C-d}
 \key{insert SCHEDULED timestamp}{C-c C-s}
 \key{create sparse tree with all deadlines due}{C-c / d}
@@ -579,13 +579,13 @@ after  ``{\tt :}'', and dictionary words elsewhere.
 \key{access the calendar for the current date}{C-c >}
 \key{insert timestamp matching date in calendar}{C-c <}
 \key{access agenda for current date}{C-c C-o}
-\key{Select date while prompted}{mouse-1/RET}
+\key{select date while prompted}{mouse-1/RET}
 %\key{... select date in calendar}{mouse-1/RET}
 %\key{... scroll calendar back/forward one month}{< / >}
 %\key{... forward/backward one day}{S-LEFT/RIGHT}
 %\key{... forward/backward one week}{S-UP/DOWN}
 %\key{... forward/backward one month}{M-S-LEFT/RIGT}
-\key{Toggle custom format display for dates/times}{C-c C-x C-t}
+\key{toggle custom format display for dates/times}{C-c C-x C-t}
 
 \newcolumn
 
@@ -666,7 +666,7 @@ after  ``{\tt :}'', and dictionary words elsewhere.
 
 {\bf Misc}
 
-\key{Open link in current line}{C-c C-o}
+\key{open link in current line}{C-c C-o}
 
 {\bf Calendar commands}
 
@@ -692,8 +692,8 @@ Include Emacs diary entries into Org-mode agenda with:
 \section{LaTeX and cdlatex-mode}
 
 \key{preview LaTeX fragment}{C-c C-x C-l}
-\key{Expand abbreviation (cdlatex-mode)}{TAB}
-\key{Insert/modify math symbol (cdlatex-mode)}{` / '}
+\key{expand abbreviation (cdlatex-mode)}{TAB}
+\key{insert/modify math symbol (cdlatex-mode)}{` / '}
 
 \section{Exporting and Publishing}
 

+ 9 - 0
lisp/ChangeLog

@@ -1,5 +1,14 @@
 2009-03-21  Carsten Dominik  <carsten.dominik@gmail.com>
 
+	* org-table.el (org-table-beginning-of-field)
+	(org-table-end-of-field): New commands
+	(org-table-previous-field, org-table-beginning-of-field): Better
+	error messages.
+	(orgtbl-setup): Include `M-a' and `M-e'.
+
+	* org.el (org-backward-sentence, org-forward-sentence): New
+	commands.
+
 	* org-colview.el (org-colview-initial-truncate-line-value): New
 	variable.
 	(org-columns-remove-overlays): Restore the value of `truncate-lines'.

+ 39 - 2
lisp/org-table.el

@@ -827,13 +827,48 @@ Before doing so, re-align the table if necessary."
       (org-table-align))
   (if (org-at-table-hline-p)
       (end-of-line 1))
-  (re-search-backward "|" (org-table-begin))
-  (re-search-backward "|" (org-table-begin))
+  (condition-case nil
+      (progn
+	(re-search-backward "|" (org-table-begin))
+	(re-search-backward "|" (org-table-begin)))
+    (error (error "Cannot move to previous table field")))
   (while (looking-at "|\\(-\\|[ \t]*$\\)")
     (re-search-backward "|" (org-table-begin)))
   (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")
+  (let ((pos (point)))
+    (while (> n 1)
+      (setq n (1- n))
+      (org-table-previous-field))
+    (if (not (re-search-backward "|" (point-at-bol 0) t))
+	(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))))
+
+(defun org-table-end-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.
+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))))
+
 (defun org-table-next-row ()
   "Go to the next row (same column) in the current table.
 Before doing so, re-align the table if necessary."
@@ -3387,6 +3422,8 @@ to execute outside of tables."
 	  '("\C-c`"		 org-table-edit-field)
 	  '("\C-c*"		 org-table-recalculate)
 	  '("\C-c^"		 org-table-sort-lines)
+	  '("\M-a"		 org-table-beginning-of-field)
+	  '("\M-e"		 org-table-end-of-field)
 	  '([(control ?#)]       org-table-rotate-recalc-marks)))
 	elt key fun cmd)
     (while (setq elt (pop bindings))

+ 21 - 0
lisp/org.el

@@ -15438,6 +15438,27 @@ beyond the end of the headline."
 (define-key org-mode-map "\C-a" 'org-beginning-of-line)
 (define-key org-mode-map "\C-e" 'org-end-of-line)
 
+(defun org-backward-sentence (&optional arg)
+  "Go to beginning of sentence, or beginning of table field.
+This will call `backward-sentence' or `org-table-beginning-of-field',
+depending on context."
+  (interactive "P")
+  (cond
+   ((org-at-table-p) (call-interactively 'org-table-beginning-of-field))
+   (t (call-interactively 'backward-sentence))))
+
+(defun org-forward-sentence (&optional arg)
+  "Go to end of sentence, or end of table field.
+This will call `forward-sentence' or `org-table-end-of-field',
+depending on context."
+  (interactive "P")
+  (cond
+   ((org-at-table-p) (call-interactively 'org-table-end-of-field))
+   (t (call-interactively 'forward-sentence))))
+
+(define-key org-mode-map "\M-a" 'org-backward-sentence)
+(define-key org-mode-map "\M-e" 'org-forward-sentence)
+
 (defun org-kill-line (&optional arg)
   "Kill line, to tags or end of line."
   (interactive "P")