unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Indentation of constants in LISP
@ 2007-02-02 16:17 A Soare
  2007-02-03 11:19 ` Richard Stallman
  2007-02-20 13:29 ` Johan Bockgård
  0 siblings, 2 replies; 29+ messages in thread
From: A Soare @ 2007-02-02 16:17 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 855 bytes --]

Hello.

There is no rule in this moment to align the constant symbols in
lisp, emacs lisp, lisp-interaction modes. For example:

 '( :stipple nil
             :background "LightBlue"
             :foreground "Black"
             :inverse-video nil

(f p q r :name nil
   :server nil

In case that the first symbol of the current line is a constant,
the indentation will be:

 '( :stipple nil
    :background "LightBlue"
    :foreground "Black"
    :inverse-video nil

(f p q r :name nil
         :server nil


etc.

It's not an exhaustive treatment, because there is not an
exhaustive definition of this kind of alignement.


I attached here the file diff which represents the output from 

cvs -d:pserver:anonymous@cvs.gnu.org:/sources/emacs diff emacs/lisp/emacs-lisp/lisp-mode.el

and, in case that the code is accepted, a change log entry.



A Soare

[-- Attachment #2: /diff --]
[-- Type: application/octet-stream, Size: 1185 bytes --]

Index: emacs/lisp/emacs-lisp/lisp-mode.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/emacs-lisp/lisp-mode.el,v
retrieving revision 1.196
diff -r1.196 lisp-mode.el
909a910,927
>               ((save-excursion
>                  (goto-char indent-point)
>                  (skip-chars-forward " \t")
>                  (and (looking-at ":")
>                       (thing-at-point 'symbol)))
>                ;; Align a constant symbol under a constant symbol
>                ;; Not used keywordp in order not to intern it
>                (let ((desired-indent
>                       (save-excursion
>                         (goto-char (1+ containing-sexp))
>                         (parse-partial-sexp (point) calculate-lisp-indent-last-sexp 0 t)
>                         (point))))
>                  (goto-char calculate-lisp-indent-last-sexp)
>                  (while (> (point) desired-indent)
>                    (cond ((equal (elt (thing-at-point 'symbol) 0) ?:)
>                           (setq desired-indent (point)))
>                          (t (backward-sexp 1))))
>                  (current-column)))

[-- Attachment #3: /change-log --]
[-- Type: application/octet-stream, Size: 172 bytes --]

2007-02-02  Alin C. Soare  <alinsoar@voila.fr>  (tiny change)

	* lisp/emacs-lisp/lisp-mode.el (calculate-lisp-indent):
	Added indentation for the constant symbols of Lisp

[-- Attachment #4: Type: text/plain, Size: 142 bytes --]

_______________________________________________
Emacs-devel mailing list
Emacs-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-devel

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: Indentation of constants in LISP
  2007-02-02 16:17 A Soare
@ 2007-02-03 11:19 ` Richard Stallman
  2007-02-20 13:29 ` Johan Bockgård
  1 sibling, 0 replies; 29+ messages in thread
From: Richard Stallman @ 2007-02-03 11:19 UTC (permalink / raw)
  To: alinsoar; +Cc: emacs-devel

This is an interesting idea.

thingatpt is not normally loaded, so it would be better to avoid using
it here.  It should not be needed here, since the code is not trying
to find the whole symbol name, just checking that there is one.  Can
you rewrite it to use looking-at instead of thing-at-point?

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: Indentation of constants in LISP
@ 2007-02-04 11:37 A Soare
  0 siblings, 0 replies; 29+ messages in thread
From: A Soare @ 2007-02-04 11:37 UTC (permalink / raw)
  To: rms; +Cc: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 754 bytes --]

I gave up with the things. Please look again. new diff is attached.

Alin Soare

> Message du 03/02/07 à 12h22
> De : "Richard Stallman" <rms@gnu.org>
> A : alinsoar@voila.fr
> Copie à : emacs-devel@gnu.org
> Objet : Re: Indentation of constants in LISP
> 
> This is an interesting idea.
> 
> thingatpt is not normally loaded, so it would be better to avoid using
> it here.  It should not be needed here, since the code is not trying
> to find the whole symbol name, just checking that there is one.  Can
> you rewrite it to use looking-at instead of thing-at-point?
> 
> 
> _______________________________________________
> Emacs-devel mailing list
> Emacs-devel@gnu.org
> http://lists.gnu.org/mailman/listinfo/emacs-devel
> 
>

[-- Attachment #2: /diff --]
[-- Type: application/octet-stream, Size: 1345 bytes --]

Index: emacs/lisp/emacs-lisp/lisp-mode.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/emacs-lisp/lisp-mode.el,v
retrieving revision 1.197
diff -r1.197 lisp-mode.el
911a912,931
>               ((save-excursion
>                 (goto-char indent-point)
>                 (skip-chars-forward " \t")
>                 (looking-at ":")
>                 (zerop (skip-syntax-backward "w_")))
>                ;; Align a constant symbol under the last constant symbol
>                ;; from the same level. Not used keywordp in order not to intern it
>                ;; definition of a symbol in *thingatpt.el* (defun forward-symbol ...)
>                (let ((desired-indent
>                       (save-excursion
>                         (goto-char (1+ containing-sexp))
>                         (parse-partial-sexp (point) calculate-lisp-indent-last-sexp 0 t)
>                         (point))))
>                  (goto-char calculate-lisp-indent-last-sexp)
>                  (while (> (point) desired-indent)
>                    (cond ((and (looking-at ":")
>                                (zerop (skip-syntax-backward "w_")))
>                           (setq desired-indent (point)))
>                          (t (backward-sexp 1))))
>                  (current-column)))

[-- Attachment #3: Type: text/plain, Size: 142 bytes --]

_______________________________________________
Emacs-devel mailing list
Emacs-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-devel

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: Indentation of constants in LISP
@ 2007-02-04 13:28 A Soare
  2007-02-05  0:23 ` Richard Stallman
  2007-02-05  1:28 ` Stefan Monnier
  0 siblings, 2 replies; 29+ messages in thread
From: A Soare @ 2007-02-04 13:28 UTC (permalink / raw)
  To: emacs-devel


In fact, it is not necessary to add (zerop (skip-syntax-backward "w_")), it is sufficient just to verify that (string (char-syntax ?\:)) is "_", because before the ":" there is or a space or a tab, which is from the " " syntax class, so 
(zerop (skip-syntax-backward "w_")) will always return 0.

Alin Soare

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: Indentation of constants in LISP
  2007-02-04 13:28 A Soare
@ 2007-02-05  0:23 ` Richard Stallman
  2007-02-05  1:28 ` Stefan Monnier
  1 sibling, 0 replies; 29+ messages in thread
From: Richard Stallman @ 2007-02-05  0:23 UTC (permalink / raw)
  To: alinsoar; +Cc: emacs-devel

    In fact, it is not necessary to add (zerop (skip-syntax-backward "w_")), it is sufficient just to verify that (string (char-syntax ?\:)) is "_", because before the ":" there is or a space or a tab, which is from the " " syntax class, so 
    (zerop (skip-syntax-backward "w_")) will always return 0.

When you send a revised patch, please make this change too.

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: Indentation of constants in LISP
  2007-02-04 13:28 A Soare
  2007-02-05  0:23 ` Richard Stallman
@ 2007-02-05  1:28 ` Stefan Monnier
  1 sibling, 0 replies; 29+ messages in thread
From: Stefan Monnier @ 2007-02-05  1:28 UTC (permalink / raw)
  To: alinsoar; +Cc: emacs-devel

> it is sufficient just to verify that (string (char-syntax ?\:)) is "_",

You mean, verify that (char-syntax ?\:) is ?\_, right?


        Stefan

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: Indentation of constants in LISP
@ 2007-02-05  7:41 A Soare
  2007-02-05 19:06 ` Stefan Monnier
  0 siblings, 1 reply; 29+ messages in thread
From: A Soare @ 2007-02-05  7:41 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel


I mean that ":" is part of a SYMBOL i.e. (string (char-syntax ?:))  is equal "_", and, in the same time, the characters SPACE TAB NEW-LINE  are NOT from this syntax class ("_").

I could give this verification up if I am sure that in all lisp modes this always happen, i.e. The syntax class for ":" is always "_" and none of the syntax classes for SPACE TAB NEW-LINE  are never "_".

But I will still make this verification.

Alin Soare


> Message du 05/02/07 à 02h28
> De : "Stefan Monnier" <monnier@iro.umontreal.ca>
> A : alinsoar@voila.fr
> Copie à : "emacs-devel" <emacs-devel@gnu.org>
> Objet : Re: Indentation of constants in LISP
> 
> > it is sufficient just to verify that (string (char-syntax ?\:)) is "_",
> 
> You mean, verify that (char-syntax ?\:) is ?\_, right?
> 
> 
>         Stefan
> 
>

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: Indentation of constants in LISP
@ 2007-02-05  9:51 A Soare
  0 siblings, 0 replies; 29+ messages in thread
From: A Soare @ 2007-02-05  9:51 UTC (permalink / raw)
  To: rms; +Cc: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 243 bytes --]

I added here

1. output from 

 cvs -d:pserver:anonymous@cvs.gnu.org:/sources/emacs diff -c emacs/lisp/emacs-lisp/lisp-mode.el

 - one version with very detailed comments
 - one version with short comments

2. a Change-Log entry.

Alin Soare


[-- Attachment #2: /diff-long-format --]
[-- Type: application/octet-stream, Size: 3803 bytes --]


Index: emacs/lisp/emacs-lisp/lisp-mode.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/emacs-lisp/lisp-mode.el,v
retrieving revision 1.196
diff -c -r1.196 lisp-mode.el
*** emacs/lisp/emacs-lisp/lisp-mode.el	21 Jan 2007 02:44:24 -0000	1.196
--- emacs/lisp/emacs-lisp/lisp-mode.el	5 Feb 2007 09:39:52 -0000
***************
*** 907,912 ****
--- 907,960 ----
          (cond ((elt state 3)
                 ;; Inside a string, don't change indentation.
  	       nil)
+               ((save-excursion
+                  ;; test whether current line begins with a constant
+                  ;;
+                  ;; from the beginning of the current-line (indent-point) we jump
+                  ;; to the first readable character, if there is one.
+                  ;; before this first readable character we have or SPACE, or TAB
+                  ;; or NEW-LINE. If the first character is ?\:, we consider that it
+                  ;; is the start of a constant symbol, because the syntax class of ?\:
+                  ;; is "_", i.e. ":" is symbol constituent. If there is possible to
+                  ;; change the syntax table of LISP major mode for some practical
+                  ;; reasons, so that one of the characters SPACE, TAB or NEW-LINE
+                  ;; become a symbol constituent, it is necessary to uncomment and
+                  ;; insert into save-excursion just one of the 2 last conditions
+                  (goto-char indent-point)
+                  (skip-chars-forward " \t")
+                  (looking-at ":"))
+                ;;(and (string-equal (string (char-syntax ?\:)) "_")
+                ;;     (not (char-equal (char-syntax (preceding-char)) ?\_)))
+                ;;(zerop (skip-syntax-backward "w_"))
+                (let ((desired-indent
+                       (save-excursion
+                         (goto-char (1+ containing-sexp))
+                         (parse-partial-sexp (point) calculate-lisp-indent-last-sexp 0 t)
+                         (point)))
+                      (parse-sexp-ignore-comments t))
+                  ;; Align a constant symbol under the last constant symbol
+                  ;; Not used keywordp in order not to intern it.
+                  ;;
+                  ;; desired-indent is initialised with the beginning of the
+                  ;; first sexp from the last opened parenthesis (i.e. the first
+                  ;; expression from the same level as the point's).
+                  ;; we begin checking from the last sexp before the indent-point
+                  ;; i.e. from calculate-lisp-indent-last-sexp.
+                  ;; backward-sexp goes back one sexp by one sexp.
+                  ;; In case that we find a ":", we stop, because this is the beginning of
+                  ;; a symbol. If it were not the beginning , then backward-sexp would
+                  ;; jump more, so it is not necessary to do another verification
+                  ;; to check this is a constant.
+                  ;; I made parse-sexp-ignore-comments locally true, to be sure that
+                  ;; comments are ignored by backward-sexp in this searching
+                  ;; finally we return the current column, which will be the result of
+                  ;; this function.
+                  (goto-char calculate-lisp-indent-last-sexp)
+                  (while (> (point) desired-indent)
+                    (if (looking-at ":")
+                        (setq desired-indent (point)))
+                    (backward-sexp 1)))
+                  (current-column))
                ((and (integerp lisp-indent-offset) containing-sexp)
                 ;; Indent by constant offset
                 (goto-char containing-sexp)

[-- Attachment #3: /diff-short-format --]
[-- Type: application/octet-stream, Size: 1603 bytes --]

Index: emacs/lisp/emacs-lisp/lisp-mode.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/emacs-lisp/lisp-mode.el,v
retrieving revision 1.196
diff -c -r1.196 lisp-mode.el
*** emacs/lisp/emacs-lisp/lisp-mode.el	21 Jan 2007 02:44:24 -0000	1.196
--- emacs/lisp/emacs-lisp/lisp-mode.el	5 Feb 2007 09:31:19 -0000
***************
*** 907,912 ****
--- 907,930 ----
          (cond ((elt state 3)
                 ;; Inside a string, don't change indentation.
  	       nil)
+               ((save-excursion
+                  ;; test whether current line begins with a constant
+                  (goto-char indent-point)
+                  (skip-chars-forward " \t")
+                  (looking-at ":"))
+                (let ((desired-indent
+                       (save-excursion
+                         (goto-char (1+ containing-sexp))
+                         (parse-partial-sexp (point) calculate-lisp-indent-last-sexp 0 t)
+                         (point)))
+                      (parse-sexp-ignore-comments t))
+                  ;; Align a constant symbol under the last constant symbol
+                  (goto-char calculate-lisp-indent-last-sexp)
+                  (while (> (point) desired-indent)
+                    (if (looking-at ":")
+                        (setq desired-indent (point))
+                    (backward-sexp 1))))
+                  (current-column))
                ((and (integerp lisp-indent-offset) containing-sexp)
                 ;; Indent by constant offset
                 (goto-char containing-sexp)

[-- Attachment #4: /change-log --]
[-- Type: application/octet-stream, Size: 166 bytes --]

2007-01-20  Alin C. Soare  <alinsoar@voila.fr>  (tiny change)

	* lisp/emacs-lisp/lisp-mode.el (calculate-lisp-indent):
	Added indentation for the constants of Lisp.

[-- Attachment #5: Type: text/plain, Size: 142 bytes --]

_______________________________________________
Emacs-devel mailing list
Emacs-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-devel

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: Indentation of constants in LISP
@ 2007-02-05 14:33 A Soare
  0 siblings, 0 replies; 29+ messages in thread
From: A Soare @ 2007-02-05 14:33 UTC (permalink / raw)
  To: rms; +Cc: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 156 bytes --]

I send again teh files, because I see now that there was an error in change-log and one in diff-long-format, and one error in diff-short-format.

A Soare



[-- Attachment #2: /diff-long-format --]
[-- Type: application/octet-stream, Size: 3807 bytes --]


Index: emacs/lisp/emacs-lisp/lisp-mode.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/emacs-lisp/lisp-mode.el,v
retrieving revision 1.196
diff -c -r1.196 lisp-mode.el
*** emacs/lisp/emacs-lisp/lisp-mode.el	21 Jan 2007 02:44:24 -0000	1.196
--- emacs/lisp/emacs-lisp/lisp-mode.el	5 Feb 2007 14:23:37 -0000
***************
*** 907,912 ****
--- 907,960 ----
          (cond ((elt state 3)
                 ;; Inside a string, don't change indentation.
  	       nil)
+               ((save-excursion
+                  ;; test whether current line begins with a constant
+                  ;;
+                  ;; from the beginning of the current-line (indent-point) we jump
+                  ;; to the first readable character, if there is one.
+                  ;; before this first readable character we have or SPACE, or TAB
+                  ;; or NEW-LINE. If the first character is ?\:, we consider that it
+                  ;; is the start of a constant symbol, because the syntax class of ?\:
+                  ;; is "_", i.e. ":" is symbol constituent. If there is possible to
+                  ;; change the syntax table of LISP major mode for some practical
+                  ;; reasons, so that one of the characters SPACE, TAB or NEW-LINE
+                  ;; become a symbol constituent, it is necessary to uncomment and
+                  ;; insert into save-excursion just one of the 2 last conditions
+                  (goto-char indent-point)
+                  (skip-chars-forward " \t")
+                  (looking-at ":"))
+                ;;(and (string-equal (string (char-syntax ?\:)) "_")
+                ;;     (not (char-equal (char-syntax (preceding-char)) ?\_)))
+                ;;(zerop (skip-syntax-backward "w_"))
+                (let ((desired-indent
+                       (save-excursion
+                         (goto-char (1+ containing-sexp))
+                         (parse-partial-sexp (point) calculate-lisp-indent-last-sexp 0 t)
+                         (point)))
+                      (parse-sexp-ignore-comments t))
+                  ;; Align a constant symbol under the last constant symbol
+                  ;; Not used keywordp in order not to intern it.
+                  ;;
+                  ;; desired-indent is initialised with the beginning of the
+                  ;; first sexp from the last opened parenthesis (i.e. the first
+                  ;; expression from the same level as the point's).
+                  ;; we begin checking from the last sexp before the indent-point
+                  ;; i.e. from calculate-lisp-indent-last-sexp.
+                  ;; backward-sexp goes back one sexp by one sexp.
+                  ;; In case that we find a ":", we stop, because this is the beginning of
+                  ;; a symbol. If it were not the beginning , then backward-sexp would
+                  ;; jump more, so it is not necessary to do another verification
+                  ;; to check this is a constant.
+                  ;; I made parse-sexp-ignore-comments locally true, to be sure that
+                  ;; comments are ignored by backward-sexp in this searching
+                  ;; finally we return the current column, which will be the result of
+                  ;; this function.
+                  (goto-char calculate-lisp-indent-last-sexp)
+                  (while (> (point) desired-indent)
+                    (if (looking-at ":")
+                        (setq desired-indent (point))
+                      (backward-sexp 1))))
+                  (current-column))
                ((and (integerp lisp-indent-offset) containing-sexp)
                 ;; Indent by constant offset
                 (goto-char containing-sexp)


[-- Attachment #3: /diff-short-format --]
[-- Type: application/octet-stream, Size: 1605 bytes --]

Index: emacs/lisp/emacs-lisp/lisp-mode.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/emacs-lisp/lisp-mode.el,v
retrieving revision 1.196
diff -c -r1.196 lisp-mode.el
*** emacs/lisp/emacs-lisp/lisp-mode.el	21 Jan 2007 02:44:24 -0000	1.196
--- emacs/lisp/emacs-lisp/lisp-mode.el	5 Feb 2007 14:26:46 -0000
***************
*** 907,912 ****
--- 907,930 ----
          (cond ((elt state 3)
                 ;; Inside a string, don't change indentation.
  	       nil)
+               ((save-excursion
+                  ;; test whether current line begins with a constant
+                  (goto-char indent-point)
+                  (skip-chars-forward " \t")
+                  (looking-at ":"))
+                (let ((desired-indent
+                       (save-excursion
+                         (goto-char (1+ containing-sexp))
+                         (parse-partial-sexp (point) calculate-lisp-indent-last-sexp 0 t)
+                         (point)))
+                      (parse-sexp-ignore-comments t))
+                  ;; Align a constant symbol under the last constant symbol
+                  (goto-char calculate-lisp-indent-last-sexp)
+                  (while (> (point) desired-indent)
+                    (if (looking-at ":")
+                        (setq desired-indent (point))
+                      (backward-sexp 1))))
+                  (current-column))
                ((and (integerp lisp-indent-offset) containing-sexp)
                 ;; Indent by constant offset
                 (goto-char containing-sexp)

[-- Attachment #4: /change-log --]
[-- Type: application/octet-stream, Size: 166 bytes --]

2007-02-05  Alin C. Soare  <alinsoar@voila.fr>  (tiny change)

	* lisp/emacs-lisp/lisp-mode.el (calculate-lisp-indent):
	Added indentation for the constants of Lisp.

[-- Attachment #5: Type: text/plain, Size: 142 bytes --]

_______________________________________________
Emacs-devel mailing list
Emacs-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-devel

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: Indentation of constants in LISP
  2007-02-05  7:41 A Soare
@ 2007-02-05 19:06 ` Stefan Monnier
  0 siblings, 0 replies; 29+ messages in thread
From: Stefan Monnier @ 2007-02-05 19:06 UTC (permalink / raw)
  To: alinsoar; +Cc: emacs-devel

> I mean that ":" is part of a SYMBOL i.e. (string (char-syntax ?:))  is
> equal "_", and, in the same time, the characters SPACE TAB NEW-LINE  are
> NOT from this syntax class ("_").

OK, let me write this differently:

If (string (char-syntax ?:)) is equal to "_" then it is necessarily true
that (char-syntax ?:) is equal to ?\_.

Your test is comparable to checking if (list <foo>) is equal to '(2) rather
than checking if <foo> is equal to 2.


        Stefan

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: Indentation of constants in LISP
  2007-02-02 16:17 A Soare
  2007-02-03 11:19 ` Richard Stallman
@ 2007-02-20 13:29 ` Johan Bockgård
  2007-02-21  0:44   ` Richard Stallman
  1 sibling, 1 reply; 29+ messages in thread
From: Johan Bockgård @ 2007-02-20 13:29 UTC (permalink / raw)
  To: emacs-devel

A Soare <alinsoar@voila.fr> writes:

> In case that the first symbol of the current line is a constant,
> the indentation will be:
>
>  '( :stipple nil
>     :background "LightBlue"
>     :foreground "Black"
>     :inverse-video nil

See below.

> (f p q r :name nil
>          :server nil

It's not clear that this is necessarily an improvement.


Generally, I think that this approach is flawed. It breaks the
indentation of many forms, and trying to "align" things in this way is
a bad idea in the first place.

Problems:

    (prog2
        x
     :y
     z)

    (defcustom var :val
                   :group foo)

    (foo :a b :c d
              :e f)

    (foo a :b c
         d
           :e f)

    (actually, TAB and indent-region produce different results in the
    last two cases!)

etc.

Here's one more:

    :x   TAB => error




OTOH, this one-line patch by Pascal Bourguignon might be a good idea:

http://common-lisp.net/pipermail/slime-devel/2004-October/002487.html

--- lisp-mode.el        18 Feb 2007 00:06:37 +0100      1.199
+++ lisp-mode.el        20 Feb 2007 13:35:31 +0100      
@@ -965,7 +965,7 @@
     (goto-char (1+ (elt state 1)))
     (parse-partial-sexp (point) calculate-lisp-indent-last-sexp 0 t)
     (if (and (elt state 2)
-             (not (looking-at "\\sw\\|\\s_")))
+             (or (looking-at ":") (not (looking-at "\\sw\\|\\s_"))))
         ;; car of form doesn't seem to be a symbol
         (progn
           (if (not (> (save-excursion (forward-line 1) (point))


It indents

    (:stipple y
     z)

to go along with the existing treatment of forms that begin with a
constant, such as

    ("stipple" y
     z)

(Technically, ":foo" isn't disallowed as a function name, but it is
highly unusual.)

-- 
Johan Bockgård

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: Indentation of constants in LISP
@ 2007-02-20 14:14 A Soare
  2007-02-20 18:04 ` Stuart D. Herring
  0 siblings, 1 reply; 29+ messages in thread
From: A Soare @ 2007-02-20 14:14 UTC (permalink / raw)
  To: emacs-devel


> Message: 11
> Date: Tue, 20 Feb 2007 14:29:06 +0100
> From: bojohan+news@dd.chalmers.se (Johan Bockg?rd )
> Subject: Re: Indentation of constants in LISP
> To: emacs-devel@gnu.org
> Message-ID: <yoij649x7yal.fsf@gamma02.me.chalmers.se>
> Content-Type: text/plain; charset=utf-8
> 
> A Soare <alinsoar@voila.fr> writes:
> 
> > In case that the first symbol of the current line is a constant,
> > the indentation will be:
> >
> >  '( :stipple nil
> >     :background "LightBlue"
> >     :foreground "Black"
> >     :inverse-video nil
> 
> See below.
> 
> > (f p q r :name nil
> >          :server nil

This is OK.

> 
> It's not clear that this is necessarily an improvement.
> 
> 
> Generally, I think that this approach is flawed. It breaks the
> indentation of many forms, and trying to "align" things in this way is
> a bad idea in the first place.
> 
> Problems:
> 
>     (prog2
>         x
>      :y
>      z)
> 
This is not a problem at all, because in this case this old situation is also a problem:

(prog2
    x
    y
  z)



>     (defcustom var :val
>                    :group foo)

This is ok.

> 
>     (foo :a b :c d
>               :e f)

This is OK.

> 
>     (foo a :b c
>          d
>            :e f)

This is ok.

> 
>     (actually, TAB and indent-region produce different results in the
>     last two cases!)

If you take into consideration my definition of the align. it is all ok.


> 
> etc.
> 
> Here's one more:
> 
>     :x   TAB => error
> 

This is not OK.

As I said when I send this improvement, I GAVE NOT a GENERAL DEFINITION of this kind of alignement.

I have taken into consideration just the cases that I needed for my own code.

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: Indentation of constants in LISP
@ 2007-02-20 14:26 A Soare
  2007-02-21 22:55 ` Richard Stallman
  0 siblings, 1 reply; 29+ messages in thread
From: A Soare @ 2007-02-20 14:26 UTC (permalink / raw)
  To: emacs-devel


>     (actually, TAB and indent-region produce different results in the
>     last two cases!)

If you look closely before trying to atack my code, this always happened .

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: Indentation of constants in LISP
@ 2007-02-20 15:28 A Soare
  0 siblings, 0 replies; 29+ messages in thread
From: A Soare @ 2007-02-20 15:28 UTC (permalink / raw)
  To: Emacs   Dev  [emacs-devel]

I forgot to check that I am inside a LISP expression in order to make sense to align constant symbols.

Here is a patch that fixes the bug just reported.

Alin Soare

cvs -d:pserver:anonymous@cvs.gnu.org:/sources/emacs diff -c emacs/lisp/emacs-lisp/lisp-mode.el

Index: emacs/lisp/emacs-lisp/lisp-mode.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/emacs-lisp/lisp-mode.el,v
retrieving revision 1.199
diff -c -r1.199 lisp-mode.el
*** emacs/lisp/emacs-lisp/lisp-mode.el  17 Feb 2007 11:34:22 -0000      1.199
--- emacs/lisp/emacs-lisp/lisp-mode.el  20 Feb 2007 15:26:46 -0000
***************
*** 913,919 ****
                   ;; test whether current line begins with a constant
                   (goto-char indent-point)
                   (skip-chars-forward " \t")
!                  (looking-at ":"))
                 (let ((desired-indent
                        (save-excursion
                          (goto-char (1+ containing-sexp))
--- 913,920 ----
                   ;; test whether current line begins with a constant
                   (goto-char indent-point)
                   (skip-chars-forward " \t")
!                  (and (looking-at ":")
!                       containing-sexp))
                 (let ((desired-indent
                        (save-excursion
                          (goto-char (1+ containing-sexp))

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: Indentation of constants in LISP
  2007-02-20 14:14 A Soare
@ 2007-02-20 18:04 ` Stuart D. Herring
  0 siblings, 0 replies; 29+ messages in thread
From: Stuart D. Herring @ 2007-02-20 18:04 UTC (permalink / raw)
  To: alinsoar; +Cc: emacs-devel

> This is not a problem at all, because in this case this old situation is
> also a problem:
>
> (prog2
>     x
>     y
>   z)

How is this a problem?  `prog2' is supposed to indent its first two
arguments specially:

Symbol prog2's plist is
 (lisp-indent-function 2)

>>     (foo :a b :c d
>>               :e f)
>
> This is OK.

Er, what?  Just because two constant-value pairs fit on one line, I don't
follow that we should align everything that follows to the latter.

Davis

-- 
This product is sold by volume, not by mass.  If it appears too dense or
too sparse, it is because mass-energy conversion has occurred during
shipping.

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: Indentation of constants in LISP
@ 2007-02-20 18:23 A Soare
  0 siblings, 0 replies; 29+ messages in thread
From: A Soare @ 2007-02-20 18:23 UTC (permalink / raw)
  To: herring; +Cc: Emacs   Dev  [emacs-devel]



Will you or somebody else be so kind to define some rules in some situations so that sentiment of discontent (mécontentement) dissapear?

This will be much more practical.

Alin Soare.

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: Indentation of constants in LISP
@ 2007-02-20 19:17 A Soare
  2007-02-21  8:38 ` Richard Stallman
  0 siblings, 1 reply; 29+ messages in thread
From: A Soare @ 2007-02-20 19:17 UTC (permalink / raw)
  To: herring; +Cc: Emacs   Dev  [emacs-devel]


> Message du 20/02/07 à 19h04
> De : "Stuart D. Herring" <herring@lanl.gov>
> A : alinsoar@voila.fr
> Copie à : emacs-devel@gnu.org
> Objet : Re: Indentation of constants in LISP
> 
> > This is not a problem at all, because in this case this old situation is
> > also a problem:
> >
> > (prog2
> >     x
> >     y
> >   z)
> 
> How is this a problem?  `prog2' is supposed to indent its first two
> arguments specially:
> 
> Symbol prog2's plist is
>  (lisp-indent-function 2)
> 
> >>     (foo :a b :c d
> >>               :e f)
> >
> > This is OK.
> 
> Er, what?  Just because two constant-value pairs fit on one line, I don't
> follow that we should align everything that follows to the latter.

When I posted it , I wrote:

It's not an exhaustive treatment, because there is not an
exhaustive definition of this kind of alignement. 

When I wrote the code, I supposed that some special commands, like prog2, etc will take CONSTANT symbols as the last parameters, not the first as you write. The constant symbols are special cases. Where in all Emacs do you see a code like that one of which you say here?

First of all look at the code of Emacs. Where, in all thousands of lines of Emacs, do you find a code as you do critique here:

(prog2
    a
 :b
 c

A Soare

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: Indentation of constants in LISP
  2007-02-20 13:29 ` Johan Bockgård
@ 2007-02-21  0:44   ` Richard Stallman
  0 siblings, 0 replies; 29+ messages in thread
From: Richard Stallman @ 2007-02-21  0:44 UTC (permalink / raw)
  To: Johan Bockgård; +Cc: emacs-devel

These problems show that the patch that was installed is no good in
its current form.  We have to revert the change, it unless these
problems are fixed quickly.

However, the idea may still be a good one if it is implemented differently.

	(prog2
	    x
	 :y
	 z)

That doesn't seem like a real case.

	(defcustom var :val
		       :group foo)

The special case check for the second line of a def... form
should override this special case check.

	(foo :a b :c d
		  :e f)

That is a bug, but I tend to think it can be fixed locally.

	(foo a :b c
	     d
	       :e f)

Likewise.  Perhaps the check for a previous keyword should look at
most 2 args back.  Then it would reject this case.

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: Indentation of constants in LISP
@ 2007-02-21  8:32 A Soare
  0 siblings, 0 replies; 29+ messages in thread
From: A Soare @ 2007-02-21  8:32 UTC (permalink / raw)
  To: Emacs   Dev  [emacs-devel]


OK, I will make the patch today.

Alin Soare

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: Indentation of constants in LISP
  2007-02-20 19:17 A Soare
@ 2007-02-21  8:38 ` Richard Stallman
  0 siblings, 0 replies; 29+ messages in thread
From: Richard Stallman @ 2007-02-21  8:38 UTC (permalink / raw)
  To: alinsoar; +Cc: emacs-devel

    First of all look at the code of Emacs. Where, in all thousands of lines of Emacs, do you find a code as you do critique here:

    (prog2
	a
     :b
     c

It is not unreasonable to write a keyword symbol
as the second argument to prog2.  That case should be handled properly.

The way to handle this case properly, and many others too,
is that the special rules for indenting the first two
arguments of prog2 should take precedence over this feature for
keyword symbols.

In fact, it might be ideal if this feature for indenting keywords
applies only when indenting a list whose car is not recognized
as a known function at all.

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: Indentation of constants in LISP
@ 2007-02-21 10:41 A Soare
  2007-02-22 17:21 ` Richard Stallman
  0 siblings, 1 reply; 29+ messages in thread
From: A Soare @ 2007-02-21 10:41 UTC (permalink / raw)
  To: rms; +Cc: Emacs   Dev  [emacs-devel]


> 
> In fact, it might be ideal if this feature for indenting keywords
> applies only when indenting a list whose car is not recognized
> as a known function at all.

In case that the function is not recognized, please somebody tell me what should happen if the previous line is completely commented:

1. to align in the same line with the comment
2. to align to the last previous 2 symbol, if one of them is constant and it lies on the last uncommented line

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: Indentation of constants in LISP
@ 2007-02-21 22:33 A Soare
  0 siblings, 0 replies; 29+ messages in thread
From: A Soare @ 2007-02-21 22:33 UTC (permalink / raw)
  To: Emacs   Dev  [emacs-devel]; +Cc: Richard   Stallman  [rms]

Here is the indentation rewriten, and taking into consideration all problems we have just talked about.

If there are some other new problems, please report.


Alin  Soare


Index: emacs/lisp/emacs-lisp/lisp-mode.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/emacs-lisp/lisp-mode.el,v
retrieving revision 1.199
diff -c -r1.199 lisp-mode.el
*** emacs/lisp/emacs-lisp/lisp-mode.el	17 Feb 2007 11:34:22 -0000	1.199
--- emacs/lisp/emacs-lisp/lisp-mode.el	21 Feb 2007 22:26:09 -0000
***************
*** 908,942 ****
        (let ((normal-indent (current-column)))
          (cond ((elt state 3)
                 ;; Inside a string, don't change indentation.
! 	       nil)
!               ((save-excursion
!                  ;; test whether current line begins with a constant
!                  (goto-char indent-point)
!                  (skip-chars-forward " \t")
!                  (looking-at ":"))
!                (let ((desired-indent
!                       (save-excursion
!                         (goto-char (1+ containing-sexp))
!                         (parse-partial-sexp (point) calculate-lisp-indent-last-sexp 0 t)
!                         (point)))
!                      (parse-sexp-ignore-comments t))
!                  ;; Align a constant symbol under the last constant symbol
!                  (goto-char calculate-lisp-indent-last-sexp)
!                  (while (> (point) desired-indent)
!                    (if (looking-at ":")
!                        (setq desired-indent (point))
!                      (backward-sexp 1))))
!                  (current-column))
                ((and (integerp lisp-indent-offset) containing-sexp)
                 ;; Indent by constant offset
                 (goto-char containing-sexp)
                 (+ (current-column) lisp-indent-offset))
                (desired-indent)
-               ((and (boundp 'lisp-indent-function)
-                     lisp-indent-function
-                     (not retry))
-                (or (funcall lisp-indent-function indent-point state)
-                    normal-indent))
                (t
                 normal-indent))))))
  
--- 908,955 ----
        (let ((normal-indent (current-column)))
          (cond ((elt state 3)
                 ;; Inside a string, don't change indentation.
!                nil)
                ((and (integerp lisp-indent-offset) containing-sexp)
                 ;; Indent by constant offset
                 (goto-char containing-sexp)
                 (+ (current-column) lisp-indent-offset))
+               ((save-excursion
+                  ;; the car must be defined on the same line as the inner parenthesis.
+                  ;; in this case calculate-lisp-indent-last-sexp is not nil.
+                  (and containing-sexp
+                       (goto-char (1+ containing-sexp))
+                       (skip-chars-forward " \t")
+                       (looking-at "\\sw\\|\\s_")))
+                (or
+                 ;; try to align the parameters of a known function
+                 (and (boundp 'lisp-indent-function)
+                      lisp-indent-function
+                      (not retry)
+                      (funcall lisp-indent-function indent-point state))
+                 ;; if not a standard function, try to align a constant-symbol
+                 ;; under the last preceding constant symbol, if there is such one
+                 ;; of the last 2 preceding symbols, in the previous uncommented
+                 ;; line
+                 (and (save-excursion
+                        (goto-char indent-point)
+                        (skip-chars-forward " \t")
+                        (looking-at ":"))
+                      (let ((parse-sexp-ignore-comments t)
+                            indent)
+                        (goto-char calculate-lisp-indent-last-sexp)
+                        (if (looking-at ":")
+                            (setq indent (current-column))
+                          (when (and (> calculate-lisp-indent-last-sexp containing-sexp)
+                                     (< (save-excursion (beginning-of-line) (point))
+                                        (prog2 (backward-sexp) (point))))
+                            (if (looking-at ":")
+                                (setq indent (current-column)))))
+                        indent))
+                 ;; another symbols or constants not preceded by a constant
+                 ;; as defined above.
+                 normal-indent))
+               ;; in this case calculate-lisp-indent-last-sexp is nil
                (desired-indent)
                (t
                 normal-indent))))))

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: Indentation of constants in LISP
  2007-02-20 14:26 A Soare
@ 2007-02-21 22:55 ` Richard Stallman
  0 siblings, 0 replies; 29+ messages in thread
From: Richard Stallman @ 2007-02-21 22:55 UTC (permalink / raw)
  To: alinsoar; +Cc: emacs-devel

    >     (actually, TAB and indent-region produce different results in the
    >     last two cases!)

    If you look closely before trying to atack my code, this always happened .

Is that a bug in Emacs?

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: Indentation of constants in LISP
@ 2007-02-22  2:24 A Soare
  2007-02-22 17:20 ` Richard Stallman
  0 siblings, 1 reply; 29+ messages in thread
From: A Soare @ 2007-02-22  2:24 UTC (permalink / raw)
  To: rms; +Cc: Emacs   Dev  [emacs-devel]

[-- Attachment #1: Type: text/plain, Size: 5629 bytes --]

>     If you look closely before trying to atack my code, this always happened .
> 
> Is that a bug in Emacs?


C'est pas du tout un bug en Emacs, sinon il s'etait fait faire connaitre sans doute par quelqu'un depuis longtemps.

There are simply different definitions. Maybe there was 2 persons: one wrote the indentation for a region, and the other for a line.

The indentation for a region uses from time to time the function which calculates the indentation for a line. Still, it does not call this function for every line. 

Still, indeed, it would have been nice to exist just one definition of indentation. The author of lisp-indent-function is maybe different from the author of indent-sexp, or maybe the same author forgot what he did.

If this is consider a bug, then the only one thing to do is to rewrite completely the function indent-sexp.



I attach here a new patch, because there were 2 things that I do not like in the patch I have just sent.

Now I insert the patch in the text, and I attach it in the same time.


Please consider just this latter patch.


Alin Soare.







Index: emacs/lisp/emacs-lisp/lisp-mode.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/emacs-lisp/lisp-mode.el,v
retrieving revision 1.199
diff -c -r1.199 lisp-mode.el
*** emacs/lisp/emacs-lisp/lisp-mode.el	17 Feb 2007 11:34:22 -0000	1.199
--- emacs/lisp/emacs-lisp/lisp-mode.el	22 Feb 2007 02:21:08 -0000
***************
*** 908,942 ****
        (let ((normal-indent (current-column)))
          (cond ((elt state 3)
                 ;; Inside a string, don't change indentation.
! 	       nil)
!               ((save-excursion
!                  ;; test whether current line begins with a constant
!                  (goto-char indent-point)
!                  (skip-chars-forward " \t")
!                  (looking-at ":"))
!                (let ((desired-indent
!                       (save-excursion
!                         (goto-char (1+ containing-sexp))
!                         (parse-partial-sexp (point) calculate-lisp-indent-last-sexp 0 t)
!                         (point)))
!                      (parse-sexp-ignore-comments t))
!                  ;; Align a constant symbol under the last constant symbol
!                  (goto-char calculate-lisp-indent-last-sexp)
!                  (while (> (point) desired-indent)
!                    (if (looking-at ":")
!                        (setq desired-indent (point))
!                      (backward-sexp 1))))
!                  (current-column))
                ((and (integerp lisp-indent-offset) containing-sexp)
                 ;; Indent by constant offset
                 (goto-char containing-sexp)
                 (+ (current-column) lisp-indent-offset))
                (desired-indent)
-               ((and (boundp 'lisp-indent-function)
-                     lisp-indent-function
-                     (not retry))
-                (or (funcall lisp-indent-function indent-point state)
-                    normal-indent))
                (t
                 normal-indent))))))
  
--- 908,955 ----
        (let ((normal-indent (current-column)))
          (cond ((elt state 3)
                 ;; Inside a string, don't change indentation.
!                nil)
                ((and (integerp lisp-indent-offset) containing-sexp)
                 ;; Indent by constant offset
                 (goto-char containing-sexp)
                 (+ (current-column) lisp-indent-offset))
+               ((save-excursion
+                  ;; the car must be defined on the same line as the inner parenthesis.
+                  ;; in this case calculate-lisp-indent-last-sexp is not nil.
+                  (and containing-sexp
+                       (goto-char (1+ containing-sexp))
+                       (skip-chars-forward " \t")
+                       calculate-lisp-indent-last-sexp))
+                (or
+                 ;; try to align the parameters of a known function
+                 (and (boundp 'lisp-indent-function)
+                      lisp-indent-function
+                      (not retry)
+                      (funcall lisp-indent-function indent-point state))
+                 ;; if not a standard function, try to align a constant-symbol
+                 ;; under the last preceding constant symbol, if there is such one
+                 ;; of the last 2 preceding symbols, in the previous uncommented
+                 ;; line
+                 (and (save-excursion
+                        (goto-char indent-point)
+                        (skip-chars-forward " \t")
+                        (looking-at ":"))
+                 (let ((parse-sexp-ignore-comments t)
+                       indent)
+                   (goto-char calculate-lisp-indent-last-sexp)
+                   (or (and (looking-at ":")
+                            (setq indent (current-column)))
+                       (and (> calculate-lisp-indent-last-sexp containing-sexp)
+                            (< (save-excursion (beginning-of-line) (point))
+                               (prog2 (backward-sexp) (point)))
+                            (looking-at ":")
+                                 (setq indent (current-column))))
+                        indent))
+                 ;; another symbols or constants not preceded by a constant
+                 ;; as defined above.
+                 normal-indent))
+               ;; in this case calculate-lisp-indent-last-sexp is nil
                (desired-indent)
                (t
                 normal-indent))))))
  









[-- Attachment #2: /patch --]
[-- Type: application/octet-stream, Size: 4526 bytes --]

Index: emacs/lisp/emacs-lisp/lisp-mode.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/emacs-lisp/lisp-mode.el,v
retrieving revision 1.199
diff -c -r1.199 lisp-mode.el
*** emacs/lisp/emacs-lisp/lisp-mode.el	17 Feb 2007 11:34:22 -0000	1.199
--- emacs/lisp/emacs-lisp/lisp-mode.el	22 Feb 2007 02:21:08 -0000
***************
*** 908,942 ****
        (let ((normal-indent (current-column)))
          (cond ((elt state 3)
                 ;; Inside a string, don't change indentation.
! 	       nil)
!               ((save-excursion
!                  ;; test whether current line begins with a constant
!                  (goto-char indent-point)
!                  (skip-chars-forward " \t")
!                  (looking-at ":"))
!                (let ((desired-indent
!                       (save-excursion
!                         (goto-char (1+ containing-sexp))
!                         (parse-partial-sexp (point) calculate-lisp-indent-last-sexp 0 t)
!                         (point)))
!                      (parse-sexp-ignore-comments t))
!                  ;; Align a constant symbol under the last constant symbol
!                  (goto-char calculate-lisp-indent-last-sexp)
!                  (while (> (point) desired-indent)
!                    (if (looking-at ":")
!                        (setq desired-indent (point))
!                      (backward-sexp 1))))
!                  (current-column))
                ((and (integerp lisp-indent-offset) containing-sexp)
                 ;; Indent by constant offset
                 (goto-char containing-sexp)
                 (+ (current-column) lisp-indent-offset))
                (desired-indent)
-               ((and (boundp 'lisp-indent-function)
-                     lisp-indent-function
-                     (not retry))
-                (or (funcall lisp-indent-function indent-point state)
-                    normal-indent))
                (t
                 normal-indent))))))
  
--- 908,955 ----
        (let ((normal-indent (current-column)))
          (cond ((elt state 3)
                 ;; Inside a string, don't change indentation.
!                nil)
                ((and (integerp lisp-indent-offset) containing-sexp)
                 ;; Indent by constant offset
                 (goto-char containing-sexp)
                 (+ (current-column) lisp-indent-offset))
+               ((save-excursion
+                  ;; the car must be defined on the same line as the inner parenthesis.
+                  ;; in this case calculate-lisp-indent-last-sexp is not nil.
+                  (and containing-sexp
+                       (goto-char (1+ containing-sexp))
+                       (skip-chars-forward " \t")
+                       calculate-lisp-indent-last-sexp))
+                (or
+                 ;; try to align the parameters of a known function
+                 (and (boundp 'lisp-indent-function)
+                      lisp-indent-function
+                      (not retry)
+                      (funcall lisp-indent-function indent-point state))
+                 ;; if not a standard function, try to align a constant-symbol
+                 ;; under the last preceding constant symbol, if there is such one
+                 ;; of the last 2 preceding symbols, in the previous uncommented
+                 ;; line
+                 (and (save-excursion
+                        (goto-char indent-point)
+                        (skip-chars-forward " \t")
+                        (looking-at ":"))
+                 (let ((parse-sexp-ignore-comments t)
+                       indent)
+                   (goto-char calculate-lisp-indent-last-sexp)
+                   (or (and (looking-at ":")
+                            (setq indent (current-column)))
+                       (and (> calculate-lisp-indent-last-sexp containing-sexp)
+                            (< (save-excursion (beginning-of-line) (point))
+                               (prog2 (backward-sexp) (point)))
+                            (looking-at ":")
+                                 (setq indent (current-column))))
+                        indent))
+                 ;; another symbols or constants not preceded by a constant
+                 ;; as defined above.
+                 normal-indent))
+               ;; in this case calculate-lisp-indent-last-sexp is nil
                (desired-indent)
                (t
                 normal-indent))))))
  

[-- Attachment #3: Type: text/plain, Size: 142 bytes --]

_______________________________________________
Emacs-devel mailing list
Emacs-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-devel

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: Indentation of constants in LISP
@ 2007-02-22  2:53 A Soare
  0 siblings, 0 replies; 29+ messages in thread
From: A Soare @ 2007-02-22  2:53 UTC (permalink / raw)
  To: Emacs   Dev  [emacs-devel]; +Cc: Richard   Stallman  [rms]

I made a new little modification, because I forgot to cut 3 lines before the old (looking-at ).

Please forget about the later patch.




Index: emacs/lisp/emacs-lisp/lisp-mode.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/emacs-lisp/lisp-mode.el,v
retrieving revision 1.199
diff -c -r1.199 lisp-mode.el
*** emacs/lisp/emacs-lisp/lisp-mode.el	17 Feb 2007 11:34:22 -0000	1.199
--- emacs/lisp/emacs-lisp/lisp-mode.el	22 Feb 2007 02:51:26 -0000
***************
*** 908,942 ****
        (let ((normal-indent (current-column)))
          (cond ((elt state 3)
                 ;; Inside a string, don't change indentation.
! 	       nil)
!               ((save-excursion
!                  ;; test whether current line begins with a constant
!                  (goto-char indent-point)
!                  (skip-chars-forward " \t")
!                  (looking-at ":"))
!                (let ((desired-indent
!                       (save-excursion
!                         (goto-char (1+ containing-sexp))
!                         (parse-partial-sexp (point) calculate-lisp-indent-last-sexp 0 t)
!                         (point)))
!                      (parse-sexp-ignore-comments t))
!                  ;; Align a constant symbol under the last constant symbol
!                  (goto-char calculate-lisp-indent-last-sexp)
!                  (while (> (point) desired-indent)
!                    (if (looking-at ":")
!                        (setq desired-indent (point))
!                      (backward-sexp 1))))
!                  (current-column))
                ((and (integerp lisp-indent-offset) containing-sexp)
                 ;; Indent by constant offset
                 (goto-char containing-sexp)
                 (+ (current-column) lisp-indent-offset))
                (desired-indent)
-               ((and (boundp 'lisp-indent-function)
-                     lisp-indent-function
-                     (not retry))
-                (or (funcall lisp-indent-function indent-point state)
-                    normal-indent))
                (t
                 normal-indent))))))
  
--- 908,950 ----
        (let ((normal-indent (current-column)))
          (cond ((elt state 3)
                 ;; Inside a string, don't change indentation.
!                nil)
                ((and (integerp lisp-indent-offset) containing-sexp)
                 ;; Indent by constant offset
                 (goto-char containing-sexp)
                 (+ (current-column) lisp-indent-offset))
+               (calculate-lisp-indent-last-sexp
+                ;; in this case calculate-lisp-indent-last-sexp is not nil.
+                (or
+                 ;; try to align the parameters of a known function
+                 (and (boundp 'lisp-indent-function)
+                      lisp-indent-function
+                      (not retry)
+                      (funcall lisp-indent-function indent-point state))
+                 ;; if not a standard function, try to align a constant-symbol
+                 ;; under the last preceding constant symbol, if there is such one
+                 ;; of the last 2 preceding symbols, in the previous uncommented
+                 ;; line
+                 (and (save-excursion
+                        (goto-char indent-point)
+                        (skip-chars-forward " \t")
+                        (looking-at ":"))
+                 (let ((parse-sexp-ignore-comments t)
+                       indent)
+                   (goto-char calculate-lisp-indent-last-sexp)
+                   (or (and (looking-at ":")
+                            (setq indent (current-column)))
+                       (and (> calculate-lisp-indent-last-sexp containing-sexp)
+                            (< (save-excursion (beginning-of-line) (point))
+                               (prog2 (backward-sexp) (point)))
+                            (looking-at ":")
+                                 (setq indent (current-column))))
+                        indent))
+                 ;; another symbols or constants not preceded by a constant
+                 ;; as defined above.
+                 normal-indent))
+               ;; in this case calculate-lisp-indent-last-sexp is nil
                (desired-indent)
                (t
                 normal-indent))))))

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: Indentation of constants in LISP
@ 2007-02-22 13:29 A Soare
  0 siblings, 0 replies; 29+ messages in thread
From: A Soare @ 2007-02-22 13:29 UTC (permalink / raw)
  To: Emacs   Dev  [emacs-devel]

I simplified the code as much as I could, and I solved a bug from yesterday.

This is a final version I think.




Alin Soare.


Index: emacs/lisp/emacs-lisp/lisp-mode.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/emacs-lisp/lisp-mode.el,v
retrieving revision 1.199
diff -c -r1.199 lisp-mode.el
*** emacs/lisp/emacs-lisp/lisp-mode.el	17 Feb 2007 11:34:22 -0000	1.199
--- emacs/lisp/emacs-lisp/lisp-mode.el	22 Feb 2007 13:27:18 -0000
***************
*** 909,942 ****
          (cond ((elt state 3)
                 ;; Inside a string, don't change indentation.
  	       nil)
-               ((save-excursion
-                  ;; test whether current line begins with a constant
-                  (goto-char indent-point)
-                  (skip-chars-forward " \t")
-                  (looking-at ":"))
-                (let ((desired-indent
-                       (save-excursion
-                         (goto-char (1+ containing-sexp))
-                         (parse-partial-sexp (point) calculate-lisp-indent-last-sexp 0 t)
-                         (point)))
-                      (parse-sexp-ignore-comments t))
-                  ;; Align a constant symbol under the last constant symbol
-                  (goto-char calculate-lisp-indent-last-sexp)
-                  (while (> (point) desired-indent)
-                    (if (looking-at ":")
-                        (setq desired-indent (point))
-                      (backward-sexp 1))))
-                  (current-column))
                ((and (integerp lisp-indent-offset) containing-sexp)
                 ;; Indent by constant offset
                 (goto-char containing-sexp)
                 (+ (current-column) lisp-indent-offset))
                (desired-indent)
-               ((and (boundp 'lisp-indent-function)
-                     lisp-indent-function
-                     (not retry))
-                (or (funcall lisp-indent-function indent-point state)
-                    normal-indent))
                (t
                 normal-indent))))))
  
--- 909,954 ----
          (cond ((elt state 3)
                 ;; Inside a string, don't change indentation.
  	       nil)
                ((and (integerp lisp-indent-offset) containing-sexp)
                 ;; Indent by constant offset
                 (goto-char containing-sexp)
                 (+ (current-column) lisp-indent-offset))
+               ;; in this case calculate-lisp-indent-last-sexp is not nil
+               (calculate-lisp-indent-last-sexp
+                (or
+                 ;; try to align the parameters of a known function
+                 (and (boundp 'lisp-indent-function)
+                      lisp-indent-function
+                      (not retry)
+                      (funcall lisp-indent-function indent-point state))
+                 ;; if not a standard function, try to align a constant-symbol
+                 ;; under the last preceding constant symbol, if there is such one
+                 ;; of the last 2 preceding symbols, in the previous uncommented
+                 ;; line
+                 (and (save-excursion
+                        (goto-char indent-point)
+                        (skip-chars-forward " \t")
+                        (looking-at ":"))
+                      (> calculate-lisp-indent-last-sexp
+                         (save-excursion
+                           (goto-char (1+ containing-sexp))
+                           (parse-partial-sexp (point) calculate-lisp-indent-last-sexp 0 t)
+                           (point)))
+                      (let ((parse-sexp-ignore-comments t)
+                            indent)
+                        (goto-char calculate-lisp-indent-last-sexp)
+                        (or (and (looking-at ":")
+                                 (setq indent (current-column)))
+                            (and (< (save-excursion (beginning-of-line) (point))
+                                    (prog2 (backward-sexp) (point)))
+                                 (looking-at ":")
+                                 (setq indent (current-column))))
+                        indent))
+                 ;; another symbols or constants not preceded by a constant
+                 ;; as defined above.
+                 normal-indent))
+               ;; in this case calculate-lisp-indent-last-sexp is nil
                (desired-indent)
                (t
                 normal-indent))))))

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: Indentation of constants in LISP
  2007-02-22  2:24 A Soare
@ 2007-02-22 17:20 ` Richard Stallman
  0 siblings, 0 replies; 29+ messages in thread
From: Richard Stallman @ 2007-02-22 17:20 UTC (permalink / raw)
  To: alinsoar; +Cc: emacs-devel

    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?

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: Indentation of constants in LISP
  2007-02-21 10:41 A Soare
@ 2007-02-22 17:21 ` Richard Stallman
  0 siblings, 0 replies; 29+ messages in thread
From: Richard Stallman @ 2007-02-22 17:21 UTC (permalink / raw)
  To: alinsoar; +Cc: emacs-devel

    In case that the function is not recognized, please somebody tell
    me what should happen if the previous line is completely
    commented:

    1. to align in the same line with the comment
    2. to align to the last previous 2 symbol, if one of them is constant and it lies on the last uncommented line

It should ignore comments and look at the previous arguments.

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: Indentation of constants in LISP
@ 2007-02-23 15:58 A Soare
  0 siblings, 0 replies; 29+ messages in thread
From: A Soare @ 2007-02-23 15:58 UTC (permalink / raw)
  To: Emacs   Dev  [emacs-devel]

>     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 ).

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

^ permalink raw reply	[flat|nested] 29+ messages in thread

end of thread, other threads:[~2007-02-23 15:58 UTC | newest]

Thread overview: 29+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-02-21  8:32 Indentation of constants in LISP A Soare
  -- strict thread matches above, loose matches on Subject: below --
2007-02-23 15:58 A Soare
2007-02-22 13:29 A Soare
2007-02-22  2:53 A Soare
2007-02-22  2:24 A Soare
2007-02-22 17:20 ` Richard Stallman
2007-02-21 22:33 A Soare
2007-02-21 10:41 A Soare
2007-02-22 17:21 ` Richard Stallman
2007-02-20 19:17 A Soare
2007-02-21  8:38 ` Richard Stallman
2007-02-20 18:23 A Soare
2007-02-20 15:28 A Soare
2007-02-20 14:26 A Soare
2007-02-21 22:55 ` Richard Stallman
2007-02-20 14:14 A Soare
2007-02-20 18:04 ` Stuart D. Herring
2007-02-05 14:33 A Soare
2007-02-05  9:51 A Soare
2007-02-05  7:41 A Soare
2007-02-05 19:06 ` Stefan Monnier
2007-02-04 13:28 A Soare
2007-02-05  0:23 ` Richard Stallman
2007-02-05  1:28 ` Stefan Monnier
2007-02-04 11:37 A Soare
2007-02-02 16:17 A Soare
2007-02-03 11:19 ` Richard Stallman
2007-02-20 13:29 ` Johan Bockgård
2007-02-21  0:44   ` Richard Stallman

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).