Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I predominantly use emacs for editing my Puppet configuration files. I use the following settings in my .emacs to load Ruby mode and use it for Puppet config files (*.pp):

(autoload 'ruby-mode "ruby-mode" "Major mode for editing ruby scripts." t)
(setq auto-mode-alist  (cons '(".rb$" . ruby-mode) auto-mode-alist))
(setq auto-mode-alist  (cons '(".pp$" . ruby-mode) auto-mode-alist))

This works well except for the the indentation of the 'ensure' directive in my puppet files. Because ensure is a reserved word in Ruby, it outdents it:

cron { logrotate:
  command => "/usr/sbin/logrotate",
  user => root,
  hour => 2,
ensure => present
  minute => 0,

How do I tell Emacs to not treat ensure specially in Puppet files?

share|improve this question
up vote 1 down vote accepted

I think the simplest way to handle this is to just copy ruby-mode.el to puppet-mode.el and rip out all the places you see it handling ensure specially. In my ruby-mode.el, this seems to only happen in two places:

  1. Where the block words are defined

    (defconst ruby-block-mid-keywords
      '("then" "else" "elsif" "when" "rescue" "ensure")
      "Keywords where the indentation gets shallower in middle of block statements.")
  2. Where reserved words are defined:

    (defconst ruby-font-lock-keywords

I bet deleting ensure from those two places, saving as puppet-mode.el and then changing your .emacs to this would do the trick:

(autoload 'puppet-mode "puppet-mode" "Major mode for editing Puppet config" t)
(setq auto-mode-alist  (cons '(".pp$" . puppet-mode) auto-mode-alist))
share|improve this answer
This worked well. I wasn't very happy with the emacs-puppet module available and this worked well. I also needed to do a replace-string for 'ruby-mode' / 'puppet-mode' in order to make this function as desired. – Tim Brigham Apr 29 '12 at 2:07

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.