Skip to content

moved ruby's electric indent to lua-mode #112

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

moved ruby's electric indent to lua-mode #112

wants to merge 1 commit into from

Conversation

ngzh
Copy link

@ngzh ngzh commented Dec 10, 2015

Copied from ruby-mode.el

now, when typing a closing token like end, an automatically reindent
will be performed. it also works for else elseif until. (I did a quick
scan on lua syntax, described in lua manual and don't think there will be
more keyword which trigger a reindent)

example:

1 function foo()              1 function foo()
2     return "foo"            2    return "foo"
3     en                      3 end
        ^ type 'd' here will cause ^ to reindent

I'm been using this for almost a month and everything seems to be ok, though in fact I'm not very familiar with elisp, so better have a look at the code and do some extra test.

now, when typing a closing token like _end_, an automatically reindent
will be performed. it also works for _else_  _elseif_  _until_

function foo()
    ...
    en
end<-

in the above example, typing 'd' will invoke the automatically reindent
@immerrr
Copy link
Owner

immerrr commented Dec 10, 2015

Hi and thank you for the PR.

Electric indentation of block closing tokens is already implemented via abbrev-mode, see lua-mode-abbrev-table as well as lua-electric-flag variable. That being said, there were plans of migrating to electric-indent infrastructure, but unfortunately that is only available since emacs-24.4 and some still use older versions.

If you don't mind doing some refactoring to select the one that is appropriate for the running version of emacs on top of your slightly adapted copy-n-paste, I'll gladly accept that.

@ngzh
Copy link
Author

ngzh commented Dec 10, 2015

Thanks for your quick reply.

I'm using emacs 24.5 actually, so I guess there may be some surprise for me since electric indent doesn't work for me out of the box(I've tried toggle lua-toggle-electric-state but didn't see any difference)

And as for the code I copied, I'll try to make them clean to provide those who need a fallback. Got to learn something but that will be OK, just need some time.

@immerrr
Copy link
Owner

immerrr commented Dec 10, 2015

@fangzhouuu you might need to enable abbrev-mode, it got disabled by default in one of the recent releases

@ngzh
Copy link
Author

ngzh commented Dec 11, 2015

Well I've enable abbrev-mode but it still not working for end else elseif(works for brackets). It could be the the effect of other package since I copied a huge bunch of code in my config file. I might have to setup a clean emacs dev envirnoment using a VM or a docker container.

@immerrr
Copy link
Owner

immerrr commented Dec 11, 2015

You can do emacs -Q -l path/to/lua-mode.el to try out a fresh emacs env.

If you have cask, you can use make tryout command from lua-mode directory.

@immerrr
Copy link
Owner

immerrr commented Dec 11, 2015

Also, there are tests for electric indentation functionality:

(it "works with end"
(with-lua-buffer
(execute-kbd-macro (kbd "if SPC foo SPC then M-j"))
(execute-kbd-macro (kbd "'baz' M-j"))
(should (eq (current-indentation) lua-indent-level))
(abbrev-mode 1)
(execute-kbd-macro (kbd "end M-j"))
(beginning-of-line 0)
(should (eq (current-indentation) 0))))
(it "works with else"
(with-lua-buffer
(execute-kbd-macro (kbd "if SPC foo SPC then M-j"))
(execute-kbd-macro (kbd "'baz' M-j"))
(should (eq (current-indentation) lua-indent-level))
(abbrev-mode 1)
(execute-kbd-macro (kbd "else M-j"))
(beginning-of-line 0)
(should (eq (current-indentation) 0))))
(it "works with elseif"
(with-lua-buffer
(execute-kbd-macro (kbd "if SPC foo SPC then"))
(newline-and-indent)
(execute-kbd-macro (kbd "'baz'"))
(newline-and-indent)
(should (eq (current-indentation) lua-indent-level))
(abbrev-mode 1)
(execute-kbd-macro (kbd "elseif"))
(newline-and-indent)
(beginning-of-line 0)
(should (eq (current-indentation) 0)))))

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

Successfully merging this pull request may close these issues.

2 participants