What did you expect to happen?
I expect autofill to not touch code block in markdown file.
What actually happened?
While pasting or typing code in markdown codeblock, autofill is applied on space or RET.
Additional details:
Steps to reproduce:
System information:
Loading /etc/emacs/site-start.d/00debian.el (source)...
Loading /etc/emacs/site-start.d/50autoconf.el (source)...
Loading /etc/emacs/site-start.d/50cmake-data.el (source)...
Loading /etc/emacs/site-start.d/50dictionaries-common.el (source)...
Loading debian-ispell...
Loading /var/cache/dictionaries-common/emacsen-ispell-default.el (source)...
Loading /var/cache/dictionaries-common/emacsen-ispell-dicts.el (source)...
((emacs
(version . "26.1")
(features . "XPM JPEG TIFF GIF PNG RSVG IMAGEMAGICK SOUND GPM DBUS GSETTINGS NOTIFY ACL LIBSELINUX GNUTLS LIBXML2 FREETYPE M17N_FLT LIBOTF XFT ZLIB TOOLKIT_SCROLL_BARS GTK3 X11 THREADS LIBSYSTEMD LCMS2")
(build . "sept. 23, 2019")
(buildopts "--build x86_64-linux-gnu --prefix=/usr --sharedstatedir=/var/lib --libexecdir=/usr/lib --localstatedir=/var/lib --infodir=/usr/share/info --mandir=/usr/share/man --enable-libsystemd --with-pop=yes --enable-locallisppath=/etc/emacs:/usr/local/share/emacs/26.1/site-lisp:/usr/local/share/emacs/site-lisp:/usr/share/emacs/26.1/site-lisp:/usr/share/emacs/site-lisp --with-sound=alsa --without-gconf --with-mailutils --build x86_64-linux-gnu --prefix=/usr --sharedstatedir=/var/lib --libexecdir=/usr/lib --localstatedir=/var/lib --infodir=/usr/share/info --mandir=/usr/share/man --enable-libsystemd --with-pop=yes --enable-locallisppath=/etc/emacs:/usr/local/share/emacs/26.1/site-lisp:/usr/local/share/emacs/site-lisp:/usr/share/emacs/26.1/site-lisp:/usr/share/emacs/site-lisp --with-sound=alsa --without-gconf --with-mailutils --with-x=yes --with-x-toolkit=gtk3 --with-toolkit-scroll-bars 'CFLAGS=-g -O2 -fdebug-prefix-map=/build/emacs-StqULU/emacs-26.1+1=. -fstack-protector-strong -Wformat -Werror=format-security -Wall' 'CPPFLAGS=-Wdate-time -D_FORTIFY_SOURCE=2' LDFLAGS=-Wl,-z,relro")
(windowsys . batch)
(daemonp . server-running))
(doom
(version . "2.0.9")
(build . "HEAD, origin/develop, origin/HEAD 097972bd9 2020-01-28 20:47:45 -0500")
(dir . "~/.config/doom/"))
(system
(type . gnu/linux)
(config . "x86_64-pc-linux-gnu")
(shell . "/bin/bash")
(uname . "Linux 4.19.0-6-amd64 #1 SMP Debian 4.19.67-2+deb10u2 (2019-11-11) x86_64")
(path "~/.cache/pyenv/plugins/pyenv-virtualenvwrapper/shims" "~/.cache/pyenv/libexec" "~/.cache/pyenv/plugins/python-build/bin" "~/.cache/pyenv/plugins/pyenv-virtualenvwrapper/bin" "~/.cache/pyenv/plugins/pyenv-virtualenv/bin" "~/.cache/pyenv/plugins/pyenv-update/bin" "~/.cache/pyenv/plugins/pyenv-installer/bin" "~/.cache/pyenv/plugins/pyenv-doctor/bin" "~/.cache/pyenv/shims" "~/.gem/ruby/2.3.0/bin" "~/.poetry/bin" "~/.cache/pyenv/shims" "~/.cache/pyenv/bin" "~/.cache/gopath/bin" "~/.local/bin" "~/.poetry/bin" "~/.gem/ruby/2.3.0/bin" "~/.poetry/bin" "~/.cache/pyenv/shims" "~/.cache/pyenv/bin" "~/.cache/gopath/bin" "~/.local/bin" "~/.poetry/bin" "/usr/local/bin" "/usr/bin" "/bin" "/usr/local/games" "/usr/games" "/usr/lib/emacs/26.1/x86_64-linux-gnu"))
(config
(envfile . envvar-file)
(elc-files . 32)
(modules :completion company ivy :ui doom doom-dashboard doom-quit fill-column hl-todo indent-guides modeline nav-flash neotree ophints (popup +all +defaults) tabs vc-gutter vi-tilde-fringe window-select workspaces zen :editor (evil +bindings +everywhere) fold multiple-cursors rotate-text snippets :emacs dired electric vc :tools ansible direnv docker editorconfig eval (lookup +docsets) lsp magit :lang (cc +lsp) data emacs-lisp go (java +meghanada) (javascript +lsp) markdown org php (python +pyenv) rst sh web :checkers syntax :config (default +bindings +smartparens))
(packages . "<(void-function sp-point-in-string)>")
(elpa "n/a")
(unpin "n/a")))
This also happens in LaTeX math blocks (\begin{equation}, \begin{align}...)
Would be nice if autofill was disabled there also.
EDIT: reorganizing
After reading up on autofill in EmacsWiki, you can use the code face for determining whether to autofill:
(set (make-local-variable 'fill-nobreak-predicate)
(lambda ()
(not (eq (get-text-property (point) 'face)
'markdown-code-face)))
And in latex, texmathp checks if point is in math:
(add-hook! 'TeX-mode-hook
(set (make-local-variable 'fill-nobreak-predicate) 'texmathp))
though maybe there's a more general solution, that will cover not only math but also tikz pictures and other non-textual envs.
@yoavm448 great ! Do you know if that could be included in Doom ?
... I don't know. I might be able to create a PR once I manage to get magit and forge to fork stuff. Haven't really got time for that now though, maybe next week.
Ok, I'll try if you don't mind.
Those settings break the pre-existing nobreak predicates for those modes. And shouldn't the first predicate be inverted?
(setq-hook! 'markdown-mode-hook
fill-nobreak-predicate (cons #'markdown-code-block-at-point-p
fill-nobreak-predicate))
(setq-hook! 'TeX-mode-hook
fill-nobreak-predicate (cons #'texmathp fill-nobreak-predicate))
If so, I'll add them to Doom.
Yeah, you are entirely correct.