DEV Community

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

Posted on

2

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

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (0)

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay