DEV Community

Cover image for My EMACS Custom Indent Function Uses 'tab-width'
Michael
Michael

Posted on

My EMACS Custom Indent Function Uses 'tab-width'

I think image came from here: https://github.com/jcsalomon/smarttabs

I have been investing a guilty amount of time customizing my EMACS init config lately. It began with trying to understand more iterative processes in Elisp, so I read up on loops; most of which are simple examples, but I am a bit proud of what I was able to work on just now.

So I am trying to get the Aggressive Indent package to use 2 spaces for indentation - A.I. uses the local mode indent width - which is not that difficult, but as I dedicate a section of my init to setting these widths I thought I should at least update the custom indent function I had. It was a custom interactive function I mapped to my space key that insert(s) two spaces for quick indentation. I used this to quickly indent my code (enter+space or beginning-of-line+space). A horrible process! Anyway now it uses a while loop and the global tab-width variable to insert spaces.

; Previously
;(defun space-times-2 ()
(defun insert-space-indent ()
  (interactive)
  (setq scoped-indent-width tab-width)
  (while (> scoped-indent-width 0)
    (insert " ")
    (setq scoped-indent-width (- scoped-indent-width 1))
  )
)
Enter fullscreen mode Exit fullscreen mode

I thought this was exciting, learning Elisp here and there, it's a very different syntax to the web languages. If this is interesting or helpful I'll share more of Elisp/EMACS stuff I've been learning.

#candevtobemytwitter

Top comments (0)