summaryrefslogtreecommitdiff
path: root/src/elisp
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adamc@hcoop.net>2008-10-16 16:00:58 -0400
committerGravatar Adam Chlipala <adamc@hcoop.net>2008-10-16 16:00:58 -0400
commit22236f78bf5acb81d9c404ab71be9aa3d9e3bf26 (patch)
tree0841a60524db4ea17a419856effca6eb75d0e7c4 /src/elisp
parent5a71851c8495e85a43227db438b15a3060d724d9 (diff)
Crud auto-indented correctly
Diffstat (limited to 'src/elisp')
-rw-r--r--src/elisp/urweb-mode.el2
-rw-r--r--src/elisp/urweb-move.el111
2 files changed, 66 insertions, 47 deletions
diff --git a/src/elisp/urweb-mode.el b/src/elisp/urweb-mode.el
index 1938eeba..9bfa0c96 100644
--- a/src/elisp/urweb-mode.el
+++ b/src/elisp/urweb-mode.el
@@ -676,7 +676,7 @@ it is not on its own line but is the last element on that line."
"Find the indentation for the SYM we're `looking-at'.
If indentation is delegated, point will move to the start of the parent.
Optional argument STYLE is currently ignored."
- (assert (equal sym (save-excursion (urweb-forward-sym))))
+;;(assert (equal sym (save-excursion (urweb-forward-sym))))
(save-excursion
(let ((delegate (and (not (equal sym "end")) (assoc sym urweb-close-paren)))
(head-sym sym))
diff --git a/src/elisp/urweb-move.el b/src/elisp/urweb-move.el
index da74bcee..5e4e6824 100644
--- a/src/elisp/urweb-move.el
+++ b/src/elisp/urweb-move.el
@@ -182,6 +182,7 @@ This assumes that we are `looking-at' the OP."
(or (/= 0 (skip-syntax-forward "'w_"))
(/= 0 (skip-syntax-forward ".'"))))
(defun urweb-forward-sym ()
+ (interactive)
(let ((sym (urweb-move-read (urweb-forward-sym-1))))
(cond
((equal "op" sym)
@@ -206,22 +207,33 @@ This assumes that we are `looking-at' the OP."
(or (/= 0 (skip-syntax-backward ".'"))
(/= 0 (skip-syntax-backward "'w_"))))
(defun urweb-backward-sym ()
+ (interactive)
(let ((sym (urweb-move-read (urweb-backward-sym-1))))
- (when sym
- ;; FIXME: what should we do if `sym' = "op" ?
- (let ((point (point)))
- (urweb-backward-spaces)
- (if (equal "op" (urweb-move-read (urweb-backward-sym-1)))
- (concat "op " sym)
- (goto-char point)
- (cond
- ((string= sym "=") (if (urweb-poly-equal-p) "=" "d="))
- ((string= sym "of") (if (urweb-nested-of-p) "of" "=of"))
- ;; ((string= sym "datatype")
- ;; (save-excursion (urweb-backward-spaces)
- ;; (if (eq (preceding-char) ?=) "=datatype" sym)))
- (t sym)))))))
-
+ (let ((result
+ (when sym
+ ;; FIXME: what should we do if `sym' = "op" ?
+ (let ((point (point)))
+ (urweb-backward-spaces)
+ (if (equal "op" (urweb-move-read (urweb-backward-sym-1)))
+ (concat "op " sym)
+ (goto-char point)
+ (cond
+ ((string= sym "=") (if (urweb-poly-equal-p) "=" "d="))
+ ((string= sym "of") (if (urweb-nested-of-p) "of" "=of"))
+ ;; ((string= sym "datatype")
+ ;; (save-excursion (urweb-backward-spaces)
+ ;; (if (eq (preceding-char) ?=) "=datatype" sym)))
+ (t sym)))))))
+ (if (looking-at ">")
+ (substring result 1 nil)
+ result))))
+;; (if (save-excursion (backward-char 5) (looking-at "</xml>"))
+;; (progn
+;; (backward-char 5)
+;; (urweb-tag-matcher)
+;; (backward-char)
+;; (urweb-backward-sym))
+;; result))))
(defun urweb-tag-matcher ()
"Seek back to a matching opener tag"
@@ -243,35 +255,42 @@ This assumes that we are `looking-at' the OP."
"Move one sexp backward if possible, or one char else.
Returns t if the move indeed moved through one sexp and nil if not.
PREC is the precedence currently looked for."
- (let ((parse-sexp-lookup-properties t)
- (parse-sexp-ignore-comments t))
- (urweb-backward-spaces)
- (let* ((op (urweb-backward-sym))
- (op-prec (urweb-op-prec op 'back))
- match)
- (cond
- ((not op)
- (let ((point (point)))
- (ignore-errors (let ((forward-sexp-function nil)) (backward-sexp 1)))
- (if (/= point (point)) t (ignore-errors (backward-char 1)) nil)))
- ;; stop as soon as precedence is smaller than `prec'
- ((and prec op-prec (>= prec op-prec)) nil)
- ;; special rules for nested constructs like if..then..else
- ((and (or (not prec) (and prec op-prec))
- (setq match (second (assoc op urweb-close-paren))))
- (urweb-find-match-backward (concat "\\<" op "\\>") match))
- ;; don't back over open-parens
- ((assoc op urweb-open-paren) nil)
- ;; infix ops precedence
- ((and prec op-prec) (< prec op-prec))
- ;; [ prec = nil ] a new operator, let's skip the sexps until the next
- (op-prec (while (urweb-move-if (urweb-backward-sexp op-prec))) t)
- ;; special symbols indicating we're getting out of a nesting level
- ((string-match urweb-sexp-head-symbols-re op) nil)
- ;; if the op was not alphanum, then we still have to do the backward-sexp
- ;; this reproduces the usual backward-sexp, but it might be bogus
- ;; in this case since !@$% is a perfectly fine symbol
- (t t))))) ;(or (string-match "\\sw" op) (urweb-backward-sexp prec))
+ (let ((result (let ((parse-sexp-lookup-properties t)
+ (parse-sexp-ignore-comments t))
+ (urweb-backward-spaces)
+ (let* ((op (urweb-backward-sym))
+ (op-prec (urweb-op-prec op 'back))
+ match)
+ (cond
+ ((not op)
+ (let ((point (point)))
+ (ignore-errors (let ((forward-sexp-function nil)) (backward-sexp 1)))
+ (if (/= point (point)) t (ignore-errors (backward-char 1)) nil)))
+ ;; stop as soon as precedence is smaller than `prec'
+ ((and prec op-prec (>= prec op-prec)) nil)
+ ;; special rules for nested constructs like if..then..else
+ ((and (or (not prec) (and prec op-prec))
+ (setq match (second (assoc op urweb-close-paren))))
+ (urweb-find-match-backward (concat "\\<" op "\\>") match))
+ ;; don't back over open-parens
+ ((assoc op urweb-open-paren) nil)
+ ;; infix ops precedence
+ ((and prec op-prec) (< prec op-prec))
+ ;; [ prec = nil ] a new operator, let's skip the sexps until the next
+ (op-prec (while (urweb-move-if (urweb-backward-sexp op-prec))) t)
+ ;; special symbols indicating we're getting out of a nesting level
+ ((string-match urweb-sexp-head-symbols-re op) nil)
+ ;; if the op was not alphanum, then we still have to do the backward-sexp
+ ;; this reproduces the usual backward-sexp, but it might be bogus
+ ;; in this case since !@$% is a perfectly fine symbol
+ (t t))))))
+ (if (save-excursion (backward-char 5) (looking-at "</xml>"))
+ (progn
+ (backward-char 5)
+ (urweb-tag-matcher)
+ (backward-char)
+ (urweb-backward-sexp prec))
+ result)))
(defun urweb-forward-sexp (prec)
"Moves one sexp forward if possible, or one char else.
@@ -340,8 +359,8 @@ Returns T if the move indeed moved through one sexp and NIL if not."
;;(defun urweb-forward-thing ()
;; (if (= ?w (char-syntax (char-after))) (forward-word 1) (forward-char 1)))
-(defun urweb-backward-arg () (urweb-backward-sexp 1000))
-(defun urweb-forward-arg () (urweb-forward-sexp 1000))
+(defun urweb-backward-arg () (interactive) (urweb-backward-sexp 1000))
+(defun urweb-forward-arg () (interactive) (urweb-forward-sexp 1000))
(provide 'urweb-move)