[-- Attachment #1: Type: text/plain, Size: 717 bytes --] I'm trying to set this ╭──── │C-x RET r utf-8 RET ╰──── as "C-x zx" as I'm finding that I need to use this block-quoted command fairly regularly for some unknown reason. I have set it as --8<---------------cut here---------------start------------->8--- #+BEGIN_SRC emacs-lisp (global-set-key (kbd "C-x zx") 'r utf8) #+END_SRC --8<---------------cut here---------------end--------------->8--- but the system rejects it as the "utf8" stage. How can I set it please? Thanks Sharon. -- A taste of linux = http://www.sharons.org.uk my git repo = https://bitbucket.org/boudiccas/dots TGmeds = http://www.tgmeds.org.uk Debian testing, fluxbox 1.3.5, emacs 24.4.1.0 [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 818 bytes --]
Sharon Kimble <boudiccas@skimble.plus.com> writes:
> I'm trying to set this
>
> ╭────
> │C-x RET r utf-8 RET
> ╰────
>
> as "C-x zx" as I'm finding that I need to use this block-quoted
> command fairly regularly for some unknown reason.
>
> I have set it as
>
> #+BEGIN_SRC emacs-lisp
> (global-set-key (kbd "C-x zx") 'r utf8)
> #+END_SRC
>
> but the system rejects it as the "utf8" stage.
You've got a small confusion here between "key sequence" and "command
name". Up at the top, you're typing in the key sequence "C-x RET r".
That key sequence calls the command `revert-buffer-with-coding-system'.
You can verify this by using "C-h c" (for describe-key-briefly) and then
typing "C-x RET r". Or, the other way around, by typing "C-h w" (for
where-is), then "revert-buffer-with-coding-system".
When you set your global keys, the key sequence needs to point at a
_command_, not at more keys. We already know what the command name is,
so it will look like:
(global-set-key (kbd "C-x zx") 'revert-buffer-with-coding-system)
But that doesn't include the utf-8 part: using this key sequence will
still prompt you for a coding system. You could do that in a lambda, but
it probably won't accept a non-interactive function, so you'll likely
want something a little more complicated:
(defun my-set-coding-system-to-utf8 ()
(interactive)
(revert-buffer-with-coding-system 'utf-8))
(global-set-key (kbd "C-x zx") 'my-set-coding-system-to-utf8)
Give that a shot!
Note that the coding system specified is the symbol 'utf-8. It needs to
be quoted, and it needs to have the hyphen. I have more than once tried
to set my coding systems to 'utf8, to no avail.
Yours,
Eric
On 2014-12-08, at 08:35, Eric Abrahamsen wrote: > [...] You could do that in a lambda, but > it probably won't accept a non-interactive function, [...] Out of curiosity: can't a lambda (in e.g. global-set-key) be made interactive? I did this right now: (global-set-key (kbd "C-z C-s") (lambda () (interactive) (message "It can be done!"))) and it seems to work. Is it going to change e.g. in future Emacs versions, IOW, is it deprecated or something? > Yours, > Eric Best, -- Marcin Borkowski http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski Faculty of Mathematics and Computer Science Adam Mickiewicz University
Marcin Borkowski <mbork@wmi.amu.edu.pl> writes:
> On 2014-12-08, at 08:35, Eric Abrahamsen wrote:
>
>> [...] You could do that in a lambda, but
>> it probably won't accept a non-interactive function, [...]
>
> Out of curiosity: can't a lambda (in e.g. global-set-key) be made
> interactive? I did this right now:
>
> (global-set-key (kbd "C-z C-s") (lambda () (interactive) (message "It can be done!")))
>
> and it seems to work. Is it going to change e.g. in future Emacs
> versions, IOW, is it deprecated or something?
No, you're quite right, I was just answering off the cuff, without
thorough thought. It is indeed possible to stick (interactive) inside of
a lambda, though intuition tells me that that it's not generally good
practice -- Emacs' introspection functions will probably at some point
bark at you for not having a named function, and it will make it harder
to use the built-in help functions to figure out what's going on. But
yes, you're right, it's definitely possible.
E
On 2014-12-08, at 10:39, Eric Abrahamsen wrote: > No, you're quite right, I was just answering off the cuff, without > thorough thought. It is indeed possible to stick (interactive) inside of > a lambda, though intuition tells me that that it's not generally good > practice -- Emacs' introspection functions will probably at some point > bark at you for not having a named function, and it will make it harder > to use the built-in help functions to figure out what's going on. But > yes, you're right, it's definitely possible. You're probably right - describe-key works (of course), but in an ideal way (somehow jumping to the source won't work;-) - but a docstring will!). > E Best. -- Marcin Borkowski http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski Faculty of Mathematics and Computer Science Adam Mickiewicz University
[-- Attachment #1: Type: text/plain, Size: 443 bytes --] Thanks for this Eric, I’ve put your function [my-set-coding-system-to-utf8] into my "init.org" and also my mono menu. Unfortunately I had just converted my last two problem pages into utf8, but I'm now ready for its next bout. Thanks again Sharon. -- A taste of linux = http://www.sharons.org.uk my git repo = https://bitbucket.org/boudiccas/dots TGmeds = http://www.tgmeds.org.uk Debian testing, fluxbox 1.3.5, emacs 24.4.1.0 [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 818 bytes --]