unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Issue or feature?
       [not found] <20201224030549.qtmvcjmi4zw4pcgw.ref@Ergus>
@ 2020-12-24  3:05 ` Ergus
  2020-12-24  3:50   ` Stefan Monnier
  0 siblings, 1 reply; 2+ messages in thread
From: Ergus @ 2020-12-24  3:05 UTC (permalink / raw)
  To: emacs-devel

Hi I have observed something that IMO is an unintended behavior.

I have more or less this code in my init:

```
(add-hook 'prog-mode-hook (lambda ()
	                       (run-with-idle-timer 1 nil #'flycheck-mode 1)))

...

(add-hook 'prog-mode-hook (lambda ()
	                       (run-with-idle-timer 1 nil #'turn-on-diff-hl-mode)))
```

Both functions: flycheck-mode and turn-on-diff-hl-mode seems to call
some external commands (ispell and git)

but then I get an error when debugging:

```
Debugger entered--Lisp error: (error "Failed (status 128): git --no-pager diff-index --e...")
   signal(error ("Failed (status 128): git --no-pager diff-index --e..."))
   error("Failed (%s): %s" "status 128" "git --no-pager diff-index --exit-code -U0 -p 4b825...")
   vc-do-command(" *diff-hl* " 1 "git" ("/home/ergo/.emacs.d/init.el") "--no-pager" "diff-index" "--exit-code" "-U0" "-p" "4b825dc642cb6eb9a060e54bf8d69288fbee4904" nil "--")
   apply(vc-do-command " *diff-hl* " 1 "git" ("/home/ergo/.emacs.d/init.el") ("--no-pager" "diff-index" "--exit-code" "-U0" "-p" "4b825dc642cb6eb9a060e54bf8d69288fbee4904" nil "--"))
   vc-git-command(" *diff-hl* " 1 ("/home/ergo/.emacs.d/init.el") "diff-index" "--exit-code" "-U0" "-p" "4b825dc642cb6eb9a060e54bf8d69288fbee4904" nil "--")
   apply(vc-git-command " *diff-hl* " 1 ("/home/ergo/.emacs.d/init.el") "diff-index" "--exit-code" ("-U0" "-p" "4b825dc642cb6eb9a060e54bf8d69288fbee4904" nil "--"))
   vc-git-diff(("/home/ergo/.emacs.d/init.el") "4b825dc642cb6eb9a060e54bf8d69288fbee4904" nil " *diff-hl* ")
   apply(vc-git-diff (("/home/ergo/.emacs.d/init.el") "4b825dc642cb6eb9a060e54bf8d69288fbee4904" nil " *diff-hl* "))
   vc-call-backend(Git diff ("/home/ergo/.emacs.d/init.el") "4b825dc642cb6eb9a060e54bf8d69288fbee4904" nil " *diff-hl* ")
   diff-hl-changes-buffer("/home/ergo/.emacs.d/init.el" Git)
   diff-hl-changes()
   diff-hl-update()
   diff-hl-margin-mode(1)
   (if (display-graphic-p) nil (diff-hl-margin-mode 1))
   (unless (display-graphic-p) (diff-hl-margin-mode 1))
   (progn (turn-on-diff-hl-mode) (unless (display-graphic-p) (diff-hl-margin-mode 1)))
   (if (or (and buffer-file-name (not (file-remote-p buffer-file-name))) (eq major-mode 'vc-dir-mode)) (progn (turn-on-diff-hl-mode) (unless (display-graphic-p) (diff-hl-margin-mode 1))))
   (when (or (and buffer-file-name (not (file-remote-p buffer-file-name))) (eq major-mode 'vc-dir-mode)) (turn-on-diff-hl-mode) (unless (display-graphic-p) (diff-hl-margin-mode 1)))
   my/diff-hl-mode()
   apply(my/diff-hl-mode nil)
   timer-event-handler([t 0 1 0 nil my/diff-hl-mode nil idle 0])
   input-pending-p(t)
   sit-for(0)
   ispell-init-process()
   ispell-buffer-local-words()
   ispell-accept-buffer-local-defs()
   flyspell-accept-buffer-local-defs(force)
   flyspell-mode-on(nil)
   flyspell-mode(1)
   flyspell-prog-mode()
   apply(flyspell-prog-mode nil)
   timer-event-handler([t 0 1 0 nil flyspell-prog-mode nil idle 0])
```

When I set different delays to the timers the error disappears.

I have 5 different similar hooks:

```
C-h v prog-mode-hook

((lambda nil
    (run-with-idle-timer 1 nil #'flycheck-mode 1))
  (lambda nil
    (run-with-idle-timer 1 nil #'company-mode 1))
  (lambda nil
    (run-with-idle-timer 1 nil #'flyspell-prog-mode))
  (lambda nil
    (run-with-idle-timer 1 nil #'diff-hl-mode 1))
  (lambda nil
    (electric-pair-local-mode 1)))
```

But the problem seems to be related with the ones that start external
processes only.

I know how to fix his in my config, but I am wondering if this is a
limitation for run-with-idle-timer? Or if such behavior needs to be (or
is already) documented?

Best,
Ergus



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Issue or feature?
  2020-12-24  3:05 ` Issue or feature? Ergus
@ 2020-12-24  3:50   ` Stefan Monnier
  0 siblings, 0 replies; 2+ messages in thread
From: Stefan Monnier @ 2020-12-24  3:50 UTC (permalink / raw)
  To: Ergus; +Cc: emacs-devel

> (add-hook 'prog-mode-hook (lambda ()
> 	                       (run-with-idle-timer 1 nil #'flycheck-mode 1)))

Timers are run in a rather unpredictable context, so you'll want to do
something like:

    (add-hook 'prog-mode-hook
              (lambda ()
                (run-with-idle-timer 1 nil
                  (lambda (buf) (with-current-buffer buf (flycheck-mode 1)))
                  (current-buffer))))

-- Stefan




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-12-24  3:50 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20201224030549.qtmvcjmi4zw4pcgw.ref@Ergus>
2020-12-24  3:05 ` Issue or feature? Ergus
2020-12-24  3:50   ` Stefan Monnier

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).