Doom-emacs: [HOWTO] Define a custom evil ex command

Created on 12 Sep 2019  ·  3Comments  ·  Source: hlissner/doom-emacs

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")))

question elisp resolved

Most helpful comment

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")

All 3 comments

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)

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

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")
Was this page helpful?
0 / 5 - 0 ratings