comparison lisp/emacs-lisp/lisp-mode.el @ 17308:e52fa60d97e8

(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.
author Richard M. Stallman <rms@gnu.org>
date Sat, 05 Apr 1997 21:51:44 +0000
parents 1b3723c744f5
children 71db8e3ee12f
comparison
equal deleted inserted replaced
17307:830ad59547e4 17308:e52fa60d97e8
336 336
337 (defun lisp-comment-indent () 337 (defun lisp-comment-indent ()
338 (if (looking-at "\\s<\\s<\\s<") 338 (if (looking-at "\\s<\\s<\\s<")
339 (current-column) 339 (current-column)
340 (if (looking-at "\\s<\\s<") 340 (if (looking-at "\\s<\\s<")
341 (let ((tem (calculate-lisp-indent))) 341 (let ((tem (or (calculate-lisp-indent) (current-column))))
342 (if (listp tem) (car tem) tem)) 342 (if (listp tem) (car tem) tem))
343 (skip-chars-backward " \t") 343 (skip-chars-backward " \t")
344 (max (if (bolp) 0 (1+ (current-column))) 344 (max (if (bolp) 0 (1+ (current-column)))
345 comment-column)))) 345 comment-column))))
346 346
355 (let ((indent (calculate-lisp-indent)) shift-amt beg end 355 (let ((indent (calculate-lisp-indent)) shift-amt beg end
356 (pos (- (point-max) (point)))) 356 (pos (- (point-max) (point))))
357 (beginning-of-line) 357 (beginning-of-line)
358 (setq beg (point)) 358 (setq beg (point))
359 (skip-chars-forward " \t") 359 (skip-chars-forward " \t")
360 (if (looking-at "\\s<\\s<\\s<") 360 (if (or (null indent) (looking-at "\\s<\\s<\\s<"))
361 ;; Don't alter indentation of a ;;; comment line. 361 ;; Don't alter indentation of a ;;; comment line
362 ;; or a line that starts in a string.
362 (goto-char (- (point-max) pos)) 363 (goto-char (- (point-max) pos))
363 (if (and (looking-at "\\s<") (not (looking-at "\\s<\\s<"))) 364 (if (and (looking-at "\\s<") (not (looking-at "\\s<\\s<")))
364 ;; Single-semicolon comment lines should be indented 365 ;; Single-semicolon comment lines should be indented
365 ;; as comment lines, not as code. 366 ;; as comment lines, not as code.
366 (progn (indent-for-comment) (forward-char -1)) 367 (progn (indent-for-comment) (forward-char -1))
389 (defvar calculate-lisp-indent-last-sexp) 390 (defvar calculate-lisp-indent-last-sexp)
390 391
391 (defun calculate-lisp-indent (&optional parse-start) 392 (defun calculate-lisp-indent (&optional parse-start)
392 "Return appropriate indentation for current line as Lisp code. 393 "Return appropriate indentation for current line as Lisp code.
393 In usual case returns an integer: the column to indent to. 394 In usual case returns an integer: the column to indent to.
394 Can instead return a list, whose car is the column to indent to. 395 If the value is nil, that means don't change the indentation
396 because the line starts inside a string.
397
398 The value can also be a list of the form (COLUMN CONTAINING-SEXP-START).
395 This means that following lines at the same level of indentation 399 This means that following lines at the same level of indentation
396 should not necessarily be indented the same way. 400 should not necessarily be indented the same as this line.
397 The second element of the list is the buffer position 401 Then COLUMN is the column to indent to, and CONTAINING-SEXP-START
398 of the start of the containing expression." 402 is the buffer position of the start of the containing expression."
399 (save-excursion 403 (save-excursion
400 (beginning-of-line) 404 (beginning-of-line)
401 (let ((indent-point (point)) 405 (let ((indent-point (point))
402 state paren-depth 406 state paren-depth
403 ;; setting this to a number inhibits calling hook 407 ;; setting this to a number inhibits calling hook
468 ;; Call indentation hook except when overridden by lisp-indent-offset 472 ;; Call indentation hook except when overridden by lisp-indent-offset
469 ;; or if the desired indentation has already been computed. 473 ;; or if the desired indentation has already been computed.
470 (let ((normal-indent (current-column))) 474 (let ((normal-indent (current-column)))
471 (cond ((elt state 3) 475 (cond ((elt state 3)
472 ;; Inside a string, don't change indentation. 476 ;; Inside a string, don't change indentation.
473 (goto-char indent-point) 477 nil)
474 (skip-chars-forward " \t")
475 (current-column))
476 ((and (integerp lisp-indent-offset) containing-sexp) 478 ((and (integerp lisp-indent-offset) containing-sexp)
477 ;; Indent by constant offset 479 ;; Indent by constant offset
478 (goto-char containing-sexp) 480 (goto-char containing-sexp)
479 (+ (current-column) lisp-indent-offset)) 481 (+ (current-column) lisp-indent-offset))
480 (desired-indent) 482 (desired-indent)
690 (>= (car indent-stack) 0)) 692 (>= (car indent-stack) 0))
691 (setq this-indent (car indent-stack)) 693 (setq this-indent (car indent-stack))
692 (let ((val (calculate-lisp-indent 694 (let ((val (calculate-lisp-indent
693 (if (car indent-stack) (- (car indent-stack)) 695 (if (car indent-stack) (- (car indent-stack))
694 starting-point)))) 696 starting-point))))
695 (if (integerp val) 697 (if (null val)
696 (setcar indent-stack 698 (setq this-indent val)
697 (setq this-indent val)) 699 (if (integerp val)
698 (setcar indent-stack (- (car (cdr val)))) 700 (setcar indent-stack
699 (setq this-indent (car val))))) 701 (setq this-indent val))
700 (if (/= (current-column) this-indent) 702 (setcar indent-stack (- (car (cdr val))))
703 (setq this-indent (car val))))))
704 (if (and this-indent (/= (current-column) this-indent))
701 (progn (delete-region bol (point)) 705 (progn (delete-region bol (point))
702 (indent-to this-indent))))) 706 (indent-to this-indent)))))
703 (or outer-loop-done 707 (or outer-loop-done
704 (setq outer-loop-done (= (point) last-point)) 708 (setq outer-loop-done (= (point) last-point))
705 (setq last-point (point))))))) 709 (setq last-point (point)))))))