emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Indentation of constants in LISP


From: A Soare
Subject: Re: Indentation of constants in LISP
Date: Fri, 23 Feb 2007 16:58:18 +0100 (CET)

>     There are simply different definitions. Maybe there was 2 persons:
>     one wrote the indentation for a region, and the other for a line.
> 
> Yes, but the two commands are SUPPOSED to indent everything the same way.
> If they do it differently, I think that is a bug.
> 
> Can you state a precise test case for this bug?
> 

There some ambiguities:

One problem:

I do not understand why the indentation of a line is defined twice: one in the 
function indent-sexp :

          ;; Now indent the next line according
          ;; to what we learned from parsing the previous one.
          (setq bol (point))
          (skip-chars-forward " \t")
          ;; But not if the line is blank, or just a comment
          ;; (except for double-semi comments; indent them as usual).
          (if (or (eobp) (looking-at "\\s<\\|\n"))
          ET CAETERA

and, the second time, in the function lisp-indent-line.

(defun lisp-indent-line (&optional whole-exp)
  "Indent current line as Lisp code.
With argument, indent any additional lines of the same expression
rigidly along with this one."
  (interactive "P")
  (let ((indent (calculate-lisp-indent)) shift-amt end
        (pos (- (point-max) (point)))
        (beg (progn (beginning-of-line) (point))))
    (skip-chars-forward " \t")
    (if (or (null indent) (looking-at "\\s<\\s<\\s<"))
        ;; Don't alter indentation of a ;;; comment line
        ;; or a line that starts in a string.
        (goto-char (- (point-max) pos))
      (if (and (looking-at "\\s<") (not (looking-at "\\s<\\s<")))
          ;; Single-semicolon comment lines should be indented
          ;; as comment lines, not as code.


This seems ambigous.

In indent-sexp we can check simplement whether the line is empty. If it is not 
empty, we call lisp-indent-line.

----------------------------

The second problem:

Why the function lisp-indent-region is written so:

(defun lisp-indent-region (start end)
  "Indent every line whose first char is between START and END inclusive."
  (save-excursion
    (let ((endmark (copy-marker end)))
      (goto-char start)
      (and (bolp) (not (eolp))
           (lisp-indent-line))
      (indent-sexp endmark)
      (set-marker endmark nil))))

using indent-sexp instead to look something like this:

(defun lisp-indent-region (start end)
  "Indent every line whose first char is between START and END inclusive."
  (save-excursion
      (goto-char start)
      (while (< (point) end)
        (or (eobp)
            (looking-at "\\s<\\|\n")
            (lisp-indent-line))
        (forward-line))
      (set-marker (copy-marker end) nil)
      (message "indent region finished")))

The logic of indent-sexp seems to have been written to indent a lisp 
expression, that starts exactly after an open syntax class symbol (, until to 
its corresponding ).

------------------------------










reply via email to

[Prev in Thread] Current Thread [Next in Thread]