all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* don't hard-code keys
@ 2021-05-01 22:35 Emanuel Berg via Users list for the GNU Emacs text editor
  2021-05-02  7:13 ` Tassilo Horn
  0 siblings, 1 reply; 6+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-05-01 22:35 UTC (permalink / raw)
  To: help-gnu-emacs

Here are two interesting functions for several reasons...

But the question: how can I avoid hard-coding the C-u key but
instead have the keybinding inserted thru a reference to the
function, i.e. `universal-argument'?

I don't plan to rebind C-u and/or use something else for
universal-argument, rather I'd like to just not have the C-u
hard-coded for personal/political reasons.

(defun open-irc (&optional connect)
  (interactive "P")
  (let ((irc-buffer (car (erc-buffer-list))))
    (if irc-buffer
        (progn
          (switch-to-buffer irc-buffer)
          (erc-scroll-to-bottom-no-blanks))
      (if connect
          (irc-connect-to-all)
        (message "did nothing, C-u to connect") )))) ; [1]

(defun new-message (&optional force)
  (interactive "P")
  (message (format "%s" force))
  (if (or (not (eq major-mode 'message-mode)) force)
      (progn
        (unless (gnus-alive-p) (gnus))
        (gnus-post-news 'post "") )
    (message "did nothing, C-u to force") )) ; [2]

[1] https://dataswamp.org/~incal/emacs-init/erc-incal.el
[2] https://dataswamp.org/~incal/emacs-init/gnus/gnus-incal.el

-- 
underground experts united
https://dataswamp.org/~incal




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: don't hard-code keys
  2021-05-01 22:35 don't hard-code keys Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-05-02  7:13 ` Tassilo Horn
  2021-05-02 14:44   ` Emanuel Berg via Users list for the GNU Emacs text editor
  0 siblings, 1 reply; 6+ messages in thread
From: Tassilo Horn @ 2021-05-02  7:13 UTC (permalink / raw)
  To: help-gnu-emacs

Emanuel Berg via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org> writes:

> But the question: how can I avoid hard-coding the C-u key but
> instead have the keybinding inserted thru a reference to the
> function, i.e. `universal-argument'?

You mean, in the `message' call?  Have a look at

  (info "(elisp) Keys in Documentation")

HTH,
Tassilo



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: don't hard-code keys
  2021-05-02  7:13 ` Tassilo Horn
@ 2021-05-02 14:44   ` Emanuel Berg via Users list for the GNU Emacs text editor
  2021-05-02 17:28     ` Thibaut Verron
  0 siblings, 1 reply; 6+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-05-02 14:44 UTC (permalink / raw)
  To: help-gnu-emacs

Tassilo Horn wrote:

>> But the question: how can I avoid hard-coding the C-u key
>> but instead have the keybinding inserted thru a reference
>> to the function, i.e. `universal-argument'?
>
> You mean, in the `message' call?  Have a look at
>
>   (info "(elisp) Keys in Documentation")

I have it working in docstrings but not in general, for
example this

  ‘\[COMMAND]’
       stands for a key sequence that will invoke COMMAND, or ‘M-x
       COMMAND’ if COMMAND has no key bindings.

sounds like what I want but

  (substitute-command-keys "\[universal-argument]")

:(

-- 
underground experts united
https://dataswamp.org/~incal




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: don't hard-code keys
  2021-05-02 14:44   ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-05-02 17:28     ` Thibaut Verron
  2021-05-02 17:33       ` Emanuel Berg via Users list for the GNU Emacs text editor
  0 siblings, 1 reply; 6+ messages in thread
From: Thibaut Verron @ 2021-05-02 17:28 UTC (permalink / raw)
  To: Emanuel Berg, help-gnu-emacs

On Sun, 2 May 2021, 16:48 Emanuel Berg via Users list for the GNU Emacs
text editor, <help-gnu-emacs@gnu.org> wrote:

> Tassilo Horn wrote:
>
> >> But the question: how can I avoid hard-coding the C-u key
> >> but instead have the keybinding inserted thru a reference
> >> to the function, i.e. `universal-argument'?
> >
> > You mean, in the `message' call?  Have a look at
> >
> >   (info "(elisp) Keys in Documentation")
>
> I have it working in docstrings but not in general, for
> example this
>
>   ‘\[COMMAND]’
>        stands for a key sequence that will invoke COMMAND, or ‘M-x
>        COMMAND’ if COMMAND has no key bindings.
>
> sounds like what I want but
>
>   (substitute-command-keys "\[universal-argument]")
>
> :(
>

You need to escape the backslash, otherwise \[ just becomes [ in the
string.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: don't hard-code keys
  2021-05-02 17:28     ` Thibaut Verron
@ 2021-05-02 17:33       ` Emanuel Berg via Users list for the GNU Emacs text editor
  2021-05-02 17:38         ` Emanuel Berg via Users list for the GNU Emacs text editor
  0 siblings, 1 reply; 6+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-05-02 17:33 UTC (permalink / raw)
  To: help-gnu-emacs

Thibaut Verron wrote:

>>   ‘\[COMMAND]’
>>        stands for a key sequence that will invoke COMMAND, or ‘M-x
>>        COMMAND’ if COMMAND has no key bindings.
>>
>> sounds like what I want but
>>
>>   (substitute-command-keys "\[universal-argument]")
>>
>> :(
>
> You need to escape the backslash, otherwise \[ just becomes
> [ in the string.

Wo-ho! 

  (substitute-command-keys "\\[universal-argument]") ; C-u

:)

-- 
underground experts united
https://dataswamp.org/~incal




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: don't hard-code keys
  2021-05-02 17:33       ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-05-02 17:38         ` Emanuel Berg via Users list for the GNU Emacs text editor
  0 siblings, 0 replies; 6+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-05-02 17:38 UTC (permalink / raw)
  To: help-gnu-emacs

> Wo-ho! 
>
>   (substitute-command-keys "\\[universal-argument]") ; C-u
>
> :)

Stuff is in place, works fine:

(defun open-irc (&optional connect)
  (interactive "P")
  (let ((irc-buffer (car (erc-buffer-list))))
    (if irc-buffer
        (progn
          (switch-to-buffer irc-buffer)
          (erc-scroll-to-bottom-no-blanks))
      (if connect
          (irc-connect-to-all)
        (message
         "did nothing, %s to connect"
         (substitute-command-keys "\\[universal-argument]") )))))

https://dataswamp.org/~incal/emacs-init/erc-incal.el

(defun new-message (&optional force)
  (interactive "P")
  (message (format "%s" force))
  (if (or (not (eq major-mode 'message-mode)) force)
      (progn
        (unless (gnus-alive-p) (gnus))
        (gnus-post-news 'post "") )
    (message
     "did nothing, %s to force"
     (substitute-command-keys "\\[universal-argument]")
     )))

https://dataswamp.org/~incal/emacs-init/gnus/gnus-incal.el

-- 
underground experts united
https://dataswamp.org/~incal




^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-05-02 17:38 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-05-01 22:35 don't hard-code keys Emanuel Berg via Users list for the GNU Emacs text editor
2021-05-02  7:13 ` Tassilo Horn
2021-05-02 14:44   ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-05-02 17:28     ` Thibaut Verron
2021-05-02 17:33       ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-05-02 17:38         ` Emanuel Berg via Users list for the GNU Emacs text editor

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.