"Modified file" dialog pops up when I edit a file after make/0 in PCEMacs (v. 9.1.1)

Hi everyone. I’m having a bit of trouble with PCEmacs. In short, when I edit a
file it immediately pops up a dialog saying the file has been modified and
asking me whether to reload it. I give more details below, but this is a bit
dangerous because if I accidentally press “Reload” I risk losing work.

Here are some more details on what happens and how to reproduce it, at least
on my system. I’m running SWI 9.1.1, 64-bit on Windows 11.

  1. Save the following as a file pcemacs_test.pl:
:-module(pcemacs_test, [pred/1
                       ]).

pred(X):-
        pred_1(X).

pred_1(a).
pred_1(b).
  1. Double-click pcemacs_test.pl to load it in memory and start the SWI console.

  2. Open pcemacs_test.pl in PCEmacs:

?- edit(pcemacs_test).
true.
  1. Press “Ctrl + End” to place the cursor at the end of the file, as shown in
    the image:

pcemacs1

  1. Press Enter to add a newiline:

pcemacs2

  1. Save pcemacs_test.pl:

pcemacs3

  1. At the top-level, call make/0:
?- make.
% c:/users/[REDACTED]/pcemacs_test compiled into pcemacs_test 0.00 sec, -3 clauses
true.
  1. Return to PCEmacs and press Enter again:

The “Modified file” dialog pops up.

Note that the same happens if you type any key instead of Enter.

I first noticed this happening around 23 September this year, when I got a new
laptop with Windows 11 on it (I know). I downloaded the latest SWI-Prolog
version, but I’m not sure which version that was. I have a couple of left-over
installers on my machine and the earliest is swipl-9.0.2-1.x64.exe.

I went back to version 8.4.3 (64 bit for windows) and I don’t get the same
thing. No reload dialog pops up when I edit a PCEMacs buffer after calling
make/0.

If this is correct behaviour, is there a way to set a flag or something else
to turn it off?

If it’s not correct behaviour - what do I do?

Cheers,
Stassa

It is rather unclear where this comes from. Others? The behavior is defined in buffer.pl, which you can find after starting PceEmacs and than run

?- edit(_->check_modified_file).

Which should get you at

check_modified_file(B, Frame:frame=[frame], Confirm:confirm=[bool]) :->
    "Check if file has been modified after buffer"::
    (   get(B, file, File),
        File \== @nil,
        send(File, exists),
        get(B, time_stamp, Stamp),
        get(File, time, FileStamp),
        \+ send(Stamp, equal, FileStamp),
        \+ object(@emacs_reverting)
    ->  (   confirm_reload(B, Frame, Confirm, File)
        ->  send(B, revert)
        ;   true
        )
    ;   true
    ).

Possibly some print statements will help figuring out what is wrong. You can also try playing around with the file object, e.g.

 ?- new(F, file('c:/users/[REDACTED]/pcemacs_test.pl')).
 ?- get($F, time, Time).
 ...

etc. Possibly that reveals what is wrong. Any weird (non-ASCII) characters in [REDACTED]? Some things have changed to the low-level API to the filesystem on Windows.

Hi Jan,

Thanks for the quick reply! No weird characters in [REDACTED] (you can see them in the last screenshot :).

I’ll have a look at buffer.pl and see if I can find something.

Thanks!
Stassa

One thing that often bites on atypical filesystems is case-(in)sensitivity. For example, what would happen had the original file name really been “Buffer.pl” ?

I think this is something to do with user permissions on MS Windows.

The user account I’ve been using is not an admin account. When I use an admin account, I don’t get the pop-up asking me to reload.

Additionally, when I make/0 the project with an instance of SWI started as an administrator, I get this output:

?- make.
% Updating index for library c:/program files/swipl/library/
% Updating index for library c:/program files/swipl/xpce/prolog/lib/
true.

I tried that but it didn’t change anything. And I must have broken something because now after renaming the file back to buffer.pl, this:

edit(_->check_modified_file).

Doesn’t find the right buffer.pl - it just opens an empty file. (Edit: even after uninstalling and reinstalling. I don’t understand).

This is not even a good guess but something that needs to be checked.

Windows 10 Controlled Folder Access and file access predicate errors

I would add more but I need to re-read and run all of the checks in the link just to refresh my memory.

That is a hint. It would be a bit odd if you can read and write the file, but cannot get its time stamp. Try using the xpce class file on the target file.

That is normal. Considering the modification times left by the installer it is quite likely it considers the indexes out of date, but if it can’t write them anyway it doesn’t bother. When you run as admin it should do this update once.

Note that you first need to start the editor to get this code loaded. Next, this should work.

Unfortunately, I think this was a false guess on my part. I was not following the steps I documented above exactly, so I got confused. If I follow those steps exactly, my admin account does pop up the “Reload” dialog.

I get this update more than once, I think maybe two or three times after I uninstall and reinstall.

Btw, there’s a message about updating xpce/prolog/lib also, I edited my post on discord after you’ve read it probably.

Yes, I first open my pcemacs_test.pl file in PCEmacs, then I try edit(_->check_modified_file)., but what opens is a blank file titled buffer.pl.

If I call edit(buffer.pl) PCEmacs opens the right buffer.pl, but I can’t seem to get it to find the send method.

Thanks! But “Controlled folder access” is set to off on my user account. And I think the permissions thing was a red herring after all.

I can tell that the SWI uninstaller is leaving behind some files, e.g. the console history. Is there a way to really remove everything, as if SWI had never been installed on a machine?

I’m asking because I don’t understand e.g. why I cant edit check_modified_file directly anymore. This morning, just before I tried changing the capitalisation of its file name I could, but now I can’t, even after having uninstalled and re-installed swi multiple times. There must be something that remains in memory and messes things up at least for that (and probably nothing to do with my main issue).

I tried deleting some registry keys manually but I’m not sure I got everything. What else should I remove? I want to try and make a clean install, as much as possible (since this is windows and it just has to go and put things where you’ll never find them grumble).

Well, the method is there, and if it is no longer you must have messed up something … It is a bit hard to guess what from here :frowning:

Bottom line on what it does is that it maintains a time_stamp slot on the buffer from the last load or save. If the buffer goes from unmodified to modified (first modification) it validates this stamp to the time it gets from the file object. Both use file<-time, which returns a date object that contains the POSIX time stamp (seconds after 1970). The two are compared using date->equal. Something must be going wrong there. Either some permission/file system issue that returns bogus values or some precision issue that makes it return slightly different values that do not compare equal.

I can’t reproduce this, neither on Wine, nor on Windows 11 in a VM.

Thanks. I’ll see if I can clean-install windows and whether that will make it go away. When I have time!

I wonder what other people do with their holidays :slight_smile:

A post was merged into an existing topic: I wonder what other people do with their holidays

It does reproduce in Windows 10 Sandbox

Version 8.5.15 was last version without this bug, later versions all have it.

The xpce is too difficult for me, I have spent many many evenings to get a grip of xpce and the bug, I have given up.

I think this commit made the bug, I have build swipl-devel versions 8.5.16 release version and used only those commits before this commit. They are the same commit.

swipl-devel Updated xpce · SWI-Prolog/swipl-devel@a3995b4 · GitHub

xpce PORT: Avoid using Windows stat() · SWI-Prolog/packages-xpce@6b2790b · GitHub

3 Likes

Thanks. That resolves the issue. the file<-time method used to return the modification time by default, but this commit effectively changed the default to access time on Windows. Pushed a fix, so the source should be fine and tomorrow’s daily build should have this fixed.

2 Likes

Jan Wielemaker, I love you man.

And you too, @PasiK

Now I gotta find something to do in Christmas. Besides installing linux :slight_smile:

2 Likes

And I can confirm that the daily build works and the evil nasty bug is no more.

Thank you again, guys. This was blocking me something terrible.

1 Like