Function: thai-forward-word

thai-forward-word is an interactive and byte-compiled function defined in thai-word.el.gz.

Signature

(thai-forward-word COUNT)

Documentation

Move point forward COUNT words considering Thai word boundaries.

If COUNT is negative, move point backward (- COUNT) words.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/language/thai-word.el.gz
(defun thai-forward-word (count)
  "Move point forward COUNT words considering Thai word boundaries.
If COUNT is negative, move point backward (- COUNT) words."
  (interactive "p")
  (if (> count 0)
      (while (> count 0)
	(skip-syntax-forward "^w")
	(if (looking-at "\\ct+")
	    ;; We have reached a Thai region, so we must do something
	    ;; special instead of using forward-word.
	    (let ((start (point))
		  (limit (match-end 0))
		  boundaries) ;; tail
	      ;; If thai-forward-word has been called within a Thai
	      ;; region, we must go back until the Thai region starts
	      ;; to do the contextual analysis for finding word
	      ;; breaks.
	      (while (aref (char-category-set (preceding-char)) ?t)
		(forward-char -1))
	      ;; OK, we ask for the list of word boundaries in
	      ;; reversed order.
	      (setq boundaries (nreverse (thai-find-word-boundaries limit)))
	      ;; Now we search for the next boundary after START.
	      (while (and boundaries (<= (car boundaries) start))
		(setq boundaries (cdr boundaries)))
	      ;; Adjust loop for next while loop.
	      (setq count (1- count))
	      ;; Now we skip Thai words until the BOUNDARIES list is
	      ;; empty or count-1 words have been passed.
	      (if (not boundaries)
		  (goto-char limit)
		(while (and (> count 0)
			    boundaries)
		  (setq boundaries (cdr boundaries)
			count (1- count)))
		;; If BOUNDARIES is empty, the word counter is not
		;; zero yet (remember that we have decreased COUNT by
		;; one), so we go to LIMIT.  Otherwise go to next
		;; boundary.
		(if boundaries
		    (goto-char (car boundaries))
		  (goto-char limit))))
	  ;; No Thai region.
	  (forward-word 1)
	  (setq count (1- count))))
    ;; The symmetrical action for negative values.
    (if (< count 0)
	(while (< count 0)
	  (skip-syntax-backward "^w")
	  (if (aref (char-category-set (preceding-char)) ?t)
	      (let ((start (point))
		    (limit (if (looking-at "\\ct+") (match-end 0)
			     (point)))
		    boundaries)
		(forward-char -1)
		(while (aref (char-category-set (preceding-char)) ?t)
		  (forward-char -1))
		(setq boundaries (thai-find-word-boundaries limit))
		(while (and boundaries (>= (car boundaries) start))
		  (setq boundaries (cdr boundaries)))
		(setq count (1+ count))
		(if boundaries
		    (progn
		      (while (and (< count 0) boundaries)
			(setq boundaries (cdr boundaries)
			      count (1+ count)))
		      (if boundaries
			  (goto-char (car boundaries))))))
	    (forward-word -1)
	    (setq count (1+ count)))))))