Commit 531cbff1 authored by Richard M. Stallman's avatar Richard M. Stallman
Browse files

(indent-sexp): If calculate-lisp-indent returns nil,

don't change the line's indentation.
(lisp-indent-line): Likewise.
(lisp-comment-indent): Likewise.
(calculate-lisp-indent): Return nil if line starts inside a string.
parent e7c8378c
...@@ -338,7 +338,7 @@ With argument, insert value in current buffer after the defun." ...@@ -338,7 +338,7 @@ With argument, insert value in current buffer after the defun."
(if (looking-at "\\s<\\s<\\s<") (if (looking-at "\\s<\\s<\\s<")
(current-column) (current-column)
(if (looking-at "\\s<\\s<") (if (looking-at "\\s<\\s<")
(let ((tem (calculate-lisp-indent))) (let ((tem (or (calculate-lisp-indent) (current-column))))
(if (listp tem) (car tem) tem)) (if (listp tem) (car tem) tem))
(skip-chars-backward " \t") (skip-chars-backward " \t")
(max (if (bolp) 0 (1+ (current-column))) (max (if (bolp) 0 (1+ (current-column)))
...@@ -357,8 +357,9 @@ rigidly along with this one." ...@@ -357,8 +357,9 @@ rigidly along with this one."
(beginning-of-line) (beginning-of-line)
(setq beg (point)) (setq beg (point))
(skip-chars-forward " \t") (skip-chars-forward " \t")
(if (looking-at "\\s<\\s<\\s<") (if (or (null indent) (looking-at "\\s<\\s<\\s<"))
;; Don't alter indentation of a ;;; comment line. ;; Don't alter indentation of a ;;; comment line
;; or a line that starts in a string.
(goto-char (- (point-max) pos)) (goto-char (- (point-max) pos))
(if (and (looking-at "\\s<") (not (looking-at "\\s<\\s<"))) (if (and (looking-at "\\s<") (not (looking-at "\\s<\\s<")))
;; Single-semicolon comment lines should be indented ;; Single-semicolon comment lines should be indented
...@@ -391,11 +392,14 @@ rigidly along with this one." ...@@ -391,11 +392,14 @@ rigidly along with this one."
(defun calculate-lisp-indent (&optional parse-start) (defun calculate-lisp-indent (&optional parse-start)
"Return appropriate indentation for current line as Lisp code. "Return appropriate indentation for current line as Lisp code.
In usual case returns an integer: the column to indent to. In usual case returns an integer: the column to indent to.
Can instead return a list, whose car is the column to indent to. If the value is nil, that means don't change the indentation
because the line starts inside a string.
The value can also be a list of the form (COLUMN CONTAINING-SEXP-START).
This means that following lines at the same level of indentation This means that following lines at the same level of indentation
should not necessarily be indented the same way. should not necessarily be indented the same as this line.
The second element of the list is the buffer position Then COLUMN is the column to indent to, and CONTAINING-SEXP-START
of the start of the containing expression." is the buffer position of the start of the containing expression."
(save-excursion (save-excursion
(beginning-of-line) (beginning-of-line)
(let ((indent-point (point)) (let ((indent-point (point))
...@@ -470,9 +474,7 @@ of the start of the containing expression." ...@@ -470,9 +474,7 @@ of the start of the containing expression."
(let ((normal-indent (current-column))) (let ((normal-indent (current-column)))
(cond ((elt state 3) (cond ((elt state 3)
;; Inside a string, don't change indentation. ;; Inside a string, don't change indentation.
(goto-char indent-point) nil)
(skip-chars-forward " \t")
(current-column))
((and (integerp lisp-indent-offset) containing-sexp) ((and (integerp lisp-indent-offset) containing-sexp)
;; Indent by constant offset ;; Indent by constant offset
(goto-char containing-sexp) (goto-char containing-sexp)
...@@ -692,12 +694,14 @@ ENDPOS is encountered." ...@@ -692,12 +694,14 @@ ENDPOS is encountered."
(let ((val (calculate-lisp-indent (let ((val (calculate-lisp-indent
(if (car indent-stack) (- (car indent-stack)) (if (car indent-stack) (- (car indent-stack))
starting-point)))) starting-point))))
(if (integerp val) (if (null val)
(setcar indent-stack (setq this-indent val)
(setq this-indent val)) (if (integerp val)
(setcar indent-stack (- (car (cdr val)))) (setcar indent-stack
(setq this-indent (car val))))) (setq this-indent val))
(if (/= (current-column) this-indent) (setcar indent-stack (- (car (cdr val))))
(setq this-indent (car val))))))
(if (and this-indent (/= (current-column) this-indent))
(progn (delete-region bol (point)) (progn (delete-region bol (point))
(indent-to this-indent))))) (indent-to this-indent)))))
(or outer-loop-done (or outer-loop-done
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment