0

I want to define a configurable variable in Emacs, but make it can be used in Ruby code.

The situation is like here:

https://github.com/zenspider/enhanced-ruby-mode/pull/68

I copy the content to here:

here is the elisp code that want to define a emacs variable to config the ruby indent for access modifiers (private, public, protected).

(defcustom enh-ruby-outdent-access-modifiers nil
  "*Outdent public/protected/private modifiers if this is non-nil."
  :type 'boolean :group 'enh-ruby)
  (put 'enh-ruby-outdent-access-modifiers 'safe-local-variable 'booleanp)

And here is the ruby code.

when :period then
  add :ident, tok
else
  + indent :s if %w(private protected public).include? tok
  if @ermbuffer.extra_keywords.include? tok then
    add :kw, tok
  else
  • Could the downvoter please explain their reason, so the poster can improve the question. – Andrew Swann Mar 8 '15 at 9:59
  • I didn't downvote it, but it's very unclear what this post is asking. – Dan Mar 8 '15 at 12:03
  • @Dan Is the question ask clear now? – stardiviner Mar 8 '15 at 16:16
  • Not much clearer, although it's possible that someone who knows Ruby will understand. – Dan Mar 8 '15 at 16:31
  • I know Ruby, but the above is not valid Ruby code. The line starting with + indent looks wrong and the whole expression is incomplete (missing end keywords). Where does this snippet come from? What is it supposed to do? – rekado Mar 9 '15 at 13:56
3

The two main options are:

  • Pass the value as an argument, or via standard input. Take a look at how erm-ruby-get-process passes through the value of enh-ruby-extra-keywords.

  • Use an environment variable or several, and set them where you're calling the Ruby process. Maybe let-bind process-environment to itself around that code so it's unchanged in the end (not necessary), and then use setenv before the process call. All that could be done in the same function, erm-ruby-get-process. Then the Ruby code has to fetch the value from ENV, and parse it.

  • I will try this out soon. – stardiviner Mar 10 '15 at 8:05

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.