francogarcia / godot-gdscript.el

Major mode for editing Godot Engine GDScript files with Emacs.
GNU General Public License v3.0
51 stars 9 forks source link

Change to godot style tabs indentation #3

Closed tavurth closed 6 years ago

tavurth commented 6 years ago

These are probably nicer defaults, which allow for simpler integration with the main godot process.

Is there a way to set these directly from ones ~/.spacemacs or ~/.emacs file?

francogarcia commented 6 years ago

Hello, @tavurth , How are you?

Thank you for your contribution. Although I personally prefer indenting with spaces, I agree with your reasoning.

Is there a way to set these directly from ones ~/.spacemacs or ~/.emacs file?

Sure. A benefit of Emacs is that customizing your profile also uses Emacs Lisp; therefore, you can add the same commands used to extended it to persist them into your profile. For programming languages, you will probably want to register these changes to the mode's hook, to avoid making the change globally. If you are using Spacemacs, you have use-package installed. To set-up the mode, you can do something like (in this example, I reverted it back to my preferred 4 spaces indenting):

(use-package godot-gdscript
    :mode ("\\.gd\\'" . godot-gdscript-mode)
    :defer t
    :init
    (progn
      (defun franco/godot-gdscript-mode-default-settings ()
        (setq indent-tabs-mode nil
              tab-width 4)
        ;; Make C-j work the same way as RET.
        (local-set-key (kbd "C-j") 'newline-and-indent))

      (spacemacs/add-all-to-hook 'godot-gdscript-mode-hook
                                 'franco/godot-gdscript-mode-default-settings)))

Another option is adding a lambda function directly to the mode's hook (which also works without use-package).

Best regards, Franco

tavurth commented 6 years ago

I also prefer spaces, although here I'm willing to compromise with godot as it's easier than having to run tabify every time I generate a new script, or link a function in the editor.

Thank you for the code snippet! I'll put something similar in my ~/.spacemacs