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?


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))
  • 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 clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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