anchor.diff:  (in-package :lem)
   
  -(defun skip-chars-forward (pred &optional not-p)
  +(defun char-before-2 ()
  +  (char-before 2))
  +
  +(defun char-before-3 ()
  +  (char-before 3))
  +
  +(defmacro flet-aliases (aliases &body body)
  +  (let ((gargs (gensym "args")))
  +    `(flet ,(mapcar (lambda (alias)
  +                      (assert (= 2 (length alias)))
  +                      `(,(car alias) (&rest ,gargs)
  +                         (apply #',(cadr alias) ,gargs)))
  +              aliases)
  +       ,@body)))
  +
  +(defmacro define-dir-functions ((forward-name backward-name) parms aliases &body body)
  +  `(progn
  +    (defun ,forward-name ,parms ,@body)
  +    (flet-aliases ,aliases
  +      (defun ,backward-name ,parms ,@body))))
  +
  +(define-dir-functions (skip-chars-forward skip-chars-backward)
  +  (pred &optional not-p)
  +  ((following-char preceding-char)
  +   (next-char prev-char))
     (do ()
         ((if (funcall pred (following-char))
            not-p
  
positive.code:       (cond
         ((and
           (syntax-escape-char-p (preceding-char))
           (not (syntax-escape-char-p (two-preceding-char)))))
         ((not
           (or
            (syntax-escape-char-p c)
  
negative.code:           (syntax-word-char-p c)))
          (return t))))))
  
  (define-dir-functions (%forward-sexp %backward-sexp) ()
    ((skip-space-forward skip-space-backward)
     (syntax-open-paren-char-p syntax-closed-paren-char-p)
     (syntax-closed-paren-char-p syntax-open-paren-char-p)
     (following-char preceding-char)
     (preceding-char char-before-2)
     (char-before-2 char-before-3)
     (forward-list-1 backward-list-1)
     (skip-string-forward skip-string-backward)
     (skip-symbol-forward skip-symbol-backward))
    (skip-space-forward)
    (let ((c (following-char)))
      (when (and
             (syntax-escape-char-p (preceding-char))
             (not (syntax-escape-char-p (char-before-2))))
        (next-char 1)
        (setq c (following-char)))
      (cond
       ((syntax-open-paren-char-p c)
        (forward-list-1))
       ((syntax-closed-paren-char-p c)
        nil)
       ((syntax-string-quote-char-p c)
        (skip-string-forward))
       (t
        (skip-symbol-forward)))))
  
  (define-key *global-keymap* "M-C-f" 'forward-sexp)
  (defcommand forward-sexp (n) ("p")
    (dotimes (_ n t)
      (unless (%forward-sexp)
        (return))))
  
  (define-key *global-keymap* "M-C-b" 'backward-sexp)
  (defcommand backward-sexp (n) ("p")
    (dotimes (_ n t)
      (unless (%backward-sexp)
        (return))))
  