Re: SMIE: wrote a mode for Roto, stuck on indentation

[email protected]
Newsgroups gmane.emacs.help
Message-ID <[email protected]>
"Zack Weinberg" <[email protected]> writes:

> [1:text/plain Hide]
>
> For the past while I’ve been trying to write a major mode for the Roto
> programming language, which is an embeddable scripting language in the
> same niche as Lua, but with Rust-ish syntax and static typing.  (See
> <https://roto.docs.nlnetlabs.nl/en/stable/>.)  It’s the first time
> I’ve ever tried to write an entire major mode and I’m struggling with
> getting SMIE to do what I want.
>
> I’ve listed the SMIE-related problems I’ve run into below, and I’d
> particularly like any advice you can give me on how to fix them, but
> any other feedback on things that aren’t quite right about the mode
> and/or the Lisp would also be quite welcome.  The .el file is
> attached.
>

You might try using the functions in

   (info "(elisp) SMIE Customization")

1. Starting with emacs -Q and loading your roto-mode.el
source file.

2. Copy your problem code fragments below into the *scratch*
buffer.

3. Position point on a line that is indented incorrectly.

4. Correct the indentation to what you want for that one
line.

6. M-x smie-config-set-indent

7. M-x smie-config-save
   - You will get a prompt: 
     Replace the existing mode’s config? (y or n)

   When you have not yet replaced the existing mode’s config
   (that is, the first time), answer ‘y’.  On subsequent
   config-save’s, answer ‘n’ in order to get the following
   prompt: 
     Merge with existing mode’s config? (y or n)
   and answer ‘y’. Emacs will respond with:
    "Mode rules adjusted in ‘smie-config’"

8. Examine the value of ‘smie-config’ using
      C-h v smie-config

9. Compare the rules in ‘smie-config’ with your code in the
definition of the function ‘roto--smie-rules-function’.  For
example, after the above, one of the rules in ‘smie-config’
for ‘roto-mode’ is (0 :before "test" nil), so when your
function is given the token "test" of kind :before, it
returns nil, when you want it to return 0.

Using this process, above, for each of the indentation
problems and selecting merge, you should be able to resolve
all of the indentation problems and use the value of
‘smie-config’ to adjust your code in ‘roto--smie-rules-function’.

Of course, you can also instrument for Edebug your function
‘roto--smie-rules-function’.  It will be triggered whenever
you press the tab key (for indentation) in a ‘roto-mode’
buffer.  You can then see whether you have accounted for a
given KIND and TOKEN to return the desired value.

-- 
The lyf so short, the craft so long to lerne.
- Geoffrey Chaucer, The Parliament of Birds.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.