emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/free-keys 79205af5f5 01/19: Initial commit


From: ELPA Syncer
Subject: [nongnu] elpa/free-keys 79205af5f5 01/19: Initial commit
Date: Sat, 29 Jan 2022 08:02:48 -0500 (EST)

branch: elpa/free-keys
commit 79205af5f5d46c43ba646143025d265de3b6ffda
Author: Matus Goljer <dota.keys@gmail.com>
Commit: Matus Goljer <dota.keys@gmail.com>

    Initial commit
---
 README.md    |  24 +++++++++++
 free-keys.el | 133 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 157 insertions(+)

diff --git a/README.md b/README.md
new file mode 100644
index 0000000000..fa80d0f241
--- /dev/null
+++ b/README.md
@@ -0,0 +1,24 @@
+# free-keys
+
+Show free bindings in current buffer. Based on 
https://gist.github.com/bjorne/3796607
+
+To use, call the command `free-keys`. This package takes into account the 
major mode bindigns as well as any bindings occupied by minor modes active in 
current buffer. If called with prefix argument `C-u`, you can specify a prefix 
map to be used, such as `C-c` or `C-c C-x` (these are specified as a string).
+
+You can customize the variable `free-keys-modifiers` if you use non-standard 
modifiers, such as `H` for hyper, `s` for super or `S` for shift. By default 
this list contains `C`, `M`, `C-M` and no modifier.
+
+You can customize the variable `free-keys-keys` if you use non-english 
keyboard layout and want to show free bindings for keys such as č, í, ö, è, å 
etc.
+
+These bindings are available inside the `*Free keys*` buffer:
+
+Keybinding | Description
+-----------|---------------
+`b`        | Change the "active" buffer
+`p`        | Change the prefix
+`q`        | Quit
+
+
+# Installation
+
+The easiest way is to install this via `package.el` from MELPA repository. If 
you want to install manually, clone the git repo and add it to your `load-path`:
+
+    (add-to-list 'load-path "path-to-this-git-repo")
diff --git a/free-keys.el b/free-keys.el
new file mode 100644
index 0000000000..43b0a4a216
--- /dev/null
+++ b/free-keys.el
@@ -0,0 +1,133 @@
+;;; free-keys.el --- Show free keybindings for modkeys or prefixes
+
+;; Copyright (C) 2013 Matus Goljer
+
+;; Author: Matus Goljer <matus.goljer@gmail.com>
+;; Maintainer: Matus Goljer <matus.goljer@gmail.com>
+;; Version: 0.1
+;; Created: 3rd November 2013
+;; Keywords: convenience
+
+;; This file is not part of GNU Emacs.
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; Show free keybindings for modkeys or prefixes. Based on code
+;; located here: https://gist.github.com/bjorne/3796607
+
+;;; Code:
+
+(defgroup free-keys ()
+  "Free keys."
+  :group 'convenience)
+
+(defcustom free-keys-modifiers '("" "C" "M" "C-M")
+  "List of modifiers that can be used in front of keys."
+  :type '(repeat string)
+  :group 'free-keys)
+
+(defcustom free-keys-keys 
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()-=[]{};'\\:\"|,./<>?`~"
+  "String of keys that can be used as bindings."
+  :type 'string
+  :group 'free-keys)
+
+(defvar free-keys-mode-map
+  (let ((map (make-keymap)))
+    (define-key map "b" 'free-keys-change-buffer)
+    (define-key map "p" 'free-keys-set-prefix)
+    map)
+  "Keymap for Free Keys mode.")
+
+(defvar free-keys-original-buffer nil
+  "Buffer from which `free-keys' was called.")
+
+(defun free-keys--print-in-columns (key-list &optional columns)
+  (setq columns (or columns 80))
+  (let* ((len (+ 5 (length (car key-list))))
+         (cols (/ columns len))
+         (rows (/ (length key-list) cols))
+         (cur-col 0)
+         (cur-row 0))
+    (dotimes (i (length key-list))
+      (insert (nth (+ (* cur-col rows) cur-row) key-list) "     ")
+      (cl-incf cur-col)
+      (when (= cur-col cols)
+        (insert "\n")
+        (setq cur-col 0)
+        (cl-incf cur-row)))))
+
+(defun free-keys-set-prefix (prefix)
+  "Change the prefix and update the display."
+  (interactive "sPrefix: ")
+  (free-keys prefix free-keys-original-buffer))
+
+(defun free-keys-change-buffer (buffer)
+  (interactive "bShow free bindings for buffer: ")
+  (free-keys nil (get-buffer-create buffer)))
+
+;;;###autoload
+(defun free-keys (&optional prefix buffer)
+  (interactive (list (when current-prefix-arg
+                         (read-from-minibuffer "Prefix: "))))
+  (setq prefix (or prefix ""))
+  (setq free-keys-original-buffer (or buffer (current-buffer)))
+  (let ((buf (get-buffer-create "*Free keys*")))
+    (pop-to-buffer buf)
+    (with-current-buffer buf
+      (read-only-mode -1)
+      (erase-buffer)
+      (insert "Help: (b) change buffer (p) change prefix (q) quit\n"
+              "--------------------------------------------------\n\n")
+      (insert "Free keys"
+              (if (not (equal prefix "")) (format " with prefix %s" prefix) "")
+              " in buffer "
+              (buffer-name free-keys-original-buffer)
+              " (major mode: " (with-current-buffer free-keys-original-buffer 
(symbol-name major-mode)) ")\n\n")
+      (mapc (lambda (modifier)
+              (if (not (equal modifier ""))
+                  (insert "With modifier " modifier 
"\n=========================\n")
+                (insert "With no modifier\n=========================\n"))
+              (let (empty-keys)
+                (mapc (lambda (key)
+                        (let* ((key-name
+                                (if (not (equal modifier ""))
+                                    (concat modifier "-" (char-to-string key))
+                                  (char-to-string key)))
+                               (full-name
+                                (if prefix (concat prefix " " key-name) 
key-name))
+                               (binding
+                                (with-current-buffer free-keys-original-buffer 
(key-binding (read-kbd-macro full-name)))))
+                          (when (not binding)
+                            (push full-name empty-keys))))
+                      free-keys-keys)
+                (free-keys--print-in-columns (nreverse empty-keys)))
+              (insert "\n\n"))
+            free-keys-modifiers)
+      (setq buffer-read-only t)
+      (make-local-variable 'buffer-read-only)
+      (goto-char 0)
+      (free-keys-mode))))
+
+;;;###autoload
+(define-derived-mode free-keys-mode special-mode "Free Keys"
+  "Free keys mode.
+
+Display the free keybindings in current buffer.
+
+\\{free-keys-mode-map}")
+
+(provide 'free-keys)
+;;; free-keys.el ends here



reply via email to

[Prev in Thread] Current Thread [Next in Thread]