* Emacs keybindings according to file type
@ 2020-09-21 6:46 Christopher Dimech
2020-09-21 14:16 ` Eli Zaretskii
0 siblings, 1 reply; 11+ messages in thread
From: Christopher Dimech @ 2020-09-21 6:46 UTC (permalink / raw)
To: Help Gnu Emacs
I want to set different keybinding according to the type of file I load
into a buffer. I wonder how I can do that.
In my .emacs file I have
; Loads texinfo Customisations
(setq texi--customs "/home/hagbard/swadmin/emacs/el/naiad/texi--custom.el")
(load texi--customs)
; Loads Fortran Customisations.
(setq fortran--customs "/home/hagbard/swadmin/emacs/el/naiad/fortran--custom.el")
(load fortran--customs)
; Adds Org Mode Custimisations
(setq org--customs "/home/hagbard/swadmin/emacs/el/naiad/org--custom.el")
(load org--customs)
Then in separate files I have commands for each language.
---------
I want to have keybinding for f1 and f2 to toggle between org-mode and texinfo-mode
when the file is a .texi
; Helps traverse a texinfo document using org-mode commands
; Sets Keybinding for switching between texinfo-mode and org-mode
; The Major Mode toggle is used for Syntax Highlighting
(global-set-key [f1] (kbd "M-x org-mode"))
(global-set-key [f2] (kbd "M-x texinfo-mode"))
And if I have a .f file, I want the keybinding for f90-mode
(global-set-key [f1] (kbd "M-x org-mode"))
(global-set-key [f2] (kbd "M-x f90-mode"))
-------
However, if one looks at the .emacs file, the keybindings that take effect is always of
the last file that is loaded, in this case being fortran--custom.el. This means that if
I load a .texi file, the keybinding f2 will not change the buffer to texinfo-mode.
Regards
S*
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Emacs keybindings according to file type
2020-09-21 6:46 Emacs keybindings according to file type Christopher Dimech
@ 2020-09-21 14:16 ` Eli Zaretskii
2020-09-21 14:20 ` Christopher Dimech
2020-09-23 6:33 ` Christopher Dimech
0 siblings, 2 replies; 11+ messages in thread
From: Eli Zaretskii @ 2020-09-21 14:16 UTC (permalink / raw)
To: help-gnu-emacs
> From: Christopher Dimech <dimech@gmx.com>
> Date: Mon, 21 Sep 2020 08:46:02 +0200
>
> I want to set different keybinding according to the type of file I load
> into a buffer. I wonder how I can do that.
The usual way of doing this is use local-set-key in a mode hook. Then
the key bindings will only affect the mode of that file.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Emacs keybindings according to file type
2020-09-21 14:16 ` Eli Zaretskii
@ 2020-09-21 14:20 ` Christopher Dimech
2020-09-21 15:57 ` Eric S Fraga
2020-09-23 6:33 ` Christopher Dimech
1 sibling, 1 reply; 11+ messages in thread
From: Christopher Dimech @ 2020-09-21 14:20 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: help-gnu-emacs
Where can I find some examples?
> Sent: Monday, September 21, 2020 at 2:16 PM
> From: "Eli Zaretskii" <eliz@gnu.org>
> To: help-gnu-emacs@gnu.org
> Subject: Re: Emacs keybindings according to file type
>
> > From: Christopher Dimech <dimech@gmx.com>
> > Date: Mon, 21 Sep 2020 08:46:02 +0200
> >
> > I want to set different keybinding according to the type of file I load
> > into a buffer. I wonder how I can do that.
>
> The usual way of doing this is use local-set-key in a mode hook. Then
> the key bindings will only affect the mode of that file.
>
>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Emacs keybindings according to file type
2020-09-21 14:20 ` Christopher Dimech
@ 2020-09-21 15:57 ` Eric S Fraga
0 siblings, 0 replies; 11+ messages in thread
From: Eric S Fraga @ 2020-09-21 15:57 UTC (permalink / raw)
To: help-gnu-emacs
On Monday, 21 Sep 2020 at 16:20, Christopher Dimech wrote:
> Where can I find some examples?
Maybe https://www.emacswiki.org/emacs/ModeHooks will help you?
--
Eric S Fraga via Emacs 28.0.50 & org 9.4 on Debian bullseye/sid
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Emacs keybindings according to file type
2020-09-21 14:16 ` Eli Zaretskii
2020-09-21 14:20 ` Christopher Dimech
@ 2020-09-23 6:33 ` Christopher Dimech
2020-09-23 7:33 ` Yuri Khan
2020-09-23 23:05 ` Emanuel Berg via Users list for the GNU Emacs text editor
1 sibling, 2 replies; 11+ messages in thread
From: Christopher Dimech @ 2020-09-23 6:33 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: help-gnu-emacs
Dear Compeers,
I wrote the following code to swap line for org files.
Did not work after trying it. I need to have the thing work for
org files and other files on whicn I call M-x org-mode.
( defun Transpose-Org-Line ()
"Binds up and down keys to org-drag-line* commands"
(local-set-key (kbd "C-t l f") 'org-drag-line-forwarrd)
(local-set-key (kbd "C-t l b") 'org-drag-line-backward)
)
( add-hook 'org-mode-hook 'Transpose-Org-Line )
---------------------
Christopher Dimech
Chief Administrator - Naiad Informatics - GNU Project (Geocomputation)
- Geophysical Simulation
- Geological Subsurface Mapping
- Disaster Preparedness and Mitigation
- Natural Resource Exploration and Production
- Free Software Advocacy
> Sent: Monday, September 21, 2020 at 2:16 PM
> From: "Eli Zaretskii" <eliz@gnu.org>
> To: help-gnu-emacs@gnu.org
> Subject: Re: Emacs keybindings according to file type
>
> > From: Christopher Dimech <dimech@gmx.com>
> > Date: Mon, 21 Sep 2020 08:46:02 +0200
> >
> > I want to set different keybinding according to the type of file I load
> > into a buffer. I wonder how I can do that.
>
> The usual way of doing this is use local-set-key in a mode hook. Then
> the key bindings will only affect the mode of that file.
>
>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Emacs keybindings according to file type
2020-09-23 6:33 ` Christopher Dimech
@ 2020-09-23 7:33 ` Yuri Khan
2020-09-23 7:44 ` Christopher Dimech
2020-09-23 23:05 ` Emanuel Berg via Users list for the GNU Emacs text editor
1 sibling, 1 reply; 11+ messages in thread
From: Yuri Khan @ 2020-09-23 7:33 UTC (permalink / raw)
To: Christopher Dimech; +Cc: help-gnu-emacs
On Wed, 23 Sep 2020 at 13:33, Christopher Dimech <dimech@gmx.com> wrote:
> I wrote the following code to swap line for org files.
> Did not work after trying it. I need to have the thing work for
> org files and other files on whicn I call M-x org-mode.
>
> ( defun Transpose-Org-Line ()
> "Binds up and down keys to org-drag-line* commands"
> (local-set-key (kbd "C-t l f") 'org-drag-line-forwarrd)
> (local-set-key (kbd "C-t l b") 'org-drag-line-backward)
> )
>
> ( add-hook 'org-mode-hook 'Transpose-Org-Line )
Works for me in emacs -Q, except that you misspelled ‘forward’.
Also, org-mode already binds M-S-<up> and M-S-<down> to commands that
work the same way as org-drag-line-* unless you are in a table or on a
clock timestamp. It’s likely that you will want to drag a line more
than once in a row, so a repeatable binding (a key that you can hold
down) is better than a long sequence such as C-t l f.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Emacs keybindings according to file type
2020-09-23 7:33 ` Yuri Khan
@ 2020-09-23 7:44 ` Christopher Dimech
2020-09-23 7:52 ` Yuri Khan
0 siblings, 1 reply; 11+ messages in thread
From: Christopher Dimech @ 2020-09-23 7:44 UTC (permalink / raw)
To: Yuri Khan; +Cc: help-gnu-emacs
Thank you for pointing the misspelling, it now works correctly.
In the meantime I have used the following
( org-defkey org-mode-map (kbd "C-t l f") 'org-drag-line-forward )
( org-defkey org-mode-map (kbd "C-t l b") 'org-drag-line-backward )
Concerning the repeatable binding, have you practiced, because I have not.
How do you go about it?
> Sent: Wednesday, September 23, 2020 at 7:33 AM
> From: "Yuri Khan" <yuri.v.khan@gmail.com>
> To: "Christopher Dimech" <dimech@gmx.com>
> Cc: "Eli Zaretskii" <eliz@gnu.org>, "help-gnu-emacs" <help-gnu-emacs@gnu.org>
> Subject: Re: Emacs keybindings according to file type
>
> On Wed, 23 Sep 2020 at 13:33, Christopher Dimech <dimech@gmx.com> wrote:
>
> > I wrote the following code to swap line for org files.
> > Did not work after trying it. I need to have the thing work for
> > org files and other files on whicn I call M-x org-mode.
> >
> > ( defun Transpose-Org-Line ()
> > "Binds up and down keys to org-drag-line* commands"
> > (local-set-key (kbd "C-t l f") 'org-drag-line-forwarrd)
> > (local-set-key (kbd "C-t l b") 'org-drag-line-backward)
> > )
> >
> > ( add-hook 'org-mode-hook 'Transpose-Org-Line )
>
> Works for me in emacs -Q, except that you misspelled ‘forward’.
>
> Also, org-mode already binds M-S-<up> and M-S-<down> to commands that
> work the same way as org-drag-line-* unless you are in a table or on a
> clock timestamp. It’s likely that you will want to drag a line more
> than once in a row, so a repeatable binding (a key that you can hold
> down) is better than a long sequence such as C-t l f.
>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Emacs keybindings according to file type
2020-09-23 7:44 ` Christopher Dimech
@ 2020-09-23 7:52 ` Yuri Khan
2020-09-23 8:03 ` Christopher Dimech
2020-09-23 8:06 ` Marcin Borkowski
0 siblings, 2 replies; 11+ messages in thread
From: Yuri Khan @ 2020-09-23 7:52 UTC (permalink / raw)
To: Christopher Dimech; +Cc: help-gnu-emacs
On Wed, 23 Sep 2020 at 14:44, Christopher Dimech <dimech@gmx.com> wrote:
> Concerning the repeatable binding, have you practiced, because I have not.
> How do you go about it?
A binding is called repeatable if you can repeat it easily. A single
key (possibly with modifiers) is repeatable.
There also exist techniques to make key sequences repeatable, such as
C-x z (‘repeat’). You can execute org-drag-line-forward with C-t l f,
then press C-x z to repeat that once, then press z one or several
times to repeat again. Personally, I don’t use that and strive to
assign easy keys to commands I’m going to use multiple times in a row.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Emacs keybindings according to file type
2020-09-23 7:52 ` Yuri Khan
@ 2020-09-23 8:03 ` Christopher Dimech
2020-09-23 8:06 ` Marcin Borkowski
1 sibling, 0 replies; 11+ messages in thread
From: Christopher Dimech @ 2020-09-23 8:03 UTC (permalink / raw)
To: Yuri Khan; +Cc: help-gnu-emacs
I agree with you Yuri on assigning easy keys.
For instance one can make it to continue pressing C-t l f f f to continue
moving line downward.
Any sample code to try out?
Regards
C*
> Sent: Wednesday, September 23, 2020 at 7:52 AM
> From: "Yuri Khan" <yuri.v.khan@gmail.com>
> To: "Christopher Dimech" <dimech@gmx.com>
> Cc: "Eli Zaretskii" <eliz@gnu.org>, "help-gnu-emacs" <help-gnu-emacs@gnu.org>
> Subject: Re: Emacs keybindings according to file type
>
> On Wed, 23 Sep 2020 at 14:44, Christopher Dimech <dimech@gmx.com> wrote:
>
> > Concerning the repeatable binding, have you practiced, because I have not.
> > How do you go about it?
>
> A binding is called repeatable if you can repeat it easily. A single
> key (possibly with modifiers) is repeatable.
>
> There also exist techniques to make key sequences repeatable, such as
> C-x z (‘repeat’). You can execute org-drag-line-forward with C-t l f,
> then press C-x z to repeat that once, then press z one or several
> times to repeat again. Personally, I don’t use that and strive to
> assign easy keys to commands I’m going to use multiple times in a row.
>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Emacs keybindings according to file type
2020-09-23 7:52 ` Yuri Khan
2020-09-23 8:03 ` Christopher Dimech
@ 2020-09-23 8:06 ` Marcin Borkowski
1 sibling, 0 replies; 11+ messages in thread
From: Marcin Borkowski @ 2020-09-23 8:06 UTC (permalink / raw)
To: Yuri Khan; +Cc: Christopher Dimech, help-gnu-emacs
On 2020-09-23, at 09:52, Yuri Khan <yuri.v.khan@gmail.com> wrote:
> On Wed, 23 Sep 2020 at 14:44, Christopher Dimech <dimech@gmx.com> wrote:
>
>> Concerning the repeatable binding, have you practiced, because I have not.
>> How do you go about it?
>
> A binding is called repeatable if you can repeat it easily. A single
> key (possibly with modifiers) is repeatable.
>
> There also exist techniques to make key sequences repeatable, such as
> C-x z (‘repeat’). You can execute org-drag-line-forward with C-t l f,
> then press C-x z to repeat that once, then press z one or several
> times to repeat again. Personally, I don’t use that and strive to
> assign easy keys to commands I’m going to use multiple times in a row.
Also, you might be interested in the excellent hydra package.
Hth,
--
Marcin Borkowski
http://mbork.pl
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Emacs keybindings according to file type
2020-09-23 6:33 ` Christopher Dimech
2020-09-23 7:33 ` Yuri Khan
@ 2020-09-23 23:05 ` Emanuel Berg via Users list for the GNU Emacs text editor
1 sibling, 0 replies; 11+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2020-09-23 23:05 UTC (permalink / raw)
To: help-gnu-emacs
Christopher Dimech wrote:
> ( defun Transpose-Org-Line ()
> "Binds up and down keys to org-drag-line* commands"
> (local-set-key (kbd "C-t l f") 'org-drag-line-forwarrd)
> (local-set-key (kbd "C-t l b") 'org-drag-line-backward)
> )
>
> ( add-hook 'org-mode-hook 'Transpose-Org-Line )
Uhm, what is the purpose of that Elisp?
You want to set the keys for org-mode? Or globally,
using the org functions? (actually, I don't have
them, even in org-mode)
If you want to set it for org-mode, why set them
locally? Anyway, assuming you have `required'
someplace where they are defined, or otherwise made
access to them possible:
(require 'org)
(defun set-org-keys ()
(define-key org-mode-map "\C-tlf" #'org-drag-line-forwarrd)
(define-key org-mode-map "\C-tlb" #'org-drag-line-backward) )
(add-hook 'org-mode-hook #'set-org-keys)
(also note differences in style ...)
If you want it globally, why the org-mode hook?
I agree with the people who say shortcuts should
be... short. But something just as important are that
they are _close_. Put your fingers at asdf (left
hand) and jkl; (right). Look down, and, hit the
shortcut. See, and feel, how far did your fingers
have to go? So short, close -> comfortable and fast!
...
> ---------------------
> Christopher Dimech
> Chief Administrator - Naiad Informatics - GNU Project (Geocomputation)
> - Geophysical Simulation
> - Geological Subsurface Mapping
> - Disaster Preparedness and Mitigation
> - Natural Resource Exploration and Production
> - Free Software Advocacy
Hint: RFC 3676, section 4.3 (Usenet Signature
Convention):
https://www.ietf.org/rfc/rfc3676.txt
:)
--
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2020-09-23 23:05 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-09-21 6:46 Emacs keybindings according to file type Christopher Dimech
2020-09-21 14:16 ` Eli Zaretskii
2020-09-21 14:20 ` Christopher Dimech
2020-09-21 15:57 ` Eric S Fraga
2020-09-23 6:33 ` Christopher Dimech
2020-09-23 7:33 ` Yuri Khan
2020-09-23 7:44 ` Christopher Dimech
2020-09-23 7:52 ` Yuri Khan
2020-09-23 8:03 ` Christopher Dimech
2020-09-23 8:06 ` Marcin Borkowski
2020-09-23 23:05 ` 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.