Doom-emacs: function definition is void: ad-Advice-newline-and-indent

Created on 19 May 2020  ·  31Comments  ·  Source: hlissner/doom-emacs

What did you expect to happen?

Pressing RET in org-mode inserts a new line

What actually happened?

Triggers an error: Symbol's function definition is void: ad-Advice-newline-and-indent

Additional details:

Backtrace:


Debugger entered--Lisp error: (void-function ad-Advice-newline-and-indent)
ad-Advice-newline-and-indent(#f(compiled-function (&optional arg) "Insert a newline, then indent according to major mode.\nIndentation is done using the value of indent-line-function'.\nIn programming language modes, this is the same as TAB.\nIn some text modes, where TAB inserts a tab, this command indents to the\ncolumn specified by the functioncurrent-left-margin'.\n\nWith ARG, perform this action that many times." (interactive "p") #) nil)
apply(ad-Advice-newline-and-indent #f(compiled-function (&optional arg) "Insert a newline, then indent according to major mode.\nIndentation is done using the value of indent-line-function'.\nIn programming language modes, this is the same as TAB.\nIn some text modes, where TAB inserts a tab, this command indents to the\ncolumn specified by the functioncurrent-left-margin'.\n\nWith ARG, perform this action that many times." (interactive "
p") #) nil)
org--newline(t nil nil)
#f(compiled-function (&optional indent arg interactive) "Goto next table row or insert a newline.\n\nCalls org-table-next-row' ornewline', depending on context.\n\nWhen optional INDENT argument is non-nil, call\nnewline-and-indent' with ARG, otherwise callnewline' with ARG\nand INTERACTIVE.\n\nWhen org-return-follows-link' is non-nil and point is on\na timestamp or a link, callorg-open-at-point'. However, it\nwill not happen if point is in a table or on a \"dead\"\nobject (e.g., within a comment). In these case, you need to use\norg-open-at-point' directly." (interactive "i\nP\np") #<bytecode 0x1568f77562ed>)(t) apply(#f(compiled-function (&optional indent arg interactive) "Goto next table row or insert a newline.\n\nCallsorg-table-next-row' or newline', depending on context.\n\nWhen optional INDENT argument is non-nil, call\nnewline-and-indent' with ARG, otherwise call newline' with ARG\nand INTERACTIVE.\n\nWhenorg-return-follows-link' is non-nil and point is on\na timestamp or a link, call org-open-at-point'. However, it\nwill not happen if point is in a table or on a \"dead\"\nobject (e.g., within a comment). In these case, you need to use\norg-open-at-point' directly." (interactive "i\nP\np") #) t)
org-return(t)
(closure (t) (&rest _) (interactive) (org-return t))()
funcall-interactively((closure (t) (&rest _) (interactive) (org-return t)))
call-interactively((closure (t) (&rest _) (interactive) (org-return t)) nil nil)
command-execute((closure (t) (&rest _) (interactive) (org-return t)))

Steps to reproduce:

  1. Open a new org file
  2. Enter insert mode
  3. Press RET to insert a new line. Nothing happens.

System information:

emacs   version    27.0.91
        features   XPM JPEG TIFF GIF PNG RSVG CAIRO SOUND GPM DBUS GLIB NOTIFY INOTIFY ACL GNUTLS LIBXML2 FREETYPE HARFBUZZ LIBOTF ZLIB TOOLKIT_SCROLL_BARS GTK3 X11 XDBE XIM MODULES THREADS LIBSYSTEMD JSON PDUMPER LCMS2 GMP
        build      May 15, 2020
        buildopts  (--prefix=/usr --sysconfdir=/etc --libexecdir=/usr/lib --localstatedir=/var --mandir=/usr/share/man --with-gameuser=:games --with-sound=alsa --with-modules --without-gconf --without-gsettings --enable-autodepend --enable-link-time-optimization --with-x-toolkit=gtk3 --without-xaw3d --without-m17n-flt --with-cairo --without-compress-install 'CFLAGS=-march=x86-64 -mtune=generic -O2 -pipe -fno-plt -g -flto' CPPFLAGS=-D_FORTIFY_SOURCE=2 LDFLAGS=-Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now)
        windowsys  x
        daemonp    server-running
doom    version    2.0.9
        build      HEAD -> develop 265e80123 2020-05-19 05:35:03 -0400
        dir        ~/.doom.d/
system  type       gnu/linux
        config     x86_64-pc-linux-gnu
        shell      /usr/bin/zsh
        uname      Linux 5.4.41-1-lts #1 SMP Thu, 14 May 2020 06:53:12 +0000 x86_64
        path       (/usr/local/sbin /usr/local/bin /usr/bin /opt/flutter/bin /usr/lib/jvm/default/bin /usr/bin/site_perl /usr/bin/vendor_perl /usr/bin/core_perl ~/.local/bin /usr/lib/emacs/27.0.91/x86_64-pc-linux-gnu)
config  envfile    nil
        elc-files  0
        modules    (:completion company (ivy +icons) :ui doom fill-column hl-todo (modeline +light) (popup +defaults) vc-gutter :editor (evil +everywhere) fold snippets :emacs dired undo vc :checkers syntax :tools lookup lsp magit rgb :lang cc emacs-lisp (ess +lsp) (go +lsp) haskell latex markdown nix ocaml (org +journal +roam) (rust +lsp) sh yaml :config literate (default +bindings +smartparens))
        packages   ((solaire-mode :disable t) (simple-httpd) (org-roam-server :recipe (:host github :repo org-roam/org-roam-server)))
        unpin      (n/a)
        elpa       (n/a)

:lang org unknown

Most helpful comment

I am experiencing the same problem on my laptop, ~though not on my work PC~ [update 2020-09-14: now on both computers].
I triend doom build, nuking the org-* folders in straight, and @hlissner's snippet to pin the org version. Nothing helped.

As @bsermons mentioned, the issue is resolved by disabling electric-indent-mode. Interestingly enough, electric-indent-mode itself is not the culprit, because it works in other modes just fine, but something in the way it interacts with org-mode is causing the issue.

I've applied a bandaid to the problem with the following hook.

(add-hook 'org-mode-hook (lambda () (electric-indent-local-mode -1)))

Hopefully smarter people will find a better solution, or the issue will magically resolve itself.

All 31 comments

I'm not sure what could be causing this. I don't think it is a Doom issue, specifically, because I avoid anonymous advice in Doom on principle. It makes debugging their issues so much harder. There is a plugin somewhere (or perhaps in your private config) that advises newline-and-indent.

From within Doom, try M-x doom/help-search-load-path, and search for define-advice newline-and-indent and defadvice[^!] newline-and-indent separately. doom/help-search-load-path performs a text search on all packages in your load-path.

Try running doom build and see if that fixes the issue.

Alternatively, a user on our Discord claims that deleting ~/.emacs.d/.local/straight/repos/org-* and reinstalling your org packages (by running doom sync afterwards) fixed the issue. Does this work for you?

Searching the load path doesn't show anything except this:

2020-05-20_11-21

Running doom build didn't fix it :/

Alternatively, a user on our Discord claims that deleting ~/.emacs.d/.local/straight/repos/org-* and reinstalling your org packages (by running doom sync afterwards) fixed the issue. Does this work for you?

Thanks! This worked! (I also had to remove .emacs.d/.local/straight/build/org-* to trigger the rebuild)

So it's definitely an org package, these are the packages that were removed and rebuilt:

org-journal 
org-mode 
org-roam
org-roam-server
org-superstar
org-yt

I can also confirm that deleting build/org-* as advised above and running doom sync after that fixed the issue.

I ran into this issue as well, after upgrading Doom by nuking ~/.config/emacs/ and re-cloning and running doom install. Following the above steps fixed it.

For reference, a list of the org-* packages I had (and rebuilt):

org-cliplink
org-download
org-journal
org-mode
org-noter
org-pdftools
org-projectile
org-re-reveal
org-roam
org-superstar
org-tree-slide
org-yt

I ran into this today. Rather than wholesale rm -rf-ing all the org packages out of .local/straight/repos I did them one at a time, did a doom sync and then checked to see if clearing out that particular package fixed the issue.

Here are my results:

  • rm -rf org-mode && doom sync && emacs -> not fixed :x:
  • rm -rf org-cliplink && doom sync && emacs -> not fixed :x:
  • rm -rf org-roam && doom sync && emacs -> fixed :heavy_check_mark:

Based on that seems like it's probably something to do with org-roam.

But I don't use org-roam and I run into this issue too


my org-*

org-cliplink
org-download
orgit
org-mode
org-noter
org-pdftools
org-pomodoro
org-pretty-tags
org-ql
org-sidebar
org-super-agenda
org-yt

@AloisJanicek Weird. Might have been a false positive or my test steps might not have been complete / fresh. It stands though, that removing only those three packages fixed it. Might have been one of the others and I didn't test properly afterward -- which is more than likely :sweat_smile:

This happened again to me today and I got a little more detail on the issue / what file is getting messed up. The cause of the error is the byte compiled function org--newline in org.elc. Manually recompiling org.el fixes the issue -- however, if I rebuild using doom build (not rm -rf-ing anything) the elc has the broken version of org--newline again.

I also ran (doom-cli-packages-build t) in an active emacs session and it also generated the broken elc again.

Since I can continually get the build to produce the broken elc in my current setup I'm happy to try any debug steps. (Particularly since I can fix the issue by manually rebuilding org.elc)

I'm having the same issue, and if it matters I just updated to emacs 27.1. No fix that I tried worked.

.emacs.d on  develop [⇡?] 
➜ rm -rf ~/.emacs.d/.local/straight/repos/org-*

.emacs.d on  develop [⇡?] 
➜ bin/doom sync
> Compiling your literate config...
  - Tangled 115 code blocks from config.org.yhMzch
  - Restarting...
> Compiling your literate config...
> Synchronizing your config with Doom Emacs...
  > Regenerating envvars file at "~/.emacs.d/.local/env"
    - Ignoring DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus
    - Ignoring TERM=xterm-256color
    - Ignoring HOME=/home/schmitta
    - Ignoring PWD=/home/schmitta/.emacs.d
    ✓ Successfully generated "~/.emacs.d/.local/env"
  > Installing packages...
    > Updating recipe repos...
    → Cloning org-review...r emacsmirror-mirror...
    → Cloning org-review...done
    → Cloning org-ref...
    → Cloning org-ref...done
    → Cloning org-roam-bibtex...
    → Cloning org-roam-bibtex...done
    → Cloning org-roam...
    → Cloning org-roam...done
    → Cloning org-mode...
    → Cloning org-mode...done
    → Cloning org-yt...
    → Cloning org-yt...done
    → Cloning org-cliplink...
    → Cloning org-cliplink...done
    → Cloning org-pdftools...
    → Cloning org-pdftools...done
    → Cloning org-noter...
    → Cloning org-noter...done
    → Cloning org-journal...
    → Cloning org-journal...done
    → Cloning org-mime...
    → Cloning org-mime...done
    → Cloning org-gcal.el...
    → Cloning org-gcal.el...done
    - No packages need to be installed
  > (Re)building packages...
    ✓ No packages need rebuilding
  > Purging orphaned packages (for the emperor)...
    - No builds to purge
    - Skipping elpa packages
    - Skipping repos
    - Skipping regrafting
  > (Re)generating autoloads file...
    > Generating autoloads file...
    > Byte-compiling autoloads file...
    ✓ Generated .local/autoloads.elc
  - Restart Emacs or use 'M-x doom/reload' for changes to take effect
✓ Finished! (38.7332s)

When launching emacs, I get a (file-missing Cannot open load file No such file or directory org-version.el). I suppose it's because doom sync says No packages need rebuilding (which I find strange).

If I then do a doom build, emacs starts but the issue is still there.

I tried to run byte-compile-file on org.el and relaunch emacs, to no avail.

To make progress, is there a way to know which function is advised, so that I can remove the advice?

This must be a load-order issue at compile time. Try adding this to the top of ~/.doom.d/packages.el to force org-mode to load before any of your org plugins:

(package! org-mode
  :recipe (:host github
           :repo "emacs-straight/org-mode"
           :files ("*.el" "lisp/*.el" "contrib/lisp/*.el"))
  :pin "a1e5bee5cb9c34ceb8226597605a49638bee7cec")

Then run doom build. If that doesn't work, try deleting all org-* packages in ~/.emacs.d/.local/straight/repos, then run doom sync and see if it changes anything.

Running into this again, here's what I did

  • rm -rf ~/.emacs.d/.local/straight/repos/org-*
  • doom sync

At this point, I get the (file-missing Cannot open load file No such file or directory org-version.el) error when opening an Org file. To fix this:

  • doom build

This fixes the org-version.el error, but the ad-Advice-newline-and-indent problem is still here.

  • added the above snippet to my package.el, then ran doom build again
  • It works! only problem being having to update the pinned commit hash frequently

As of f3740d4 this issue should be fixed (org packages _should_ build in the right order from now on). For folks coming from older versions of Emacs, please update doom and run doom sync && doom build.

Let me know if that doesn't fix the issue and I'll reopen it.

I ran:

doom upgrade
doom sync
doom build

and the bug returned.
I then ran:

rm -rf ~/.emacs.d/.local/straight/build/org-*
doom sync

and it fixed the issue.

BUT, once I ran another:

doom build

the bug is back once again.
Any ideas why this issue persists?

@archiif Just in case you're on a particular commit of Doom where doom upgrade was half working, make extra sure you're on the latest build and packages:

git -C ~/.emacs.d pull
doom sync -u
doom build

Any ideas why this issue persists?

The crux of the issue is that org plugins are being compiled in the wrong order. For example, if org-roam is built before org, and org-roam tries to load org at compile time, it will load the old version of org included with Emacs, rather than the new version that will be installed by the :lang org module.

f3740d4 fixed the case where private packages (org plugins) were all installed before org was. I don't know why you're seeing different behavior, unless you are installing org, or org-plus-contrib yourself, which you shouldn't be.

I'm currently having the same issue as well. I don't have org manually installed, and I can provide my config files if need be. I attempted to load org with doom upgrade; doom sync && doom build and no extra modules added and that still doesn't work.

I have the same experience as @archiif using (org +brain +pandoc +journal +pretty +roam)

I saw electric-indent-mode in the debug trace so I toggled it off and it fixes the issue but when I turn it back it is broken again. Before the doom build, electric-indent-mode is on but works as normal.
Not sure if that helps anything but somewhat of a work around for me.

Here is the debug trace:

debugger entered--Lisp error: (void-function ad-Advice-newline-and-indent)

  ad-Advice-newline-and-indent(#f(compiled-function (&optional arg) "Insert a newline, then indent according to major mode.\nIndentation is done using the value of `indent-line-function'.\nIn programming language modes, this is the same as TAB.\nIn some text modes, where TAB inserts a tab, this command indents to the\ncolumn specified by the function `current-left-margin'.\n\nWith ARG, perform this action that many times." (interactive "*p") #<bytecode 0x1ff1cc4229c9>) nil)
  apply(ad-Advice-newline-and-indent #f(compiled-function (&optional arg) "Insert a newline, then indent according to major mode.\nIndentation is done using the value of `indent-line-function'.\nIn programming language modes, this is the same as TAB.\nIn some text modes, where TAB inserts a tab, this command indents to the\ncolumn specified by the function `current-left-margin'.\n\nWith ARG, perform this action that many times." (interactive "*p") #<bytecode 0x1ff1cc4229c9>) nil)
  org--newline(t nil nil)
  #f(compiled-function (&optional indent arg interactive) "Goto next table row or insert a newline.\n\nCalls `org-table-next-row' or `newline', depending on context.\n\nWhen optional INDENT argument is non-nil, call\n`newline-and-indent' with ARG, otherwise call `newline' with ARG\nand INTERACTIVE.\n\nWhen `org-return-follows-link' is non-nil and point is on\na timestamp or a link, call `org-open-at-point'.  However, it\nwill not happen if point is in a table or on a \"dead\"\nobject (e.g., within a comment).  In these case, you need to use\n`org-open-at-point' directly." (interactive "i\nP\np") #<bytecode 0x1ff1cc422a5d>)(t)
  apply(#f(compiled-function (&optional indent arg interactive) "Goto next table row or insert a newline.\n\nCalls `org-table-next-row' or `newline', depending on context.\n\nWhen optional INDENT argument is non-nil, call\n`newline-and-indent' with ARG, otherwise call `newline' with ARG\nand INTERACTIVE.\n\nWhen `org-return-follows-link' is non-nil and point is on\na timestamp or a link, call `org-open-at-point'.  However, it\nwill not happen if point is in a table or on a \"dead\"\nobject (e.g., within a comment).  In these case, you need to use\n`org-open-at-point' directly." (interactive "i\nP\np") #<bytecode 0x1ff1cc422a5d>) t)
  org-return(t)
  (closure (t) (&rest _) (interactive) (org-return electric-indent-mode))()
  funcall-interactively((closure (t) (&rest _) (interactive) (org-return electric-indent-mode)))
  call-interactively((closure (t) (&rest _) (interactive) (org-return electric-indent-mode)) nil nil)
  command-execute((closure (t) (&rest _) (interactive) (org-return electric-indent-mode)))

I am experiencing the same problem on my laptop, ~though not on my work PC~ [update 2020-09-14: now on both computers].
I triend doom build, nuking the org-* folders in straight, and @hlissner's snippet to pin the org version. Nothing helped.

As @bsermons mentioned, the issue is resolved by disabling electric-indent-mode. Interestingly enough, electric-indent-mode itself is not the culprit, because it works in other modes just fine, but something in the way it interacts with org-mode is causing the issue.

I've applied a bandaid to the problem with the following hook.

(add-hook 'org-mode-hook (lambda () (electric-indent-local-mode -1)))

Hopefully smarter people will find a better solution, or the issue will magically resolve itself.

Want to add to the weirdness of this problem, I just updated my arch linux today and randomly started getting this issue. Must be something to due with some dependencies of emacs/doom.
Occurs even with a totally clean doom install on emacs 27.1.
The issue is removed when disabling electric-indent-mode.

Also seeing this after an upgrade of arch after completely wiping the entire install and starting from scratch. Disabling electric-indent-mode in org seems to be a working band-aid but it would be good to know what's actually going on.

Same here with the 27.1 system upgrade.
There might be some of the inner interference that not functioning under this specific build.
But as stated as other above, after using said method, which is:

I'm currently having the same issue as well. I don't have org manually installed, and I can provide my config files if need be. I attempted to load org with doom upgrade; doom sync && doom build and no extra modules added and that still doesn't work.

As said above, with the force update, it still does not work.

I guess I can add that when using native comp instead of 27.1, the issue goes away.

I ran:

doom upgrade
doom sync
doom build

and the bug returned.
I then ran:

rm -rf ~/.emacs.d/.local/straight/build/org-*
doom sync

and it fixed the issue.

BUT, once I ran another:

doom build

the bug is back once again.
Any ideas why this issue persists?

On 27.1, this is my exact situation. "Manually building" makes it work whereas doom build causes the bug to reappear.

Same issue with emacs 27.1. The delete .local/straight/repos/org-* trick still works, but is not ideal.

Sorry folks. No closer to figuring out why this happens. I've yet to reproduce it on any of my NixOS systems or Arch/MacOS VMs, with 26.3, 27.1 and 28 (gccemacs). I have no other leads. ad-Advice-newline-and-indent is the name for an anonymous advice function attached to newline-and-indent. Doom does not use these specifically to avoid mystery issues like these, so I can only imagine it's an upstream issue. Some obscure combination of packages, one of which is somehow applying an anonymous advice that doesn't exist.

At the very least, make sure you're on the very latest version of Doom (which will install the latest org).

You could try searching your load-path with M-x doom/help-search-load-path, and search for advice newline-and-indent. Maybe that'll turn up some clues.

I have the same problem runing 27.1 and 28 on arch, i also noticed inserting a new line deletes everything after the cursor and pressing u doesn't undo this behaviour.

running the specified command returns the following:
/usr/share/emacs/27.1/lisp/obsolete/tpu-extras.el.gz:378:(defadvice newline-and-indent (around tpu-respect-bottom-scroll-margin)
and
~/.emacs.d/.local/straight/build/caml/caml.el:1659:(defadvice newline-and-indent (around

This also only seems to occure for me if the line is over the 80 char limit so its possibly a problem with the TPU-edt package

I'm having the same issue, I'm on 27.1 on OSX right now, and when I run that search I get hits from obsolete/tpu-extras in the Resources folder of the .app and interestingly enough inside of caml.el in the straight directory. Very interestingly, rebuilding org does the trick but the load paths don't change after the fix.

I think I can reliably reproduce this on both OSX and Arch if you want to screenshare - let me know and we can find a time. I'm in the discord.

The problem starting again for me. One recent change is that I unpinned org-journal (I need some recent bug fixes).

I'm running with https://github.com/hlissner/doom-emacs/issues/3172#issuecomment-683259265 (disabling electric-indent-mode for org file) at the moment, and it alleviates the issue.

I just saw this on the org-mode mailing list. I think it is related:

Since recently Org is set to respect Emacs' `eletric-indent-mode'. If
I'm not mistaken, it made to the 9.4 release, I presume that's what you
are getting.

You can find the Org News entry, and how to get the previous behavior
back in:
https://code.orgmode.org/bzg/org-mode/src/master/etc/ORG-NEWS#L323

A couple of threads that might help understand the change and the
reasoning behind it:
https://orgmode.org/list/[email protected]/
https://orgmode.org/list/[email protected]/

Was this page helpful?
0 / 5 - 0 ratings