• Howto modify syntax entry for "[" and "]" in elisp mode?

    From gjlayde@georgjohann@web.de to gnu.emacs.help on Thu May 4 10:17:24 2023
    From Newsgroup: gnu.emacs.help

    I am using emacs-lisp mode to edit RTL (Register Transfer Language) files. I chose elistp because that's close to RTL.
    Indentation works fine, except when I have to break very long lines. Suppose the following example:
    [(set (pc)
    (if_then_else
    (match_operator 0 "ordered_comparison_operator"
    [(match_operand:PSI 1 "register_operand" "r,r,d ,r ,d,r")
    (match_operand:PSI 2 "nonmemory_operand" "L,r,s ,s ,M,n")])
    (label_ref (match_operand 3 "" ""))
    (pc)))
    (clobber (match_scratch:QI 4 "=X,X,&d,&d ,X,&d"))]
    What I want is that "[" and "]" basically behave like "(" and ")". In particular, it appears that indentation of the line starting with "[" is far too much and aligns with the next space in the line above.
    So "[" whould indent a fixed amout compared to the line above it.
    So I have 2 problems to solve:
    1) Tell emacs that "[" and "]" are brackets.
    2) Tell emacs to indent according to some value like "2" or "3".
    I fount https://www.gnu.org/software/emacs/manual/html_node/elisp/Syntax-Table-Functions.html which explains how to change the syntax entry for symbols, and hence I added the following code to my elisp hook:
    (defun my-lisp-mode-hook ()
    (setq indent-tabs-mode nil)
    ;; Make rCy[rCO an open parenthesis character, with rCy]rCO as its matching close.
    (modify-syntax-entry ?[ "(]")
    ;; Make rCy]rCO a close parenthesis character, with rCy$rCO as its matching open.
    (modify-syntax-entry ?] ")[")
    )
    (add-hook 'emacs-lisp-mode-hook 'my-lisp-mode-hook)
    This has no effect at all, so I'd greatly appreciate some help how to get the indentations right.
    --- Synchronet 3.21d-Linux NewsLink 1.2
  • From Ben Bacarisse@ben.usenet@bsb.me.uk to gnu.emacs.help on Thu May 4 20:48:55 2023
    From Newsgroup: gnu.emacs.help

    gjlayde <georgjohann@web.de> writes:

    I am using emacs-lisp mode to edit RTL (Register Transfer Language)
    files. I chose elistp because that's close to RTL.

    Indentation works fine, except when I have to break very long
    lines. Suppose the following example:

    [(set (pc)
    (if_then_else
    (match_operator 0 "ordered_comparison_operator"
    [(match_operand:PSI 1 "register_operand" "r,r,d ,r ,d,r")
    (match_operand:PSI 2 "nonmemory_operand" "L,r,s ,s ,M,n")])
    (label_ref (match_operand 3 "" ""))
    (pc)))
    (clobber (match_scratch:QI 4 "=X,X,&d,&d ,X,&d"))]

    What I want is that "[" and "]" basically behave like "(" and ")".

    In my emacs-lisp-mode, [ and ] already behave like ( and ) because []s
    are used for vectors and must nest correctly with ()s.

    In particular, it appears that indentation of the line starting with
    "[" is far too much and aligns with the next space in the line above.

    ( does this as well as [. The arguments in a form are lined up with
    each other:

    (a b
    c
    (d e))
    [a b
    c
    [d e]]

    Otherwise one space indent is used:

    (a
    b
    c
    (d
    e))
    [a
    b
    c
    [d
    e]]

    (I am ignoring the special case of (def... forms that indent the second
    line by an amount you can set).

    So "[" whould indent a fixed amout compared to the line above it.

    You could maybe write a indent function which you then use by setting
    the variable 'lisp-indent-function' but I can imagine that gets a bit
    fussy.
    --
    Ben.
    --- Synchronet 3.21d-Linux NewsLink 1.2
  • From gjlayde@georgjohann@web.de to gnu.emacs.help on Thu May 4 13:12:08 2023
    From Newsgroup: gnu.emacs.help

    Ben Bacarisse schrieb am Donnerstag, 4. Mai 2023 um 21:51:06 UTC+2:
    gjlayde <georg...@web.de> writes:

    I am using emacs-lisp mode to edit RTL (Register Transfer Language)
    files. I chose elistp because that's close to RTL.

    Indentation works fine, except when I have to break very long
    lines. Suppose the following example:

    [(set (pc)
    (if_then_else
    (match_operator 0 "ordered_comparison_operator"
    [(match_operand:PSI 1 "register_operand" "r,r,d ,r ,d,r") (match_operand:PSI 2 "nonmemory_operand" "L,r,s ,s ,M,n")])
    (label_ref (match_operand 3 "" ""))
    (pc)))
    (clobber (match_scratch:QI 4 "=X,X,&d,&d ,X,&d"))]

    What I want is that "[" and "]" basically behave like "(" and ")".
    In my emacs-lisp-mode, [ and ] already behave like ( and ) because []s
    are used for vectors and must nest correctly with ()s.
    In particular, it appears that indentation of the line starting with
    "[" is far too much and aligns with the next space in the line above.
    ( does this as well as [. The arguments in a form are lined up with
    each other:

    Your examples are indented fine.

    But in a simple example like
    (aaaaaaaaaaaaa b
    [c d])

    The "[" is aligned with "b", thus the indentation of the 2nd line is arbitrarily far to the right, and breaking lines does (almost) not lead to shorter lines.

    I'd like to indent "[" with the 1st or second letter of "aaaaaaaaaaa".

    --- Synchronet 3.21d-Linux NewsLink 1.2
  • From Ben Bacarisse@ben.usenet@bsb.me.uk to gnu.emacs.help on Fri May 5 00:44:50 2023
    From Newsgroup: gnu.emacs.help

    gjlayde <georgjohann@web.de> writes:

    Ben Bacarisse schrieb am Donnerstag, 4. Mai 2023 um 21:51:06 UTC+2:
    gjlayde <georg...@web.de> writes:

    I am using emacs-lisp mode to edit RTL (Register Transfer Language)
    files. I chose elistp because that's close to RTL.

    Indentation works fine, except when I have to break very long
    lines. Suppose the following example:

    [(set (pc)
    (if_then_else
    (match_operator 0 "ordered_comparison_operator"
    [(match_operand:PSI 1 "register_operand" "r,r,d ,r ,d,r")
    (match_operand:PSI 2 "nonmemory_operand" "L,r,s ,s ,M,n")])
    (label_ref (match_operand 3 "" ""))
    (pc)))
    (clobber (match_scratch:QI 4 "=X,X,&d,&d ,X,&d"))]

    What I want is that "[" and "]" basically behave like "(" and ")".
    In my emacs-lisp-mode, [ and ] already behave like ( and ) because []s
    are used for vectors and must nest correctly with ()s.
    In particular, it appears that indentation of the line starting with
    "[" is far too much and aligns with the next space in the line above.
    ( does this as well as [. The arguments in a form are lined up with
    each other:

    Your examples are indented fine.

    Well, no, not really! I had intended them to explain the problem so you
    had something more concrete to explore (I have no solution for you). I
    was illustrating the "align arguments in forms" pattern but I just
    happened to use short symbols.

    But in a simple example like
    (aaaaaaaaaaaaa b
    [c d])

    Yes, that's the case I showed only with a sorter symbol in the first
    position. I thought you already knew that the indentation was based on
    the length of that symbol. I was just explaining that the mode is
    trying to line up function arguments.

    If you break after aaaaaaaaaaaaa, you won't get that layout, but that's
    not the solution you want either. You want a simple l*n indent where l
    is the nesting level and n is something small you can choose: 1, 2 or 3
    maybe.

    The "[" is aligned with "b", thus the indentation of the 2nd line is arbitrarily far to the right, and breaking lines does (almost) not
    lead to shorter lines.

    I'd like to indent "[" with the 1st or second letter of "aaaaaaaaaaa".

    Yes, I know. I think you will have to define an indent function as I
    said. But that is not going to be easy. You'll have to find some documentation to help you. I tried a simple case, but it did not work
    as I had hoped.
    --
    Ben.
    --- Synchronet 3.21d-Linux NewsLink 1.2