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

Auto save on completion is annoying #87

Closed
hpdeifel opened this issue Sep 27, 2018 · 8 comments
Closed

Auto save on completion is annoying #87

hpdeifel opened this issue Sep 27, 2018 · 8 comments

Comments

@hpdeifel
Copy link

I have company-idle-delay set to a very short delay (0.1 seconds) to get completion as quickly as possible. Unfortunately, dante auto saves the buffer every time company is triggered, which is visually annoying (mode-line flicker, messages) and also increases input latency.

On the other hand I would be totally happy with completion based on the last saved state, it's (despite my efforts) unlikely for new exported symbols to appear in a syntactically correct buffer every 0.1 seconds.

Note that I wouldn't even need auto save for flycheck, because I have flycheck-check-syntax-automatically set to (save mode-enabled).

@bezirg
Copy link

bezirg commented Feb 1, 2019

I ran into the same problem with the exact same situation.

Even worse, company's idle-time popup does not appear, probably buried immediately when the file is auto-saved by dante.

When I remove dante-company from the head of the company-backends, the dante's auto-save is no longer triggered and the company's idle popup shows as normal using the rest of the backends (e.g. company-capf, company-dabbrev).

@purcell
Copy link
Contributor

purcell commented May 17, 2019

This is a result of Dante not using temp files when it loads the current buffer into ghci: this was changed in 9955cd1 in Aug 2018. The consequence is that Dante eagerly saves the buffer whenever it makes backend requests, including for completion and flycheck etc., and it does so while suppressing any normal after-save hooks (see #84), which can cause things like hindent integration to not work as expected. There's no way to do this sneaky saving without messing up normal Emacs behaviour, so the solution is to use a temp file approach of some sort.

I'm keen to help get this fixed - I fixed it in Intero ages ago - but I'm hesitant to dive in without an understanding of the rationale behind 9955cd1. It's presumably something about handling of Tramp files but I couldn't find any specific issue to which the commit related.

@purcell
Copy link
Contributor

purcell commented May 17, 2019

Also related:

(My motivation here is to be able to use Dante more fully as an Intero replacement in order to avoid needing the intero backend. Dante mostly does the job for me, modulo these issues.)

purcell added a commit to purcell/dante that referenced this issue Jul 9, 2019
- Temp files will always be local, even when the file is remote
- Xref still works as expected (see jyp#78)

See jyp#84, fixes jyp#87
@purcell
Copy link
Contributor

purcell commented Jul 9, 2019

Hey @hpdeifel and @bezirg, maybe check out my fix for this in #122 and see if you find any issues.

@jyp
Copy link
Owner

jyp commented Aug 15, 2019

Should be fixed by c7d7070

@jyp jyp closed this as completed Aug 15, 2019
@asheshambasta
Copy link

It doesn't seem like this plays nicely if you clone an indirect buffer, in which case, I start getting prompted:

Unchanged content check: (cl-assertion-failed (equal fn (expand-file-name buffer-file-truename)))
danteIdfKwD.hs changed on disk; really edit the buffer? (y, n, r or C-h) y
File on disk now will become a backup file if you save these changes.
Unchanged content check: (cl-assertion-failed (equal fn (expand-file-name buffer-file-truename)))
danteIdfKwD.hs changed on disk; really edit the buffer? (y, n, r or C-h) n
Company: An error occurred in auto-begin
File changed on disk: /tmp/danteIdfKwD.hs
Auto-saving...

Basically, it seems that both the indirect buffer and the original buffer are attempting to write to the same temp. file: by the time one of the buffers wants to write to the file, its contents have changed.

@jyp
Copy link
Owner

jyp commented Apr 27, 2020

I do not know what "cloning an indirect buffer" is. Could you point to relevant documentation?

@asheshambasta
Copy link

asheshambasta commented Apr 28, 2020

@jyp as I understand it, it reopens what emacs calls an indirect buffer and can be invoked with M-x clone-indirect-buffer RET and its documentation:

clone-indirect-buffer is an interactive compiled Lisp function in
‘simple.el’.

It is bound to SPC SPC c.

(clone-indirect-buffer NEWNAME DISPLAY-FLAG &optional NORECORD)

Create an indirect buffer that is a twin copy of the current buffer.

Give the indirect buffer name NEWNAME.  Interactively, read NEWNAME
from the minibuffer when invoked with a prefix arg.  If NEWNAME is nil
or if not called with a prefix arg, NEWNAME defaults to the current
buffer’s name.  The name is modified by adding a ‘<N>’ suffix to it
or by incrementing the N in an existing suffix.  Trying to clone a
buffer whose major mode symbol has a non-nil ‘no-clone-indirect’
property results in an error.

DISPLAY-FLAG non-nil means show the new buffer with ‘pop-to-buffer’.
This is always done when called interactively.

Optional third arg NORECORD non-nil means do not put this buffer at the
front of the list of recently selected ones.

Returns the newly created indirect buffer.

I don't know much about Dante internals to see why this causes issues but I'd gladly help further if I can.
From a brief look at the commit you linked above, to me it seems like dante creates a temp file on disk to which it saves changes in order to provide completion. My theory is that cloning an indirect buffer means dante attempts to write to the same temp file from both buffers, leading to a race condition of sorts.


However, this is a minor issue for me. And I'd also like to thank you for Dante, it is one Emacs integration that just works in my experience.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants