Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support SMIE (Emacs 24.4) #14

Closed
PythonNut opened this issue Nov 29, 2014 · 7 comments
Closed

Support SMIE (Emacs 24.4) #14

PythonNut opened this issue Nov 29, 2014 · 7 comments

Comments

@PythonNut
Copy link

Many Emacs 24.4 major modes are now using SMIE, a parser that improves automatic indentation and indentation based navigation. Many minor modes have switched to using it instead of the normal indentation variables, which breaks dtrt-indent in sh-mode for example.

@PythonNut
Copy link
Author

In fact, this would be trivial. All you need to do is detect if SMIE is supported and fire off a (smie-config-guess).
Here's a snippet from my init.el:

(defun smie-auto-guess ()
  (when (featurep 'smie)
    (unless (eq smie-grammar 'unset)
      (smie-config-guess))))

(add-hook 'after-change-major-mode-hook 'smie-auto-guess)

@PythonNut PythonNut reopened this Dec 2, 2014
rrthomas added a commit that referenced this issue Aug 25, 2017
In dtrt-indent-find-file-hook, if we have SMIE and the current mode supports
it, use smie-config-guess. Otherwise, fall back to
dtrt-indent-try-set-offset as normal.

Thanks to @PythonNut for example code.
@rrthomas
Copy link
Collaborator

rrthomas commented Aug 25, 2017

I believe this now works: dtrt-indent-find-file-hook now uses smie-config-guess if SMIE is available and the mode supports it. I have tested this with sh-mode (for bug #31), but would appreciate some confirmation that it works before I make a new release.

Thanks @PythonNut for the bug report and example code.

@jgeerds
Copy link

jgeerds commented Aug 25, 2017

Thanks @rrthomas ! I've also tested it with sh-mode and it works fine for me.

TBH, I don't understand how smie works. Let's take the following file as an example:

test_function() {
    if test; then
        echo lol
    fi
}

Indentation works fine with your recent changes, but sh-basic-offset and sh-indentation are set to 2 (and not 4). I guess smie uses a different variable for this. Let's say I want to change the indentation from 4 to 2 and indent-region the whole buffer. How can I do that? Changing sh-indentation, sh-basic-offset and smie-indent-basic make no difference.

@rrthomas
Copy link
Collaborator

Thanks for confirming. Good luck sussing out SMIE; I don't know much about it either.

@hrehfeld
Copy link

I still run into this, whenever a css-mode file is in the desktop file -- seems related. Reopen?

Debugger entered--Lisp error: (wrong-type-argument number-or-marker-p nil)
  smie-next-sexp(#f(compiled-function () #<bytecode 0xd5cec9>) #f(compiled-function (n) #<bytecode 0x1b0d2f9>) #<subr car> #f(compiled-function (x) "Return the car of the cdr of X." #<bytecode 0x1a49b3>) "}")
  smie-backward-sexp("}")
  smie-indent-keyword()
  run-hook-with-args-until-success(smie-indent-keyword)
  smie-indent-calculate()
  smie-config--get-trace()
  smie-config--guess(1 6439)
  smie-config-guess()
  dtrt-indent-mode(t)
  (lambda nil (dtrt-indent-mode t))()
  run-hooks(change-major-mode-after-body-hook prog-mode-hook css-mode-hook)
  apply(run-hooks (change-major-mode-after-body-hook prog-mode-hook css-mode-hook))
  run-mode-hooks(css-mode-hook)
  css-mode()
  set-auto-mode-0(css-mode nil)
  set-auto-mode()
  normal-mode(t)
  after-find-file(nil nil)
  find-file-noselect-1(#<buffer style.css> "style.css" :nowarn nil "style.css" (1738062 66309))
  find-file-noselect("style.css" :nowarn)
  desktop-restore-file-buffer("style.css" "style.css" nil)
  desktop-create-buffer(208 "style.css" "style.css" css-mode nil 1 (nil nil) nil nil ((tab-width . 4) (indent-tabs-mode . t) (buffer-display-time) (buffer-file-coding-system . utf-8-unix)) ((mark-ring nil)))
  eval-buffer(#<buffer  *load*> nil ".desktop" nil t)  ; Reading at buffer position 140676
  load-with-code-conversion(".desktop" ".desktop" t t)
  load(".desktop" t t t)
  desktop-read()

@rrthomas
Copy link
Collaborator

@hrehfeld as far as I can tell, you're experiencing a problem with CSS mode and desktop.el when you have dtrt-indent active? (I made a quick test, of opening a CSS file, quitting Emacs and restarting; the css-mode buffer was loaded fine by desktop.el with no error.) That's not the same as this issue (which was a request for SMIE support), so please file a new issue, with a way to repro and some evidence that the problem is caused by dtrt.

@hrehfeld
Copy link

Will try, but time is limited atm, currently i'm just not using dtrt-indent on css-mode as a quick workaround.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants