reddit / emacs

Why my keybinding doesn't work?

EmilySeville7cfg · 2022-12-20 04:50
I wanna define keybinding which stands for `Alt+t, a` and works just in `markdown-mode`. Here is my attempt: (defun flymake-tldr-lint--setup-keybindings (local-set-key (kbd "M-t a") 'flymake-tldr-lint-remove-broken-all)) But when I start Emacs if fails with `Debugger entered--Lisp error: (error "Malformed arglist: (local-set-key (kbd M-t a) 'flymake-tldr-lint-remove-broken-all)")`. It's not clear for me how to fix this keybinding. `flymake-tldr-lint-remove-broken-all` is my own function.
MitchellMarquez42 · 2022-12-20 06:38
You need a `()` after the name of the function you're defining. `defun` always uses the second argument as a list of parameters so if the function doesn't need parameters we put an empty list.
Careful_Assignment · 2022-12-20 06:40
It looks like you're missing the argument list to your function called "flymake-tldr-lint--setup-keybindings". The argument list should be a list of zero or more arguments for your function and should come right after the function name. Also, you don't have a closing parenthesis for the defun.
EmilySeville7cfg · 2022-12-20 07:55
Why this code doesn't work? (require 'package) (add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t) (package-initialize) (defun replace-regexp-entire-buffer (pattern replacement) "Perform regular-expression replacement throughout buffer. pattern: pattern to search replacement: replacement for pattern" (save-excursion (goto-char (point-min)) (while (re-search-forward pattern nil t) (replace-match replacement)))) (defun remove-broken-ellipsis() "Remove {{...}} placeholders in the current buffer." (interactive) (with-current-buffer (current-buffer) (replace-regexp-entire-buffer "[ ]*{{\\.\\{3\\}}}[ ]*" ""))) (defun setup-keybindings() (local-set-key [?\C-x up] #'remove-broken-ellipsis)) ;; Must invoke `remove-broken-ellipsis` on C-x and up arrow (setup-keybindings) (custom-set-variables ;; custom-set-variables was added by Custom. ;; If you edit it by hand, you could mess it up, so be careful. ;; Your init file should contain only one such instance. ;; If there is more than one, they won't work right. '(package-selected-packages '(package-lint markdown-mode))) (custom-set-faces ;; custom-set-faces was added by Custom. ;; If you edit it by hand, you could mess it up, so be careful. ;; Your init file should contain only one such instance. ;; If there is more than one, they won't work right. ) I've copied key setup function from [here](https://www.gnu.org/software/emacs/manual/html_node/efaq/Binding-combinations-of-modifiers-and-function-keys.html) and changed it to `local-set-key`.
MitchellMarquez42 · 2022-12-20 08:12
I am not a linter or debugger. I am just a human being dispensing simple corrections out of the autism of my heart. There is a lot of code here that's fine, and is copy-pasted or auto-generated. If you had trimmed this fluff out of your example, I would tell you where (one of) the problem is. But now I don't feel like it. Instead I shall link resources so you can work through this yourself. Define-key: https://www.masteringemacs.org/article/mastering-key-bindings-emacs ... Okay fine, here's a hint. Whitespace between things matters. They can't be smushed together.