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
stardiviner
  • 1,888
  • 26
  • 45
  • Could the downvoter please explain their reason, so the poster can improve the question. – Andrew Swann Mar 08 '15 at 09:59
  • I didn't downvote it, but it's very unclear what this post is asking. – Dan Mar 08 '15 at 12:03
  • @Dan Is the question ask clear now? – stardiviner Mar 08 '15 at 16:16
  • Not much clearer, although it's possible that someone who knows Ruby will understand. – Dan Mar 08 '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? –  Mar 09 '15 at 13:56
  • @stardiviner A lot of context is missing from the Ruby snippet so it's very hard to understand what you want with it. Is this your code? What does it do? Where are you trying to use a value defined in elisp? Please provide a more complete snippet that isn't shortened so much that it doesn't make any sense. –  Mar 09 '15 at 14:00
  • @rekado I add have the original issues link in the post. You should check out the whole story over there. – stardiviner Mar 10 '15 at 08:03
  • @stardiviner The code in your question must not be completely broken or taken out of context. Linking to some github issue is insufficient. As it stands, the question is not at all clear. –  Mar 10 '15 at 08:23
  • From what I understand you don't actually want an Elisp variable to be used in another programme. The Github issue is about making the indentation behaviour (for Ruby code) defined by *Elisp* code configurable with *Elisp*. –  Mar 10 '15 at 08:26
  • Does that means erm indent code through elisp, instead of erm_buffer.rb ? And I should find the way on elisp? – stardiviner Mar 10 '15 at 09:02

1 Answers1

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.

Dmitry
  • 3,508
  • 15
  • 20