I want to chnage input method by M-x ru. But I couldn't figure out how to alias a function with argument.

This is what I tried:

(defalias 'ru '(set-input-method russian-computer))

How can I alias a function with argument?


defalias creates named aliases for functions, so you must start with a function before you can create an alias for it; and you are starting with a call to a function.

So you could write a function which does what you want, and then create an alias to that function. You can even use an anonymous function, in order to avoid creating two names when you only wanted one:

(defalias 'ru (lambda ()
                "Use the russian-computer input method."
                (set-input-method 'russian-computer)))

However that is the same thing as this:

(defun ru ()
  "Use the russian-computer input method."
  (set-input-method 'russian-computer))

Which is what I suggest you actually use.

  • 1
    So in this case it's more simple to write with 'defun'. thanks! – ironsand Jun 20 '16 at 12:31

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.