changeset 359:dbef6cf84f98 dev

Two or more consecutive [Tab] in column of table jump to the next column.
author HIROSE Yuuji <yuuji@gentei.org>
date Mon, 22 Dec 2014 22:33:02 +0900
parents 2c2b70f41fb3
children e17589ce8b0d
files yahtml.el yatex.el yatex.new yatexenv.el
diffstat 4 files changed, 127 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/yahtml.el	Mon Dec 22 11:27:28 2014 +0900
+++ b/yahtml.el	Mon Dec 22 22:33:02 2014 +0900
@@ -1,6 +1,6 @@
 ;;; yahtml.el --- Yet Another HTML mode -*- coding: sjis -*-
 ;;; (c) 1994-2013 by HIROSE Yuuji [yuuji(@)yatex.org]
-;;; Last modified Sun Dec 21 14:02:00 2014 on firestorm
+;;; Last modified Mon Dec 22 22:17:24 2014 on firestorm
 ;;; $Id$
 
 (defconst yahtml-revision-number "1.77"
@@ -2500,10 +2500,61 @@
 ;	(apply 'YaTeX-saved-indent-new-comment-line (if soft (list soft))))
 ;    (fset 'move-to-column yahtml-saved-move-to-column)))
 
+;;;
+;;; ---------- move forward/backward field ----------
+;;;
+(defun yahtml-element-path ()
+  "Return the element path from <body> at point as a list"
+  (let (path elm)
+    (save-excursion
+      (while (and (YaTeX-beginning-of-environment)
+		  (looking-at (concat "<\\(" yahtml-command-regexp "\\)\\>"))
+		  (not (string= (setq elm (downcase (YaTeX-match-string 1)))
+				"body")))
+	(setq path (cons elm path)
+	      elm nil))
+      (and elm (setq path (cons elm path))))))
+
+(defun yahtml-forward-field (arg)
+  "Move ARGth forward cell to table element.
+ENVINFO is a cons of target element name and its beginning point."
+  (interactive "p")
+  (let (inenv elm path sibs)
+    (cond
+     ((< arg 0) (yahtml-backward-field (- arg)))
+     ((= arg 0) nil)
+     ((and (setq path (nreverse (yahtml-element-path)))
+	   (catch 'sibling
+	     (while path
+	       (if (setq elm (car-safe
+			      (member (car path) '("td" "th" "li" "dt" "dd"))))
+		   (throw 'sibling elm))
+	       (setq path (cdr path)))))
+      (setq inenv (YaTeX-in-environment-p elm)
+	    sibs (cdr (assoc elm '(("td" . "td\\|th")
+				   ("th" . "td\\|th")
+				   ("li" . "li")
+				   ("dt" . "dt\\|dd")
+				   ("dd" . "dt\\|dd")))))
+      (goto-char (cdr inenv))
+      (while (>= (setq arg (1- arg)) 0)
+	(yahtml-goto-corresponding-begend)
+	(if (looking-at "<") (forward-list 1))
+	(skip-chars-forward "^<"))
+      (while (looking-at "\\s \\|\\(</\\)")
+	(if (match-beginning 1) (forward-list 1)
+	  (skip-chars-forward "\n\t ")))
+      (forward-list 1) ;; step into environment
+      (skip-chars-forward " \t\n")
+      (if (looking-at (concat "<\\(" sibs "\\)\\>"))
+	  (forward-list 1))
+      ))))
+
+
 ;;; 
 ;;; ---------- indentation ----------
 ;;; 
-(defun yahtml-indent-line ()
+(defun yahtml-indent-line-1 ()
   "Indent a line (faster wrapper)"
   (interactive)
   (let (indent)
@@ -2526,6 +2577,18 @@
 	  (and (bolp) (skip-chars-forward " \t")))
       (yahtml-indent-line-real))))
 
+(defun yahtml-indent-line ()
+  "Indent a line (Second level wrapper).
+See also yahtml-indent-line-1 and yahtml-indent-line-real."
+  (interactive)
+  (let ((cc (current-column)) (p (point)))
+    (yahtml-indent-line-1)
+    (and (= cc (current-column))
+	 (= p (point))
+	 (equal last-command 'yahtml-indent-line)
+	 (yahtml-forward-field 1))))
+	   
+
 (defun yahtml-this-indent ()
   (let ((envs "[uod]l\\|table\\|[ht][rhd0-6]\\|select\\|blockquote\\|center\\|menu\\|dir\\|d[td]\\|li")
 	(itemizing-envs "^\\([uod]l\\|menu\\|dir\\|li\\|d[td]\\)$")
--- a/yatex.el	Mon Dec 22 11:27:28 2014 +0900
+++ b/yatex.el	Mon Dec 22 22:33:02 2014 +0900
@@ -1,6 +1,6 @@
 ;;; yatex.el --- Yet Another tex-mode for emacs //野鳥// -*- coding: sjis -*-
 ;;; (c)1991-2014 by HIROSE Yuuji.[yuuji@yatex.org]
-;;; Last modified Sun Dec 21 23:13:59 2014 on firestorm
+;;; Last modified Mon Dec 22 22:23:52 2014 on firestorm
 ;;; $Id$
 ;;; The latest version of this software is always available at;
 ;;; http://www.yatex.org/
@@ -2677,7 +2677,7 @@
 		    (regexp-quote
 		     (YaTeX-replace-format-args
 		      YaTeX-struct-begin env "" ""))
-		    "\\)\\|\\("
+		    "\\>\\)\\|\\("
 		    (regexp-quote
 		     (YaTeX-replace-format-args
 		      YaTeX-struct-end env "" ""))
@@ -3013,6 +3013,42 @@
       (if (string= c "t") (insert (YaTeX-read-accent-char c)))
       (forward-char 1))))
 
+;; Field skip in tabular
+(defun YaTeX-forward-field (arg)
+  "Move forward to the ARGth next column field of table."
+  (interactive "p")
+  (if (< arg 0)
+      (YaTeX-backward-field (- arg))
+    (let ((ep (save-excursion (YaTeX-end-of-environment) (point)))
+	  (wc (car (YaTeX-array-what-column-internal))))
+      (while (>= (setq arg (1- arg)) 0)
+	(skip-chars-forward "^&\\\\")
+	(while (and (not (eobp))
+		    (> ep (point))
+		    (looking-at "\\&\\|\\\\")
+		    (= wc (car (YaTeX-array-what-column-internal))))
+	  (skip-chars-forward "&\\\\" ep)
+	  (skip-chars-forward "\n\t " ep))))))
+
+(defun YaTeX-backward-field (arg)
+  "Move backward to the ARGth next column field of table."
+  (interactive "p")
+  (if (< arg 0)
+      (YaTeX-forward-field (- arg))
+    (let ((bp (save-excursion
+		(YaTeX-beginning-of-environment)
+		(point-end-of-line)))
+	  (wc (car (YaTeX-array-what-column-internal))))
+      (while (>= (setq arg (1- arg)) 0)
+	(skip-chars-backward "^&\\\\" bp)
+	(while (and (not (bobp))
+		    (< bp (point))
+		    (memq (preceding-char) '(?& ?\\))
+		    (= wc (car (YaTeX-array-what-column-internal))))
+	  (skip-chars-backward "&\\\\" bp)
+	  (skip-chars-backward "\n\t " bp))
+	(if (eolp) (skip-chars-forward "^&\\\\"))))))
+
 ;; Indentation
 (defun YaTeX-current-indentation ()
   "Return the indentation of current environment."
@@ -3116,7 +3152,7 @@
      ((YaTeX-literal-p)			;verbatims
       (tab-to-tab-stop))
      ((string-match "\\(tabular\\|array\\)" inenv) ;1.73
-      (let ((n 1))
+      (let ((n 1) (cc (current-column)) (p (point)))
 	(condition-case err
 	    (save-excursion
 	      (beginning-of-line)
@@ -3128,7 +3164,12 @@
 	(YaTeX-reindent
 	 (+ (YaTeX-current-indentation)
 	    YaTeX-environment-indent
-	    (* (1- n) YaTeX-tabular-indentation)))))
+	    (* (1- n) YaTeX-tabular-indentation)))
+	(and (= cc (current-column))
+	     (= p (point))
+	     (equal last-command 'YaTeX-indent-line)
+	     ;; if NO indent action occured, move to the next column
+	     (YaTeX-forward-field 1))))
      ((and inenv (not (equal "document" inenv)))
       (funcall indent-relative))
      ((YaTeX-on-section-command-p YaTeX-sectioning-regexp)
--- a/yatex.new	Mon Dec 22 11:27:28 2014 +0900
+++ b/yatex.new	Mon Dec 22 22:33:02 2014 +0900
@@ -2,10 +2,15 @@
 	野鳥/yahtml - 各バージョンの変更点について
 
 1.78	Drag&Dropサポートを追加。
+	tabular環境内で2連続以上Tabで、1カラム進む機能を追加。
 	=== yatex ===
 	主な外部コマンド名を変数化。
 	[prefix] t d の直後のデフォルトヴューアはPDF用のものに。
 	「%#!コマンド -オプション」のときは親ファイル指定なしと判定。
+	地の段落での [prefix] t g でヴューアの forward-search を試みる。
+	[prefix] t e の環境タイプセットの結果を可能なら画像に。
+	=== yahtml ===
+	table, ul, ol, dl 内で2連続以上Tabで、1カラム進む機能を追加。
 
 1.77	last-command-char 廃止対策を追加。
 	=== yatex ===
--- a/yatexenv.el	Mon Dec 22 11:27:28 2014 +0900
+++ b/yatexenv.el	Mon Dec 22 22:33:02 2014 +0900
@@ -1,6 +1,6 @@
 ;;; yatexenv.el --- YaTeX environment-specific functions
 ;;; (c) 1994-2013 by HIROSE Yuuji.[yuuji@yatex.org]
-;;; Last modified Sun Dec 21 13:58:31 2014 on firestorm
+;;; Last modified Mon Dec 22 12:49:03 2014 on firestorm
 ;;; $Id$
 
 ;;; Code:
@@ -12,24 +12,27 @@
 (defun YaTeX-array-what-column-internal ()
   "Return the cons of matching column and its title of array environment.
 When calling from a program, make sure to be in array/tabular environment."
-  (let ((p (point)) beg eot bor (nlptn "\\\\\\\\") (andptn "[^\\]&")
+  (let ((p (point)) bot beg eot bor eoll (nlptn "\\\\\\\\") (andptn "[^\\]&")
 	(n 0) j
 	(firsterr "This line might be the first row."))
     (save-excursion
       (YaTeX-beginning-of-environment)
+      (setq eoll (save-excursion	;end of logical line
+		   (YaTeX-goto-corresponding-environment) (point)))
       (search-forward "{" p) (up-list 1)
       (search-forward "{" p) (up-list 1)
       ;;(re-search-forward andptn p)
-      (while (progn (search-forward "&" p)
+      (setq bot (point))		;beginning of tabular
+      (while (progn (search-forward "&" eoll)
 		    (equal (char-after (1- (match-beginning 0))) ?\\ )))
       (setq beg (1- (point)))		;beg is the point of the first &
-      (or (re-search-forward nlptn p t)
+      (or (re-search-forward nlptn eoll t)
 	  (error firsterr))
       (setq eot (point))		;eot is the point of the first \\
       (goto-char p)
-      (or (re-search-backward nlptn beg t)
-	  (error firsterr))
-      (setq bor (point))		;bor is the beginning of this row.
+      (setq bor (if (re-search-backward nlptn bot 1)
+		     (point)		;bor is the beginning of this row.
+		  bot))
       (while (< (1- (point)) p)
 	(if (equal (following-char) ?&)
 	    (forward-char 1)
@@ -54,8 +57,8 @@
 	(setq j (1- j)))
       (skip-chars-forward "\\s ")
       (list n
-	    (buffer-substring
-	     (point)
+	    (YaTeX-buffer-substring
+	     (progn (skip-chars-forward "\n \t") (point))
 	     (progn
 	       (re-search-forward (concat andptn "\\|" nlptn) eot)
 	       (goto-char (match-beginning 0))

yatex.org