[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/hydra 54e9db2b02: Fix packaging of `lv` and use lexical
From: |
Stefan Monnier |
Subject: |
[elpa] externals/hydra 54e9db2b02: Fix packaging of `lv` and use lexical-binding and nadvice everywhere |
Date: |
Sun, 30 Oct 2022 22:52:49 -0400 (EDT) |
branch: externals/hydra
commit 54e9db2b023e03b6f6b46aeec48ea74fd51d4e11
Author: Stefan Monnier <monnier@iro.umontreal.ca>
Commit: Stefan Monnier <monnier@iro.umontreal.ca>
Fix packaging of `lv` and use lexical-binding and nadvice everywhere
* hydra.el: Require Emacs-24.4 so we can freely use nadvice.
Prefer #' to quote function names. Remove redundant `:group` args.
(hydra-disable): Assume `remove-function` is available.
(hydra-add-imenu): Use [:alpha:] so we accept non-ASCII chars as well.
(find-function-search-for-symbol): Don't bother using `eval-after-load`
since pieces of advice can always be installed. Use `advice-add`
instead of `defadvice`.
(hydra--around-find-function-search-for-symbol-advice): New function,
extracted from the previous `defadvice`.
(hydra-default-pre): Assume `add-function` is available.
(hydra--to-string, hydra--complain): Simplify.
(hydra--hint-heads-wocol, hydra--format-1, hydra-show-hint)
(defhydra): Use lexical-binding like everywhere else.
* .gitignore: New file.
* lv.el: Use `lexical-binding`. Add `Version:` for GNU ELPA.
(lv-use-separator, lv-use-padding): Remove redundant `:group` arg.
(lv--pad-to-center): Use `string-width` rather than `length` to compute
the width of a string.
(lv-message): Use `format-message` if available.
* targets/hydra-init.el:
* hydra-test.el:
* hydra-ox.el:
* hydra-examples.el: Use lexical-binding.
---
.gitignore | 5 ++
hydra-examples.el | 4 +-
hydra-ox.el | 12 +++--
hydra-test.el | 4 +-
hydra.el | 143 ++++++++++++++++++++++++--------------------------
lv.el | 23 ++++----
targets/hydra-init.el | 4 +-
7 files changed, 99 insertions(+), 96 deletions(-)
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000000..01cb621004
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,5 @@
+*.elc
+/hydra-autoloads.el
+/hydra-pkg.el
+/lv-autoloads.el
+/lv-pkg.el
diff --git a/hydra-examples.el b/hydra-examples.el
index 5262ec60cb..a44f33af7b 100644
--- a/hydra-examples.el
+++ b/hydra-examples.el
@@ -1,6 +1,6 @@
-;;; hydra-examples.el --- Some applications for Hydra
+;;; hydra-examples.el --- Some applications for Hydra -*- lexical-binding: t;
-*-
-;; Copyright (C) 2015 Free Software Foundation, Inc.
+;; Copyright (C) 2015-2022 Free Software Foundation, Inc.
;; Author: Oleh Krehel
diff --git a/hydra-ox.el b/hydra-ox.el
index a992efc28d..01a57dfdf1 100644
--- a/hydra-ox.el
+++ b/hydra-ox.el
@@ -1,6 +1,6 @@
-;;; hydra-ox.el --- Org mode export widget implemented in Hydra
+;;; hydra-ox.el --- Org mode export widget implemented in Hydra -*-
lexical-binding: t; -*-
-;; Copyright (C) 2015 Free Software Foundation, Inc.
+;; Copyright (C) 2015-2022 Free Software Foundation, Inc.
;; Author: Oleh Krehel
@@ -54,13 +54,15 @@
hydra-ox/async-export
(eq hydra-ox/export-scope 'subtree)
hydra-ox/visible-only
- hydra-ox/body-only) "As HTML file")
+ hydra-ox/body-only)
+ "As HTML file")
("o" (org-open-file
(org-html-export-to-html
hydra-ox/async-export
(eq hydra-ox/export-scope 'subtree)
hydra-ox/visible-only
- hydra-ox/body-only)) "As HTML file and open")
+ hydra-ox/body-only))
+ "As HTML file and open")
("b" hydra-ox/body "back")
("q" nil "quit"))
@@ -120,7 +122,7 @@ _C-a_ Async export: %`hydra-ox/async-export
("t" hydra-ox-text/body "Export to Plain Text" :exit t)
("q" nil "quit"))
-(define-key org-mode-map (kbd "C-c C-,") 'hydra-ox/body)
+(define-key org-mode-map (kbd "C-c C-,") #'hydra-ox/body)
(provide 'hydra-ox)
diff --git a/hydra-test.el b/hydra-test.el
index c672f2c2e0..0c54182127 100644
--- a/hydra-test.el
+++ b/hydra-test.el
@@ -1,6 +1,6 @@
-;;; hydra-test.el --- Tests for Hydra
+;;; hydra-test.el --- Tests for Hydra -*- lexical-binding: t; -*-
-;; Copyright (C) 2015 Free Software Foundation, Inc.
+;; Copyright (C) 2015-2022 Free Software Foundation, Inc.
;; Author: Oleh Krehel
diff --git a/hydra.el b/hydra.el
index c85926c5c8..5d5623c383 100644
--- a/hydra.el
+++ b/hydra.el
@@ -1,13 +1,13 @@
;;; hydra.el --- Make bindings that stick around. -*- lexical-binding: t -*-
-;; Copyright (C) 2015-2019 Free Software Foundation, Inc.
+;; Copyright (C) 2015-2022 Free Software Foundation, Inc.
;; Author: Oleh Krehel <ohwoeowho@gmail.com>
;; Maintainer: Oleh Krehel <ohwoeowho@gmail.com>
;; URL: https://github.com/abo-abo/hydra
;; Version: 0.15.0
;; Keywords: bindings
-;; Package-Requires: ((cl-lib "0.5") (lv "0"))
+;; Package-Requires: ((emacs "24.4") (lv "0"))
;; This file is part of GNU Emacs.
@@ -120,7 +120,7 @@ warn: keep KEYMAP and issue a warning instead of running
the command."
(setq hydra-curr-map keymap)
(setq hydra-curr-on-exit on-exit)
(setq hydra-curr-foreign-keys foreign-keys)
- (add-hook 'pre-command-hook 'hydra--clearfun)
+ (add-hook 'pre-command-hook #'hydra--clearfun)
(internal-push-keymap keymap 'overriding-terminal-local-map)))
(defun hydra--clearfun ()
@@ -149,13 +149,9 @@ warn: keep KEYMAP and issue a warning instead of running
the command."
(defun hydra-disable ()
"Disable the current Hydra."
(setq hydra-deactivate nil)
- (remove-hook 'pre-command-hook 'hydra--clearfun)
+ (remove-hook 'pre-command-hook #'hydra--clearfun)
(unless hydra--ignore
- (if (fboundp 'remove-function)
- (remove-function input-method-function #'hydra--imf)
- (when hydra--input-method-function
- (setq input-method-function hydra--input-method-function)
- (setq hydra--input-method-function nil))))
+ (remove-function input-method-function #'hydra--imf))
(dolist (frame (frame-list))
(with-selected-frame frame
(when overriding-terminal-local-map
@@ -200,14 +196,12 @@ warn: keep KEYMAP and issue a warning instead of running
the command."
(defcustom hydra-is-helpful t
"When t, display a hint with possible bindings in the echo area."
- :type 'boolean
- :group 'hydra)
+ :type 'boolean)
(defcustom hydra-default-hint ""
"Default :hint property to use for heads when not specified in
the body or the head."
- :type 'sexp
- :group 'hydra)
+ :type 'sexp)
(declare-function posframe-show "posframe")
(declare-function posframe-hide "posframe")
@@ -252,8 +246,7 @@ the body or the head."
:type '(choice
(const message)
(const lv)
- (const posframe))
- :group 'hydra)
+ (const posframe)))
(defcustom hydra-verbose nil
"When non-nil, hydra will issue some non essential style warnings."
@@ -283,8 +276,7 @@ found"
(defface hydra-face-red
'((t (:foreground "#FF0000" :bold t)))
"Red Hydra heads don't exit the Hydra.
-Every other command exits the Hydra."
- :group 'hydra)
+Every other command exits the Hydra.")
(defface hydra-face-blue
'((((class color) (background light))
@@ -327,56 +319,61 @@ Exitable only through a blue head.")
(add-to-list
'imenu-generic-expression
'("Hydras"
- "^.*(\\(defhydra\\) \\([a-zA-Z-]+\\)"
+ "^.*(\\(defhydra\\) \\([[:alpha:]-]+\\)"
2)))
;;* Find Function
-(eval-after-load 'find-func
- '(defadvice find-function-search-for-symbol
- (around hydra-around-find-function-search-for-symbol-advice
- (symbol type library) activate)
- "Navigate to hydras with `find-function-search-for-symbol'."
- (prog1 ad-do-it
- (when (symbolp symbol)
+
+;; FIXME: Maybe we can dispense with this advice if `defhydra' adds appropriate
+;; `definition-name' properties to the functions it defines?
+(advice-add 'find-function-search-for-symbol :around
+ #'hydra--around-find-function-search-for-symbol-advice)
+
+(defun hydra--around-find-function-search-for-symbol-advice
+ (orig-fun symbol type library)
+ "Navigate to hydras with `find-function-search-for-symbol'."
+ (let ((res (apply orig-fun symbol type library)))
+ (when (symbolp symbol)
;; The original function returns (cons (current-buffer) (point))
;; if it found the point.
- (unless (cdr ad-return-value)
+ (unless (cdr res)
(with-current-buffer (find-file-noselect library)
(let ((sn (symbol-name symbol)))
(when (and (null type)
- (string-match
"\\`\\(hydra-[a-z-A-Z0-9]+\\)/\\(.*\\)\\'" sn)
+ (string-match
"\\`\\(hydra-[[:alnum:]-]+\\)/\\(.*\\)\\'" sn)
(re-search-forward (concat "(defhydra " (match-string
1 sn))
nil t))
(goto-char (match-beginning 0)))
- (cons (current-buffer) (point)))))))))
+ (cons (current-buffer) (point))))))
+ res))
;;* Universal Argument
(defvar hydra-base-map
(let ((map (make-sparse-keymap)))
- (define-key map (kbd "<f1> k") 'hydra--describe-key)
- (define-key map [?\C-u] 'hydra--universal-argument)
- (define-key map [?-] 'hydra--negative-argument)
- (define-key map [?0] 'hydra--digit-argument)
- (define-key map [?1] 'hydra--digit-argument)
- (define-key map [?2] 'hydra--digit-argument)
- (define-key map [?3] 'hydra--digit-argument)
- (define-key map [?4] 'hydra--digit-argument)
- (define-key map [?5] 'hydra--digit-argument)
- (define-key map [?6] 'hydra--digit-argument)
- (define-key map [?7] 'hydra--digit-argument)
- (define-key map [?8] 'hydra--digit-argument)
- (define-key map [?9] 'hydra--digit-argument)
- (define-key map [kp-0] 'hydra--digit-argument)
- (define-key map [kp-1] 'hydra--digit-argument)
- (define-key map [kp-2] 'hydra--digit-argument)
- (define-key map [kp-3] 'hydra--digit-argument)
- (define-key map [kp-4] 'hydra--digit-argument)
- (define-key map [kp-5] 'hydra--digit-argument)
- (define-key map [kp-6] 'hydra--digit-argument)
- (define-key map [kp-7] 'hydra--digit-argument)
- (define-key map [kp-8] 'hydra--digit-argument)
- (define-key map [kp-9] 'hydra--digit-argument)
- (define-key map [kp-subtract] 'hydra--negative-argument)
+ (define-key map (kbd "<f1> k") #'hydra--describe-key)
+ (define-key map [?\C-u] #'hydra--universal-argument)
+ (define-key map [?-] #'hydra--negative-argument)
+ (define-key map [?0] #'hydra--digit-argument)
+ (define-key map [?1] #'hydra--digit-argument)
+ (define-key map [?2] #'hydra--digit-argument)
+ (define-key map [?3] #'hydra--digit-argument)
+ (define-key map [?4] #'hydra--digit-argument)
+ (define-key map [?5] #'hydra--digit-argument)
+ (define-key map [?6] #'hydra--digit-argument)
+ (define-key map [?7] #'hydra--digit-argument)
+ (define-key map [?8] #'hydra--digit-argument)
+ (define-key map [?9] #'hydra--digit-argument)
+ (define-key map [kp-0] #'hydra--digit-argument)
+ (define-key map [kp-1] #'hydra--digit-argument)
+ (define-key map [kp-2] #'hydra--digit-argument)
+ (define-key map [kp-3] #'hydra--digit-argument)
+ (define-key map [kp-4] #'hydra--digit-argument)
+ (define-key map [kp-5] #'hydra--digit-argument)
+ (define-key map [kp-6] #'hydra--digit-argument)
+ (define-key map [kp-7] #'hydra--digit-argument)
+ (define-key map [kp-8] #'hydra--digit-argument)
+ (define-key map [kp-9] #'hydra--digit-argument)
+ (define-key map [kp-subtract] #'hydra--negative-argument)
map)
"Keymap that all Hydras inherit. See `universal-argument-map'.")
@@ -525,11 +522,7 @@ Remove :color key. And sort the plist alphabetically."
(defun hydra-default-pre ()
"Default setup that happens in each head before :pre."
(when (eq input-method-function 'key-chord-input-method)
- (if (fboundp 'add-function)
- (add-function :override input-method-function #'hydra--imf)
- (unless hydra--input-method-function
- (setq hydra--input-method-function input-method-function)
- (setq input-method-function nil)))))
+ (add-function :override input-method-function #'hydra--imf)))
(defvar hydra-timeout-timer (timer-create)
"Timer for `hydra-timeout'.")
@@ -567,9 +560,7 @@ Remove :color key. And sort the plist alphabetically."
(t (format (format "%%%ds: %%%ds" key-width (- -1 doc-width)) key doc))))
(defun hydra--to-string (x)
- (if (stringp x)
- x
- (eval x)))
+ (eval x t))
(defun hydra--eval-and-format (x)
(let ((str (hydra--to-string (cdr x))))
@@ -615,7 +606,8 @@ Works for heads without a property :column."
(car y)
,max-key-len
(hydra--to-string (cdr y))
- ,max-doc-len))) x ""))
+ ,max-doc-len)))
+ x ""))
',(hydra--matrix keys n-cols n-rows))
"\n")))
@@ -627,8 +619,8 @@ Works for heads without a property :column."
", ")
,(if keys "." ""))))
(if (cl-every #'stringp
- (mapcar 'cddr alist))
- (eval res)
+ (mapcar #'cddr alist))
+ (eval res t)
res))))
(defun hydra--hint (body heads)
@@ -736,7 +728,7 @@ The expressions can be auto-expanded according to NAME."
(while (setq start
(string-match
(format
- "\\(?:%%\\(
?-?[0-9]*s?\\)\\(`[a-z-A-Z/0-9]+\\|(\\)\\)\\|\\(?:_%s_\\)\\|\\(?:[?]%s[?]\\)\\|__"
+ "\\(?:%%\\(
?-?[0-9]*s?\\)\\(`[[:alnum:]-/]+\\|(\\)\\)\\|\\(?:_%s_\\)\\|\\(?:[?]%s[?]\\)\\|__"
inner-regex
inner-regex)
docstring start))
@@ -831,14 +823,12 @@ The expressions can be auto-expanded according to NAME."
(replace-regexp-in-string
"\\(%\\)" "\\1\\1" ,rest)))))
(if (stringp rest)
- `(format ,(eval r))
+ `(format ,(eval r t))
`(format ,r))))))
(defun hydra--complain (format-string &rest args)
"Forward to (`message' FORMAT-STRING ARGS) unless `hydra-verbose' is nil."
- (if hydra-verbose
- (apply #'error format-string args)
- (apply #'message format-string args)))
+ (apply (if hydra-verbose #'error #'message) format-string args))
(defun hydra--doc (body-key body-name heads)
"Generate a part of Hydra docstring.
@@ -893,6 +883,8 @@ BODY-AFTER-EXIT is added to the end of the wrapper."
(hydra--make-callable
(cadr head))))
(doc (if (car head)
+ ;; FIXME: If the printed representation of (cadr head)
+ ;; include quotes, they should be \\= escaped!
(format "Call the head `%S' in the \"%s\" hydra.\n\n%s"
(cadr head) name doc)
(format "Call the body in the \"%s\" hydra.\n\n%s"
@@ -978,12 +970,12 @@ KEY is forwarded to `plist-get'."
:verbosity)))
(cond ((eq verbosity 0))
((eq verbosity 1)
- (message (eval hint)))
+ (message (eval hint t)))
(t
(when hydra-is-helpful
(funcall
(nth 1 (assoc hydra-hint-display-type hydra-hint-display-alist))
- (eval hint)))))))
+ (eval hint t)))))))
(defmacro hydra--make-funcall (sym)
"Transform SYM into a `funcall' to call it."
@@ -1176,11 +1168,12 @@ representing the maximum dimension of their owning
group.
(mapcar (lambda (x) (length
(hydra--to-string (nth 2 x)))) heads-group)))
(header-virtual-head `(" " nil ,column-name :column
,column-name :exit t))
(separator-virtual-head `(" " nil ,(make-string (+ 2
max-doc-len max-key-len) ?-) :column ,column-name :exit t))
- (decorated-heads (copy-tree (apply 'list header-virtual-head
separator-virtual-head heads-group))))
+ (decorated-heads (copy-tree (apply #'list header-virtual-head
separator-virtual-head heads-group))))
(push (mapcar (lambda (it)
(hydra--head-set-property it :max-key-len
max-key-len)
(hydra--head-set-property it :max-doc-len
max-doc-len))
- decorated-heads) res)))
+ decorated-heads)
+ res)))
(nreverse res))))
(defun hydra-interpose (x lst)
@@ -1318,7 +1311,7 @@ result of `defhydra'."
(cond ((stringp docstring))
((and (consp docstring)
(memq (car docstring) '(hydra--table concat format)))
- (setq docstring (concat "\n" (eval docstring))))
+ (setq docstring (concat "\n" (eval docstring t))))
(t
(setq heads (cons docstring heads))
(setq docstring "")))
@@ -1330,7 +1323,7 @@ result of `defhydra'."
(body-name (intern (format "%S/body" name)))
(body-key (cadr body))
(body-plist (cddr body))
- (base-map (or (eval (plist-get body-plist :base-map))
+ (base-map (or (eval (plist-get body-plist :base-map) t)
hydra-base-map))
(keymap (copy-keymap base-map))
(body-map (or (car body)
@@ -1344,7 +1337,7 @@ result of `defhydra'."
(body-foreign-keys (hydra--body-foreign-keys body))
(body-exit (hydra--body-exit body)))
(dolist (base body-inherit)
- (setq heads (append heads (copy-sequence (eval base)))))
+ (setq heads (append heads (copy-sequence (eval base t)))))
(dolist (h heads)
(let ((len (length h)))
(cond ((< len 2)
diff --git a/lv.el b/lv.el
index 61d0971e6a..457cb8077c 100644
--- a/lv.el
+++ b/lv.el
@@ -1,8 +1,9 @@
-;;; lv.el --- Other echo area
+;;; lv.el --- Other echo area -*- lexical-binding: t; -*-
-;; Copyright (C) 2015 Free Software Foundation, Inc.
+;; Copyright (C) 2015-2022 Free Software Foundation, Inc.
;; Author: Oleh Krehel
+;; Version: 0.15.0
;; This file is part of GNU Emacs.
@@ -42,12 +43,10 @@
(defcustom lv-use-separator nil
"Whether to draw a line between the LV window and the Echo Area."
- :group 'lv
:type 'boolean)
(defcustom lv-use-padding nil
"Whether to use horizontal padding in the LV window."
- :group 'lv
:type 'boolean)
(defface lv-separator
@@ -55,8 +54,7 @@
(((class color) (background dark)) :background "grey30"))
"Face used to draw line between the lv window and the echo area.
This is only used if option `lv-use-separator' is non-nil.
-Only the background color is significant."
- :group 'lv)
+Only the background color is significant.")
(defvar lv-wnd nil
"Holds the current LV window.")
@@ -97,7 +95,7 @@ Only the background color is significant."
(run-hooks 'lv-window-hook))
(select-window ori 'norecord)))))
-(defvar golden-ratio-mode)
+(defvar golden-ratio-mode) ;; https://github.com/roman/golden-ratio.el
(defvar lv-force-update nil
"When non-nil, `lv-message' will refresh even for the same string.")
@@ -106,15 +104,20 @@ Only the background color is significant."
"Pad STR with spaces on the left to be centered to WIDTH."
(let* ((strs (split-string str "\n"))
(padding (make-string
- (/ (- width (length (car strs))) 2)
- ?\ )))
+ (/ (- width (string-width (car strs))) 2)
+ ?\s)))
(mapconcat (lambda (s) (concat padding s)) strs "\n")))
(defun lv-message (format-string &rest args)
"Set LV window contents to (`format' FORMAT-STRING ARGS)."
- (let* ((str (apply #'format format-string args))
+ (let* ((str (apply (if (fboundp 'format-message) #'format-message #'format)
+ format-string args))
(n-lines (cl-count ?\n str))
deactivate-mark
+ ;; Keep auto-resizing out of the way.
+ ;; FIXME: We should find a way to do that without naming this specific
+ ;; package, i.e. by setting/let-binding a generic variable which
+ ;; packages like `golden-ratio' should obey.
golden-ratio-mode)
(with-selected-window (lv-window)
(when lv-use-padding
diff --git a/targets/hydra-init.el b/targets/hydra-init.el
index 881ceb68e4..1af899cbb0 100644
--- a/targets/hydra-init.el
+++ b/targets/hydra-init.el
@@ -1,6 +1,6 @@
-;;; hydra-test.el --- bare hydra init
+;;; hydra-test.el --- bare hydra init -*- lexical-binding: t; -*-
-;; Copyright (C) 2015 Free Software Foundation, Inc.
+;; Copyright (C) 2015-2022 Free Software Foundation, Inc.
;; Author: Oleh Krehel
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [elpa] externals/hydra 54e9db2b02: Fix packaging of `lv` and use lexical-binding and nadvice everywhere,
Stefan Monnier <=