Mercurial > emacs
comparison lisp/emacs-lisp/lisp-mode.el @ 9423:9076245a9fed
(calculate-lisp-indent): Local var
last-sexp renamed to calculate-lisp-indent-last-sexp.
(lisp-indent-function): Use new name of var.
(calculate-lisp-indent-last-sexp): Var defined.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Mon, 10 Oct 1994 21:53:52 +0000 |
parents | ee3bdb606d7b |
children | 738999b0296f |
comparison
equal
deleted
inserted
replaced
9422:669208821120 | 9423:9076245a9fed |
---|---|
299 (forward-line 1) | 299 (forward-line 1) |
300 (setq beg (point)) | 300 (setq beg (point)) |
301 (> end beg)) | 301 (> end beg)) |
302 (indent-code-rigidly beg end shift-amt))))) | 302 (indent-code-rigidly beg end shift-amt))))) |
303 | 303 |
304 defvar calculate-lisp-indent-last-sexp) | |
305 | |
304 (defun calculate-lisp-indent (&optional parse-start) | 306 (defun calculate-lisp-indent (&optional parse-start) |
305 "Return appropriate indentation for current line as Lisp code. | 307 "Return appropriate indentation for current line as Lisp code. |
306 In usual case returns an integer: the column to indent to. | 308 In usual case returns an integer: the column to indent to. |
307 Can instead return a list, whose car is the column to indent to. | 309 Can instead return a list, whose car is the column to indent to. |
308 This means that following lines at the same level of indentation | 310 This means that following lines at the same level of indentation |
314 (let ((indent-point (point)) | 316 (let ((indent-point (point)) |
315 state paren-depth | 317 state paren-depth |
316 ;; setting this to a number inhibits calling hook | 318 ;; setting this to a number inhibits calling hook |
317 (desired-indent nil) | 319 (desired-indent nil) |
318 (retry t) | 320 (retry t) |
319 last-sexp containing-sexp) | 321 calculate-lisp-indent-last-sexp containing-sexp) |
320 (if parse-start | 322 (if parse-start |
321 (goto-char parse-start) | 323 (goto-char parse-start) |
322 (beginning-of-defun)) | 324 (beginning-of-defun)) |
323 ;; Find outermost containing sexp | 325 ;; Find outermost containing sexp |
324 (while (< (point) indent-point) | 326 (while (< (point) indent-point) |
326 ;; Find innermost containing sexp | 328 ;; Find innermost containing sexp |
327 (while (and retry | 329 (while (and retry |
328 state | 330 state |
329 (> (setq paren-depth (elt state 0)) 0)) | 331 (> (setq paren-depth (elt state 0)) 0)) |
330 (setq retry nil) | 332 (setq retry nil) |
331 (setq last-sexp (elt state 2)) | 333 (setq calculate-lisp-indent-last-sexp (elt state 2)) |
332 (setq containing-sexp (elt state 1)) | 334 (setq containing-sexp (elt state 1)) |
333 ;; Position following last unclosed open. | 335 ;; Position following last unclosed open. |
334 (goto-char (1+ containing-sexp)) | 336 (goto-char (1+ containing-sexp)) |
335 ;; Is there a complete sexp since then? | 337 ;; Is there a complete sexp since then? |
336 (if (and last-sexp (> last-sexp (point))) | 338 (if (and calculate-lisp-indent-last-sexp |
339 (> calculate-lisp-indent-last-sexp (point))) | |
337 ;; Yes, but is there a containing sexp after that? | 340 ;; Yes, but is there a containing sexp after that? |
338 (let ((peek (parse-partial-sexp last-sexp indent-point 0))) | 341 (let ((peek (parse-partial-sexp calculate-lisp-indent-last-sexp |
342 indent-point 0))) | |
339 (if (setq retry (car (cdr peek))) (setq state peek))))) | 343 (if (setq retry (car (cdr peek))) (setq state peek))))) |
340 (if retry | 344 (if retry |
341 nil | 345 nil |
342 ;; Innermost containing sexp found | 346 ;; Innermost containing sexp found |
343 (goto-char (1+ containing-sexp)) | 347 (goto-char (1+ containing-sexp)) |
344 (if (not last-sexp) | 348 (if (not calculate-lisp-indent-last-sexp) |
345 ;; indent-point immediately follows open paren. | 349 ;; indent-point immediately follows open paren. |
346 ;; Don't call hook. | 350 ;; Don't call hook. |
347 (setq desired-indent (current-column)) | 351 (setq desired-indent (current-column)) |
348 ;; Find the start of first element of containing sexp. | 352 ;; Find the start of first element of containing sexp. |
349 (parse-partial-sexp (point) last-sexp 0 t) | 353 (parse-partial-sexp (point) calculate-lisp-indent-last-sexp 0 t) |
350 (cond ((looking-at "\\s(") | 354 (cond ((looking-at "\\s(") |
351 ;; First element of containing sexp is a list. | 355 ;; First element of containing sexp is a list. |
352 ;; Indent under that list. | 356 ;; Indent under that list. |
353 ) | 357 ) |
354 ((> (save-excursion (forward-line 1) (point)) | 358 ((> (save-excursion (forward-line 1) (point)) |
355 last-sexp) | 359 calculate-lisp-indent-last-sexp) |
356 ;; This is the first line to start within the containing sexp. | 360 ;; This is the first line to start within the containing sexp. |
357 ;; It's almost certainly a function call. | 361 ;; It's almost certainly a function call. |
358 (if (= (point) last-sexp) | 362 (if (= (point) calculate-lisp-indent-last-sexp) |
359 ;; Containing sexp has nothing before this line | 363 ;; Containing sexp has nothing before this line |
360 ;; except the first element. Indent under that element. | 364 ;; except the first element. Indent under that element. |
361 nil | 365 nil |
362 ;; Skip the first element, find start of second (the first | 366 ;; Skip the first element, find start of second (the first |
363 ;; argument of the function call) and indent under. | 367 ;; argument of the function call) and indent under. |
364 (progn (forward-sexp 1) | 368 (progn (forward-sexp 1) |
365 (parse-partial-sexp (point) last-sexp 0 t))) | 369 (parse-partial-sexp (point) |
370 calculate-lisp-indent-last-sexp | |
371 0 t))) | |
366 (backward-prefix-chars)) | 372 (backward-prefix-chars)) |
367 (t | 373 (t |
368 ;; Indent beneath first sexp on same line as last-sexp. | 374 ;; Indent beneath first sexp on same line as |
369 ;; Again, it's almost certainly a function call. | 375 ;; calculate-lisp-indent-last-sexp. Again, it's |
370 (goto-char last-sexp) | 376 ;; almost certainly a function call. |
377 (goto-char calculate-lisp-indent-last-sexp) | |
371 (beginning-of-line) | 378 (beginning-of-line) |
372 (parse-partial-sexp (point) last-sexp 0 t) | 379 (parse-partial-sexp (point) calculate-lisp-indent-last-sexp |
380 0 t) | |
373 (backward-prefix-chars))))) | 381 (backward-prefix-chars))))) |
374 ;; Point is at the point to indent under unless we are inside a string. | 382 ;; Point is at the point to indent under unless we are inside a string. |
375 ;; Call indentation hook except when overridden by lisp-indent-offset | 383 ;; Call indentation hook except when overridden by lisp-indent-offset |
376 ;; or if the desired indentation has already been computed. | 384 ;; or if the desired indentation has already been computed. |
377 (let ((normal-indent (current-column))) | 385 (let ((normal-indent (current-column))) |
394 normal-indent)))))) | 402 normal-indent)))))) |
395 | 403 |
396 (defun lisp-indent-function (indent-point state) | 404 (defun lisp-indent-function (indent-point state) |
397 (let ((normal-indent (current-column))) | 405 (let ((normal-indent (current-column))) |
398 (goto-char (1+ (elt state 1))) | 406 (goto-char (1+ (elt state 1))) |
399 (parse-partial-sexp (point) last-sexp 0 t) | 407 (parse-partial-sexp (point) calculate-lisp-indent-last-sexp 0 t) |
400 (if (and (elt state 2) | 408 (if (and (elt state 2) |
401 (not (looking-at "\\sw\\|\\s_"))) | 409 (not (looking-at "\\sw\\|\\s_"))) |
402 ;; car of form doesn't seem to be a a symbol | 410 ;; car of form doesn't seem to be a a symbol |
403 (progn | 411 (progn |
404 (if (not (> (save-excursion (forward-line 1) (point)) | 412 (if (not (> (save-excursion (forward-line 1) (point)) |
405 last-sexp)) | 413 calculate-lisp-indent-last-sexp)) |
406 (progn (goto-char last-sexp) | 414 (progn (goto-char calculate-lisp-indent-last-sexp) |
407 (beginning-of-line) | 415 (beginning-of-line) |
408 (parse-partial-sexp (point) last-sexp 0 t))) | 416 (parse-partial-sexp (point) |
409 ;; Indent under the list or under the first sexp on the | 417 calculate-lisp-indent-last-sexp 0 t))) |
410 ;; same line as last-sexp. Note that first thing on that | 418 ;; Indent under the list or under the first sexp on the same |
411 ;; line has to be complete sexp since we are inside the | 419 ;; line as calculate-lisp-indent-last-sexp. Note that first |
412 ;; innermost containing sexp. | 420 ;; thing on that line has to be complete sexp since we are |
421 ;; inside the innermost containing sexp. | |
413 (backward-prefix-chars) | 422 (backward-prefix-chars) |
414 (current-column)) | 423 (current-column)) |
415 (let ((function (buffer-substring (point) | 424 (let ((function (buffer-substring (point) |
416 (progn (forward-sexp 1) (point)))) | 425 (progn (forward-sexp 1) (point)))) |
417 method) | 426 method) |