Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[HOWTO] Define a custom evil ex command #1777

Closed
benjaminbauer opened this issue Sep 12, 2019 · 3 comments
Closed

[HOWTO] Define a custom evil ex command #1777

benjaminbauer opened this issue Sep 12, 2019 · 3 comments
Labels
is:support A request for user support: questions, how-to's, and discussions re:elisp Personal configuration issues, conflicts or questions status:resolved Issue was addressed internally

Comments

@benjaminbauer
Copy link

What I want to achieve
Since I am clumsy with releasing shift, I want to add the capitalized version of ':w' and ':q' to the evil ex commands

I tried so far:

;;doom.d/config.el
(evil-ex-define-cmd "W" #'write)
;;doom.d/config.el
(after! evil 
  (evil-ex-define-cmd "W" #'write)
)

After restarting emacs and entering :W, both still results in

Unknown command: ''W"

I also tried after! evil-ex and after! evil-ex-cmd, no joy

System information

((emacs
  (version . "26.2")
  (features . "XPM JPEG TIFF GIF PNG RSVG IMAGEMAGICK SOUND GPM DBUS GSETTINGS GLIB NOTIFY LIBSELINUX GNUTLS LIBXML2 FREETYPE M17N_FLT LIBOTF XFT ZLIB TOOLKIT_SCROLL_BARS GTK3 X11 XDBE XIM MODULES THREADS XWIDGETS LIBSYSTEMD LCMS2")
  (build . "Apr 12, 2019")
  (buildopts "--build=x86_64-linux-gnu --prefix=/usr '--includedir=${prefix}/include' '--mandir=${prefix}/share/man' '--infodir=${prefix}/share/info' --sysconfdir=/etc --localstatedir=/var --disable-silent-rules '--libdir=${prefix}/lib/x86_64-linux-gnu' '--libexecdir=${prefix}/lib/x86_64-linux-gnu' --disable-maintainer-mode --disable-dependency-tracking --prefix=/usr --sharedstatedir=/var/lib --program-suffix=26 --with-modules --with-file-notification=inotify --with-mailutils --with-x=yes --with-x-toolkit=gtk3 --with-xwidgets --with-lcms2 'CFLAGS=-g -O2 -fdebug-prefix-map=/build/emacs26-CYbeHB/emacs26-26.2~1.gitfd1b34b=. -fstack-protector-strong -Wformat -Werror=format-security -no-pie' 'CPPFLAGS=-Wdate-time -D_FORTIFY_SOURCE=2' 'LDFLAGS=-Wl,-Bsymbolic-functions -Wl,-z,relro -no-pie'"))
 (doom
  (version . "2.0.9")
  (build . "HEAD -> develop, origin/develop, origin/HEAD a16838b7 2019-09-11 23:42:27 -0400"))
 (system
  (type . gnu/linux)
  (config . "x86_64-pc-linux-gnu")
  (shell . "/bin/bash")
  (uname . "Linux 4.15.0-62-generic #69-Ubuntu SMP Wed Sep 4 20:55:53 UTC 2019 x86_64")
  (path "~/.cargo/bin" "~/bin" "~/.local/bin" "/usr/local/bin" "~/.cargo/bin" "~/.local/bin" "~/bin" "/usr/local/sbin" "/usr/local/bin" "/usr/sbin" "/usr/bin" "/sbin" "/bin" "/usr/games" "/usr/local/games" "/snap/bin" "~/.fzf/bin" "/usr/lib/x86_64-linux-gnu/emacs/26.2/x86_64-linux-gnu"))
 (config
  (envfile . envvar-file)
  (elc-files . 0)
  (modules :completion company ivy :ui doom doom-dashboard hl-todo modeline nav-flash ophints (popup +all +defaults) vc-gutter vi-tilde-fringe window-select workspaces :editor evil file-templates fold multiple-cursors rotate-text snippets :emacs dired electric vc :tools eval flycheck (lookup +docsets) magit :lang data emacs-lisp markdown (org +dragndrop +ipython +pandoc +present) python rest sh :config default)
  (packages "org-caldav" "calfw" "calfw-org" "(ttl-mode :recipe (:host github :repo jeeger/ttl-mode))")
  (elpa-packages "n/a")))
@hlissner
Copy link
Member

Your first snippet is correct:

;;doom.d/config.el
(evil-ex-define-cmd "W" #'write)

However, the write function does not exist. What you wanted was evil-write:

;;doom.d/config.el
(evil-ex-define-cmd "W" #'evil-write)

@hlissner hlissner added is:support A request for user support: questions, how-to's, and discussions re:elisp Personal configuration issues, conflicts or questions status:resolved Issue was addressed internally labels Sep 12, 2019
@benjaminbauer
Copy link
Author

Thanks a lot! I was misled my the value of evil-ex-commands:

...
("write" . evil-write)
("w" . "write")
...

Here it seems that w just references write, which seems to not work when I do it via evil-ex-define-cmd

@hlissner
Copy link
Member

Ah, in that case it was because "write" is a string and #'write is a symbol. evil-ex-define-cmd treats strings as ex commands to execute and symbols as references to elisp functions. You'd have to do:

;;doom.d/config.el
(evil-ex-define-cmd "W" "write")

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 1, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
is:support A request for user support: questions, how-to's, and discussions re:elisp Personal configuration issues, conflicts or questions status:resolved Issue was addressed internally
Projects
None yet
Development

No branches or pull requests

2 participants