Go to the first, previous, next, last section, table of contents.


Mode-Specific Expressions

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.

Variable: mode-forward-exp
This buffer-local variable contains a function which calculates the position of the end of an expression in that language.

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.

Variable: mode-backward-exp
Similar to 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.