unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* trouble overwriting C-r in a shell (term-mode)
@ 2020-05-28 16:30 Christian Seberino
  2020-05-28 20:35 ` Narendra Joshi
  0 siblings, 1 reply; 5+ messages in thread
From: Christian Seberino @ 2020-05-28 16:30 UTC (permalink / raw)
  To: help-gnu-emacs

I'm trying to overwrite C-r in a shell and it isn't working.
Any help greatly appreciated.  I tried adding a term-mode hook as
follows....

(add-hook 'term-mode-hook
          '(lambda () (interactive)
                   (global-set-key (kbd "C-r")
                                   (lambda () (interactive)
                                              (if (get-buffer  "*Open
Recent*")
                                                  (kill-buffer "*Open
Recent*"))
                                              (recentf-open-files)))))

Thanks!

Chris


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

* Re: trouble overwriting C-r in a shell (term-mode)
  2020-05-28 16:30 trouble overwriting C-r in a shell (term-mode) Christian Seberino
@ 2020-05-28 20:35 ` Narendra Joshi
  2020-05-28 21:31   ` Christian Seberino
  2020-05-28 22:42   ` Emanuel Berg via Users list for the GNU Emacs text editor
  0 siblings, 2 replies; 5+ messages in thread
From: Narendra Joshi @ 2020-05-28 20:35 UTC (permalink / raw)
  To: Christian Seberino; +Cc: help-gnu-emacs

Christian Seberino <cseberino@gmail.com> writes:

> I'm trying to overwrite C-r in a shell and it isn't working.
> Any help greatly appreciated.  I tried adding a term-mode hook as
> follows....
>
> (add-hook 'term-mode-hook
>           '(lambda () (interactive)
>                    (global-set-key (kbd "C-r")
>                                    (lambda () (interactive)
>                                               (if (get-buffer  "*Open
> Recent*")
>                                                   (kill-buffer "*Open
> Recent*"))
>                                               (recentf-open-files)))))

You can bind "C-r" in the keymap `term-raw-map' to the function: 
--8<---------------cut here---------------start------------->8---
(define-key term-raw-map (kbd "C-r") (lambda () (interactive)
                                       (if (get-buffer  "*Open Recent*")
                                           (kill-buffer "*Open Recent*"))
                                       (recentf-open-files)))
--8<---------------cut here---------------end--------------->8---

When `term-char-mode' is on, `term-raw-map' is activated as the local
map of the term buffer.


> Thanks!
>
> Chris

Best,
-- 
Narendra Joshi



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

* Re: trouble overwriting C-r in a shell (term-mode)
  2020-05-28 20:35 ` Narendra Joshi
@ 2020-05-28 21:31   ` Christian Seberino
  2020-05-28 22:42   ` Emanuel Berg via Users list for the GNU Emacs text editor
  1 sibling, 0 replies; 5+ messages in thread
From: Christian Seberino @ 2020-05-28 21:31 UTC (permalink / raw)
  To: Narendra Joshi; +Cc: help-gnu-emacs

Narendra

Oh wow.  Thanks so much.  Your code below worked!

cs


> (define-key term-raw-map (kbd "C-r") (lambda () (interactive)
>                                        (if (get-buffer  "*Open Recent*")
>                                            (kill-buffer "*Open Recent*"))
>                                        (recentf-open-files)))
>
>


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

* Re: trouble overwriting C-r in a shell (term-mode)
  2020-05-28 20:35 ` Narendra Joshi
  2020-05-28 21:31   ` Christian Seberino
@ 2020-05-28 22:42   ` Emanuel Berg via Users list for the GNU Emacs text editor
  2020-05-29  9:09     ` Jamie Beardslee
  1 sibling, 1 reply; 5+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2020-05-28 22:42 UTC (permalink / raw)
  To: help-gnu-emacs

Narendra Joshi wrote:

> (define-key term-raw-map (kbd "C-r") (lambda () (interactive)
>                                        (if (get-buffer  "*Open Recent*")
>                                            (kill-buffer "*Open Recent*"))
>                                        (recentf-open-files)))

Style points:

  "\C-r" instead of (kbd "C-r")

  `let' so the hard-coded data item "*Open Recent*"
  appears onee time

  `when' instead of `if' as there is no else branch

:)

-- 
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal




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

* Re: trouble overwriting C-r in a shell (term-mode)
  2020-05-28 22:42   ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2020-05-29  9:09     ` Jamie Beardslee
  0 siblings, 0 replies; 5+ messages in thread
From: Jamie Beardslee @ 2020-05-29  9:09 UTC (permalink / raw)
  To: help-gnu-emacs

> Style points:
>
>   "\C-r" instead of (kbd "C-r")
>
>   `let' so the hard-coded data item "*Open Recent*"
>   appears onee time
>
>   `when' instead of `if' as there is no else branch

Even more style points:

- don't bind a key to an anonymous function
- buffer name is dependent on `recentf-menu-title'
- use an informative docstring

(defun my-recentf-open-files ()
  "blah blah blah"
  (interactive)
  (let ((buffer (get-buffer (format "*%s*" recentf-menu-title))))
    (when buffer
      (kill-buffer buffer))
    (recentf-open-files)))

(define-key term-raw-map (kbd "C-r") #'my-recentf-open-files)





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

end of thread, other threads:[~2020-05-29  9:09 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-05-28 16:30 trouble overwriting C-r in a shell (term-mode) Christian Seberino
2020-05-28 20:35 ` Narendra Joshi
2020-05-28 21:31   ` Christian Seberino
2020-05-28 22:42   ` Emanuel Berg via Users list for the GNU Emacs text editor
2020-05-29  9:09     ` Jamie Beardslee

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).