Most programming use the concept of an expression, Jade allows major modes to define two functions which define the syntax of an expression in a particular programming language. Commands exist which use these functions to allow the manipulation of expressions as entities in a buffer, much like words.
The lambda-list of the function (i.e. its arguments) must be
(&optional count pos). count is the number
of expressions to move forwards over (default is one), pos is
the position to start from (default is the cursor position).
The function should return the position of the character following the end of count expressions starting from pos.
mode-forward-exp but works backwards from the character
after the expression (at pos) to the start of the previous count
expressions.
These functions can often be quite complex but their structure is usually the same; these two examples are taken from the Lisp mode,
(defun lisp-forward-sexp (&optional number pos)
"Return the position of the NUMBER'th next s-expression from POS."
(unless number
(setq number 1))
(while (> number 0)
;; Move pos over one expression
...
(setq number (1- number)))
pos)
(defun lisp-backward-sexp (&optional number orig-pos)
"Return the position of the NUMBER'th previous s-expression
from ORIG-POS."
(unless number
(setq number 1))
(unless orig-pos
(setq orig-pos (cursor-pos)))
(let
((pos (copy-pos orig-pos)))
(while (> number 0)
;; Move pos backwards over one expression
...
(setq number (1- number)))
pos))
Go to the first, previous, next, last section, table of contents.