Skip to content

Greybeard-Entertainment/disposable-key

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Emacs Disposable Keybindings

This package gives you a single function and a single minor mode that fix the problem of wanting to have disposable key bindings for just this once.

TL;DR

(use-package disposable-key
  :ensure t
  :elpaca
  (:host github
		 :repo "Greybeard-Entertainment/disposable-key"
		 :branch "barba")
  :bind
  ("<f6>" . diposable-key-bind)
  ("<f7>" . diposable-key-bind)
  ("<f8>" . diposable-key-bind)
  ("<f9>" . diposable-key-bind)
  ;; f10 -- menu most DEs
  ;; f11 -- fullscreen. Why would you want that IDK, but it doesn't hurt anyone
  ("<f12>" . diposable-key-bind)
  ("C-x M-r" . disposable-key-force-rebind))

Introduction

Disposable key bind concept

Suppose you had a function which you wanted to use contextually (because you need it), but you don’t want to set in your init.el or any of the dependent files.

You could use local-set-key but that requires you to press the combination first, plus it doesn’t tell you what that function was bound to before. This I used a whole lot, but the discover-ability of this feature leaves much to be desired. This pattern of usage made me keep a collection of keys as designated single-use key-bindings. So why not formalise this form of usage.

This package essentially allows you to do just that. You bind a bunch of keys to a function which allows you to remap them instantly when you click them, I usually had all the function keys bound to that.

Disposable key mode

This package also allows you to do something more aggressive. In the later stages of your Emacs learning curve you might stop accidentally bumping the keyboard and making unintentional inputs. At this stage, “the keyboard is your oyster”, in the sense that rather than being told that a key is unbound, I might want to choose to bind it to something useful. This is where the disposable-key-mode comes in.

I don’t recommend starting this minor mode for novices.

Installation

Direct download

Download this file and put it in your load-path. Then add

(require 'disposable-key)

Using elpaca

Elpaca is what I personally use these days so assuming that you have elpaca-use-package, you could do:

 (use-package disposable-key
	:ensure t
	:elpaca
	(:host github
		   :repo "Greybeard-Entertainment/disposable-key"
		   :branch "barba"))

Using the Emacs GUI

Run M-x package-list-packages, which will open a list of packages, where you can use C-s to find this package left click to open the menu and left click on the box saying “install” to actually install the package.

using bare use-package

Add this to your init.el.

 (use-package disposable-key
	:ensure t)

This will begin working as soon as I commit the package to one of the packaging repositories.

Usage

This package provides you with three key functions.

Bind diposable-key-bind to a few keys

If you have a cluster of keys that you want to use a placeholders for useful functions, you should bind these keys to the diposable-key-bind function.

Example:

(global-set-key (kbd "<f9>") 'diposable-key-bind)
(global-set-key (kbd "<f12>") 'diposable-key-bind)
(global-set-key (kbd "<f6>") 'diposable-key-bind)
(global-set-key (kbd "<f7>") 'diposable-key-bind)
(global-set-key (kbd "<f8>") 'diposable-key-bind)

Which will make the function row keys usable as disposable key-bindings.

Bind disposable-key-force-rebind

This function is not necessary but it is highly recommended to bind it to some other key.

If you press this before pressing any of the other disposable bindings, it would allow you to change the binding.

Example: you’re writing an Emacs lisp buffer, you bind <f9> to eval-buffer. Then you decided that you want to change your testing methodology and started using cask, so you pressed diposable-key-force-rebind and then <f9> and changed the binding.

Enable the disposable-key-global-mode

This is more of a radical solution. I’m long past the situation in which I could be making random inputs into Emacs, or near-miss a button. Instead I’m much more annoyed at the fact that I have 101 keys on a keyboard and can’t realistically remember all of the key bindings. With diposable-key mode I don’t have to; all bindings are temporary and persist until the next time I re-run Emacs, or hit the disposable-key-force-rebind key. As such, I don’t want to have to press M-x local-set-key every time I want to make a local binding.

Development Roadmap

Make bindings persistent

Differentiate global disposable keybinds from local keybinds

License

As specified in the appropriate file, this work is Free Software, and while it is distributed in the hope that it might be useful, it is not at all guaranteed to do anything.

About

The emacs disposable keybindings

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published