jwiegley / use-package

A use-package declaration for simplifying your .emacs
https://jwiegley.github.io/use-package
GNU General Public License v3.0
4.41k stars 260 forks source link

unbind-key cannot handle remap #827

Open seagle0128 opened 4 years ago

seagle0128 commented 4 years ago

For example:

(unbind-key ([remap xref-find-definitions]) go-mode-map)

Return errors:

Debugger entered--Lisp error: (invalid-function [remap xref-find-definitions])
  ([remap xref-find-definitions])
  (let* ((name ([remap xref-find-definitions])) (key (if (vectorp name) name (read-kbd-macro name))) (kdesc (cons (if (stringp name) name (key-description name)) 'go-mode-map)) (binding (lookup-key (or go-mode-map global-map) key))) (let ((entry (assoc kdesc personal-keybindings)) (details (list nil (if (numberp binding) nil binding)))) (if entry (setcdr entry details) (add-to-list 'personal-keybindings (cons kdesc details)))) (define-key (or go-mode-map global-map) key nil))
  (progn (let* ((name ([remap xref-find-definitions])) (key (if (vectorp name) name (read-kbd-macro name))) (kdesc (cons (if (stringp name) name (key-description name)) 'go-mode-map)) (binding (lookup-key (or go-mode-map global-map) key))) (let ((entry (assoc kdesc personal-keybindings)) (details (list nil (if (numberp binding) nil binding)))) (if entry (setcdr entry details) (add-to-list 'personal-keybindings (cons kdesc details)))) (define-key (or go-mode-map global-map) key nil)) (setq personal-keybindings (cl-delete-if #'(lambda (k) (and (consp (car k)) (string= (car ...) (...)) (eq (cdr ...) 'go-mode-map))) personal-keybindings)))
  (progn (progn (let* ((name ([remap xref-find-definitions])) (key (if (vectorp name) name (read-kbd-macro name))) (kdesc (cons (if (stringp name) name (key-description name)) 'go-mode-map)) (binding (lookup-key (or go-mode-map global-map) key))) (let ((entry (assoc kdesc personal-keybindings)) (details (list nil (if ... nil binding)))) (if entry (setcdr entry details) (add-to-list 'personal-keybindings (cons kdesc details)))) (define-key (or go-mode-map global-map) key nil)) (setq personal-keybindings (cl-delete-if #'(lambda (k) (and (consp ...) (string= ... ...) (eq ... ...))) personal-keybindings))))
  eval((progn (progn (let* ((name ([remap xref-find-definitions])) (key (if (vectorp name) name (read-kbd-macro name))) (kdesc (cons (if ... name ...) 'go-mode-map)) (binding (lookup-key (or go-mode-map global-map) key))) (let ((entry (assoc kdesc personal-keybindings)) (details (list nil ...))) (if entry (setcdr entry details) (add-to-list 'personal-keybindings (cons kdesc details)))) (define-key (or go-mode-map global-map) key nil)) (setq personal-keybindings (cl-delete-if #'(lambda (k) (and ... ... ...)) personal-keybindings)))) t)
  elisp--eval-last-sexp(nil)
  #f(compiled-function (eval-last-sexp-arg-internal) "Evaluate sexp before point; print value in the echo area.\nInteractively, with a non `-' prefix argument, print output into\ncurrent buffer.\n\nNormally, this function truncates long output according to the\nvalue of the variables `eval-expression-print-length' and\n`eval-expression-print-level'.  With a prefix argument of zero,\nhowever, there is no such truncation.\nInteger values are printed in several formats (decimal, octal,\nand hexadecimal).  When the prefix argument is -1 or the value\ndoesn't exceed `eval-expression-print-maximum-character', an\ninteger value is also printed as a character of that codepoint.\n\nIf `eval-expression-debug-on-error' is non-nil, which is the default,\nthis command arranges for all errors to enter the debugger." (interactive "P") #<bytecode -0xfa514315a573e0d>)(nil)
  apply(#f(compiled-function (eval-last-sexp-arg-internal) "Evaluate sexp before point; print value in the echo area.\nInteractively, with a non `-' prefix argument, print output into\ncurrent buffer.\n\nNormally, this function truncates long output according to the\nvalue of the variables `eval-expression-print-length' and\n`eval-expression-print-level'.  With a prefix argument of zero,\nhowever, there is no such truncation.\nInteger values are printed in several formats (decimal, octal,\nand hexadecimal).  When the prefix argument is -1 or the value\ndoesn't exceed `eval-expression-print-maximum-character', an\ninteger value is also printed as a character of that codepoint.\n\nIf `eval-expression-debug-on-error' is non-nil, which is the default,\nthis command arranges for all errors to enter the debugger." (interactive "P") #<bytecode -0xfa514315a573e0d>) nil)
  eval-last-sexp(nil)
  funcall-interactively(eval-last-sexp nil)
  call-interactively(eval-last-sexp nil nil)
  #f(compiled-function (cmd &optional record-flag keys special) "Execute CMD as an editor command.\nCMD must be a symbol that satisfies the `commandp' predicate.\nOptional second arg RECORD-FLAG non-nil\nmeans unconditionally put this command in the variable `command-history'.\nOtherwise, that is done only if an arg is read using the minibuffer.\nThe argument KEYS specifies the value to use instead of (this-command-keys)\nwhen reading the arguments; if it is nil, (this-command-keys) is used.\nThe argument SPECIAL, if non-nil, means that this command is executing\na special event, so ignore the prefix argument and don't clear it." #<bytecode 0x1aca69de5b3cc60f>)(eval-last-sexp nil nil nil)
  ad-Advice-command-execute(#f(compiled-function (cmd &optional record-flag keys special) "Execute CMD as an editor command.\nCMD must be a symbol that satisfies the `commandp' predicate.\nOptional second arg RECORD-FLAG non-nil\nmeans unconditionally put this command in the variable `command-history'.\nOtherwise, that is done only if an arg is read using the minibuffer.\nThe argument KEYS specifies the value to use instead of (this-command-keys)\nwhen reading the arguments; if it is nil, (this-command-keys) is used.\nThe argument SPECIAL, if non-nil, means that this command is executing\na special event, so ignore the prefix argument and don't clear it." #<bytecode 0x1aca69de5b3cc60f>) eval-last-sexp)
  apply(ad-Advice-command-execute #f(compiled-function (cmd &optional record-flag keys special) "Execute CMD as an editor command.\nCMD must be a symbol that satisfies the `commandp' predicate.\nOptional second arg RECORD-FLAG non-nil\nmeans unconditionally put this command in the variable `command-history'.\nOtherwise, that is done only if an arg is read using the minibuffer.\nThe argument KEYS specifies the value to use instead of (this-command-keys)\nwhen reading the arguments; if it is nil, (this-command-keys) is used.\nThe argument SPECIAL, if non-nil, means that this command is executing\na special event, so ignore the prefix argument and don't clear it." #<bytecode 0x1aca69de5b3cc60f>) eval-last-sexp)
  command-execute(eval-last-sexp)
conao3 commented 4 years ago

In README - key-binding remap example is here

(use-package unfill
  :bind ([remap fill-paragraph] . unfill-toggle))

I'll bit change it to suit your situation.

(use-package go-mode
  :bind (:map go-mode-map
              ([remap xref-find-definitions] . nil)))

macroexpand use-package

(pp
 (let ((use-package-expand-minimally t))
   (macroexpand-1
    '(use-package go-mode
       :bind (:map go-mode-map
                   ([remap xref-find-definitions] . nil))))))
;;=> (progn
;;     (require 'go-mode nil nil)
;;     (bind-keys :package go-mode :map go-mode-map
;;                ([remap xref-find-definitions])))

and macroexpand bind-keys

(pp
 (let ((use-package-expand-minimally t))
   (macroexpand-1
    '(bind-keys :package go-mode :map go-mode-map
                ([remap xref-find-definitions])))))
;;=> (if (boundp 'go-mode-map)
;;       (bind-key [remap xref-find-definitions] nil go-mode-map nil)
;;     (eval-after-load 'go-mode
;;       '(bind-key
;;         [remap xref-find-definitions]
;;         nil go-mode-map nil)))

BTW, macroexpand unbind-key

(pp
 (macroexpand-1
  '(unbind-key ([remap xref-find-definitions]) go-mode-map)))
;;=> (progn
;;     (bind-key ([remap xref-find-definitions]) nil go-mode-map)
;;     (setq personal-keybindings
;;           (cl-delete-if
;;            #'(lambda (k)
;;                (and (consp (car k))
;;                 (string= (caar k) ([remap xref-find-definitions]))
;;                 (eq (cdar k) 'go-mode-map)))
;;            personal-keybindings)))

(pp
 (macroexpand-1
  '(unbind-key [remap xref-find-definitions] go-mode-map)))
;;=> (progn
;;     (bind-key [remap xref-find-definitions] nil go-mode-map)
;;     (setq personal-keybindings
;;           (cl-delete-if
;;            #'(lambda (k)
;;                (and (consp (car k))
;;                 (string= (caar k) [remap xref-find-definitions])
;;                 (eq (cdar k) 'go-mode-map)))
;;            personal-keybindings)))

As this result, you would use unbind-key like below but this sexp also error :)

(unbind-key [remap xref-find-definitions] go-mode-map)
Debugger entered--Lisp error: (wrong-type-argument stringp [remap xref-find-definitions])
  string=("<remap> <fill-paragraph>" [remap xref-find-definitions])
  (and (consp (car k)) (string= (car (car k)) [remap xref-find-definitions]) (eq (cdr (car k)) (quote go-mode-map)))
  (lambda (k) (and (consp (car k)) (string= (car (car k)) [remap xref-find-definitions]) (eq (cdr (car k)) (quote go-mode-map))))((("<remap> <fill-paragraph>") nil nil))
  cl-delete(nil ((("<remap> <fill-paragraph>") nil nil) (("<remap> <xref-find-definitions>" . go-mode-map) nil nil)) :if (lambda (k) (and (consp (car k)) (string= (car (car k)) [remap xref-find-definitions]) (eq (cdr (car k)) (quote go-mode-map)))))
  apply(cl-delete nil ((("<remap> <fill-paragraph>") nil nil) (("<remap> <xref-find-definitions>" . go-mode-map) nil nil)) :if (lambda (k) (and (consp (car k)) (string= (car (car k)) [remap xref-find-definitions]) (eq (cdr (car k)) (quote go-mode-map)))) nil)
  cl-delete-if((lambda (k) (and (consp (car k)) (string= (car (car k)) [remap xref-find-definitions]) (eq (cdr (car k)) (quote go-mode-map)))) ((("<remap> <fill-paragraph>") nil nil) (("<remap> <xref-find-definitions>" . go-mode-map) nil nil)))
  (setq personal-keybindings (cl-delete-if (function (lambda (k) (and (consp (car k)) (string= (car (car k)) [remap xref-find-definitions]) (eq (cdr (car k)) (quote go-mode-map))))) personal-keybindings))
  (progn (let* ((name [remap xref-find-definitions]) (key (if (vectorp name) name (read-kbd-macro name))) (kdesc (cons (if (stringp name) name (key-description name)) (quote go-mode-map))) (binding (lookup-key (or go-mode-map global-map) key))) (let ((entry (assoc kdesc personal-keybindings)) (details (list nil (if (numberp binding) nil binding)))) (if entry (setcdr entry details) (add-to-list (quote personal-keybindings) (cons kdesc details)))) (define-key (or go-mode-map global-map) key nil)) (setq personal-keybindings (cl-delete-if (function (lambda (k) (and (consp (car k)) (string= (car ...) [remap xref-find-definitions]) (eq (cdr ...) (quote go-mode-map))))) personal-keybindings)))
  eval((progn (let* ((name [remap xref-find-definitions]) (key (if (vectorp name) name (read-kbd-macro name))) (kdesc (cons (if (stringp name) name (key-description name)) (quote go-mode-map))) (binding (lookup-key (or go-mode-map global-map) key))) (let ((entry (assoc kdesc personal-keybindings)) (details (list nil (if ... nil binding)))) (if entry (setcdr entry details) (add-to-list (quote personal-keybindings) (cons kdesc details)))) (define-key (or go-mode-map global-map) key nil)) (setq personal-keybindings (cl-delete-if (function (lambda (k) (and (consp ...) (string= ... [remap xref-find-definitions]) (eq ... ...)))) personal-keybindings))) nil)
  elisp--eval-last-sexp(t)
  #f(compiled-function (eval-last-sexp-arg-internal) "Evaluate sexp before point; print value in the echo area.\nInteractively, with a non `-' prefix argument, print output into\ncurrent buffer.\n\nNormally, this function truncates long output according to the\nvalue of the variables `eval-expression-print-length' and\n`eval-expression-print-level'.  With a prefix argument of zero,\nhowever, there is no such truncation.\nInteger values are printed in several formats (decimal, octal,\nand hexadecimal).  When the prefix argument is -1 or the value\ndoesn't exceed `eval-expression-print-maximum-character', an\ninteger value is also printed as a character of that codepoint.\n\nIf `eval-expression-debug-on-error' is non-nil, which is the default,\nthis command arranges for all errors to enter the debugger." (interactive "P") #<bytecode 0x1f2d8b>)(t)
  ad-Advice-eval-last-sexp(#f(compiled-function (eval-last-sexp-arg-internal) "Evaluate sexp before point; print value in the echo area.\nInteractively, with a non `-' prefix argument, print output into\ncurrent buffer.\n\nNormally, this function truncates long output according to the\nvalue of the variables `eval-expression-print-length' and\n`eval-expression-print-level'.  With a prefix argument of zero,\nhowever, there is no such truncation.\nInteger values are printed in several formats (decimal, octal,\nand hexadecimal).  When the prefix argument is -1 or the value\ndoesn't exceed `eval-expression-print-maximum-character', an\ninteger value is also printed as a character of that codepoint.\n\nIf `eval-expression-debug-on-error' is non-nil, which is the default,\nthis command arranges for all errors to enter the debugger." (interactive "P") #<bytecode 0x1f2d8b>) t)
  apply(ad-Advice-eval-last-sexp #f(compiled-function (eval-last-sexp-arg-internal) "Evaluate sexp before point; print value in the echo area.\nInteractively, with a non `-' prefix argument, print output into\ncurrent buffer.\n\nNormally, this function truncates long output according to the\nvalue of the variables `eval-expression-print-length' and\n`eval-expression-print-level'.  With a prefix argument of zero,\nhowever, there is no such truncation.\nInteger values are printed in several formats (decimal, octal,\nand hexadecimal).  When the prefix argument is -1 or the value\ndoesn't exceed `eval-expression-print-maximum-character', an\ninteger value is also printed as a character of that codepoint.\n\nIf `eval-expression-debug-on-error' is non-nil, which is the default,\nthis command arranges for all errors to enter the debugger." (interactive "P") #<bytecode 0x1f2d8b>) t)
  eval-last-sexp(t)
  eval-print-last-sexp(nil)
  funcall-interactively(eval-print-last-sexp nil)
  call-interactively(eval-print-last-sexp nil nil)
  command-execute(eval-print-last-sexp)