Recent

Author Topic: How to refresh file after it is updated by an external editor  (Read 1873 times)

vfclists

  • Hero Member
  • *****
  • Posts: 1147
    • HowTos Considered Harmful?
How to refresh file after it is updated by an external editor
« on: October 13, 2024, 02:38:35 am »
I'm editing some files with both Emacs and Lazarus and Lazarus doesn't seem to have the option from reloading the file with the changes on disk.

Sometimes the changes are noticed and a warning dialog comes up, but at other times you expect the warning you are not.

Is there some menu item or command for doing that?
Lazarus 3.0/FPC 3.2.2

jamie

  • Hero Member
  • *****
  • Posts: 6791
Re: How to refresh file after it is updated by an external editor
« Reply #1 on: October 18, 2024, 05:06:20 pm »
maybe

 WINDOW:Manage Source Editor

 there is a CHECK box, Check all or something like that.

I never used that but its worth a try.
The only true wisdom is knowing you know nothing

MarkMLl

  • Hero Member
  • *****
  • Posts: 8129
Re: How to refresh file after it is updated by an external editor
« Reply #2 on: October 19, 2024, 10:31:08 am »
I'm editing some files with both Emacs and Lazarus and Lazarus doesn't seem to have the option from reloading the file with the changes on disk.

I'd very strongly recommend that you not do that, for two reasons.

The first is that the combination of Lazarus and FPC has problems picking up changed files under certain circumstances, to the extent that sometimes even a build is inadequate: you need to wipe all working files, restart the IDE and then build; nobody has been able to get that to a predictable enough state that the developers could tackle it. Even without that extreme case, Lazarus can get itself into a state where the file presented as containing compile-time errors is not the same one currently being edited: this is often (but not always) associated with symlinks.

Second. Emacs comes from the unix tradition where the original file is renamed (retaining the original owner's rites) as a backup and the edited file is written from scratch (owned by the current editor, with fresh access rights etc.). That combination is more than enough to confuse any IDE.

If you want to use Emacs, then work out how to invoke FPC from it and report compilation results etc. If you only want the Emacs key codes or there's some special "must have" that you need, then identify what's missing from the Lazarus IDE and report the omissions in the bugtracker so that the developers can help you fix them.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4545
  • I like bugs.
Re: How to refresh file after it is updated by an external editor
« Reply #3 on: October 19, 2024, 12:53:36 pm »
Second. Emacs comes from the unix tradition where the original file is renamed (retaining the original owner's rites) as a backup and the edited file is written from scratch (owned by the current editor, with fresh access rights etc.). That combination is more than enough to confuse any IDE.
Yes, that may be the problem.
I sometimes edit source files with Kate editor which comes with KDE. Lazarus IDE always notices a file was modified and offers a choice to reload it.
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

MarkMLl

  • Hero Member
  • *****
  • Posts: 8129
Re: How to refresh file after it is updated by an external editor
« Reply #4 on: October 19, 2024, 01:02:03 pm »
Yes, that may be the problem.
I sometimes edit source files with Kate editor which comes with KDE. Lazarus IDE always notices a file was modified and offers a choice to reload it.

I don't know whether the IDE uses it, but I've looked at the Linux FAM stuff and found that it can be somewhat picky about only detecting /precisely/ the kind of changes it's been told to look for.

Kate's fairly recent and I think that it's very much "environment aware", i.e. D-Bus etc.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

440bx

  • Hero Member
  • *****
  • Posts: 4901
Re: How to refresh file after it is updated by an external editor
« Reply #5 on: October 19, 2024, 02:18:45 pm »
Sometimes the changes are noticed and a warning dialog comes up, but at other times you expect the warning you are not.
I do most of my editing outside of Lazarus and, as you mention there times, fortunately somewhat rare, that Lazarus doesn't notice immediately one or more files have changed.

The solution is usually simply switch back to the editor (or some other app) then back to Lazarus.  The other solution is to have Lazarus do a "build" (shift-F9), that causes it to check for changed files.

Those 2 methods have always worked for me without exception.

HTH.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

jamie

  • Hero Member
  • *****
  • Posts: 6791
Re: How to refresh file after it is updated by an external editor
« Reply #6 on: October 19, 2024, 03:45:20 pm »
I don't know how Lazarus does it but, I've written code in Windows using the OS method to run a Thread thereby monitoring changes done in a folder and sub-Folder. It works very well.

 In theory, as to how I do it, I send the main thread a message (Post) when changes are detected.

 I have not done such things here with Lazarus or any tools on the side, but I do have such functionality with apps I use.

 
The only true wisdom is knowing you know nothing

n7800

  • Full Member
  • ***
  • Posts: 199
Re: How to refresh file after it is updated by an external editor
« Reply #7 on: October 19, 2024, 04:18:54 pm »
I'm editing some files with both Emacs and Lazarus and Lazarus doesn't seem to have the option from reloading the file with the changes on disk.
...
Is there some menu item or command for doing that?

Menu "File" command "Revert".

Just noticed that it discards all changes in the editor without even asking for confirmation... Created MR362.

n7800

  • Full Member
  • ***
  • Posts: 199
Re: How to refresh file after it is updated by an external editor
« Reply #8 on: October 19, 2024, 04:40:14 pm »
If you make changes to a file in Lazarus, it no longer reports about file changes by a third-party program. This is logical, since two "branches" of changes are formed, and you cannot simply discard one of them.

And it seems that it checks files by date. There is an option that allows you to check by content (see attachments). If this option is disabled, and your editor updates the file without updating the date, the IDE will not report changes.

n7800

  • Full Member
  • ***
  • Posts: 199
Re: How to refresh file after it is updated by an external editor
« Reply #9 on: October 19, 2024, 05:01:24 pm »
The solution is usually simply switch back to the editor (or some other app) then back to Lazarus.  The other solution is to have Lazarus do a "build" (shift-F9), that causes it to check for changed files.

Those 2 methods have always worked for me without exception.

Yes, I see several DoCheckFilesOnDisk calls in the code before building, upon window activation, after calling external tools, and some other events.

By the way, it will not report if some modal window (for example, IDE Options) is open at the time of changes, and will not report even after it is closed... This should be improved.

440bx

  • Hero Member
  • *****
  • Posts: 4901
Re: How to refresh file after it is updated by an external editor
« Reply #10 on: October 19, 2024, 07:08:28 pm »
If you make changes to a file in Lazarus, it no longer reports about file changes by a third-party program. This is logical, since two "branches" of changes are formed, and you cannot simply discard one of them.
Yes, that had occasionally been a problem for me causing loss of changes because I forgot to save the file(s) in Lazarus before switching to my editor.

Fortunately, now there is a solution for that, user @DomingoGP wrote a small package that saves the file(s) automatically whenever the user switches away from Lazarus.  I've been using it since it became available and so far it works very well.

The download can be found in the thread:
https://forum.lazarus.freepascal.org/index.php/topic,68028.msg524897.html#msg524897

Note that there are two downloads for the same package (it got updated), obviously pick the most up to date one.

It would be very nice if that functionality became a selectable option in Lazarus, IOW, having the option without having to download and install a separate package for it.

HTH.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

MarkMLl

  • Hero Member
  • *****
  • Posts: 8129
Re: How to refresh file after it is updated by an external editor
« Reply #11 on: October 19, 2024, 09:28:19 pm »
It would be very nice if that functionality became a selectable option in Lazarus, IOW, having the option without having to download and install a separate package for it.

So if it's useful and reliable (noting recent discussion about switching between desktops on Linux etc.), what needs to be done to fasttrack it into the standard IDE package list (i.e. there even if not installed by default)?

It definitely shouldn't be installed and enabled by default, since the result of a forced save of a few doodles after swapping to a different desktop to deal with a 'phone call could be counterproductive...

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

440bx

  • Hero Member
  • *****
  • Posts: 4901
Re: How to refresh file after it is updated by an external editor
« Reply #12 on: October 19, 2024, 09:33:59 pm »
It definitely shouldn't be installed and enabled by default, since the result of a forced save of a few doodles after swapping to a different desktop to deal with a 'phone call could be counterproductive...

MarkMLl
It's not "intalled" if the feature is simply built into Lazarus (iow, it's always installed since it is part of Lazarus itself), it's just there for the "enabling".

As far as it being enabled by default, I agree with you, I don't think it should be enabled by default.  I would simply like the ability to be built into Lazarus and be user selectable.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

MarkMLl

  • Hero Member
  • *****
  • Posts: 8129
Re: How to refresh file after it is updated by an external editor
« Reply #13 on: October 19, 2024, 10:02:29 pm »
It's not "intalled" if the feature is simply built into Lazarus (iow, it's always installed since it is part of Lazarus itself), it's just there for the "enabling".

Wearing my picky tech writer's hat :-)

There's an important distinction here: "enabling" in this context might mean "it's built into the IDE and there's a checkbox for it", or "it's a package that can be enabled by selecting it and rebuilding the IDE".

This is almost certainly something that doesn't merit being hardcoded into the IDE. Hence the only questions are how to get it into the standard list of packages bundled with the IDE, and whether the package should be installed (even if not enabled) by default.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

440bx

  • Hero Member
  • *****
  • Posts: 4901
Re: How to refresh file after it is updated by an external editor
« Reply #14 on: October 19, 2024, 11:29:23 pm »
This is almost certainly something that doesn't merit being hardcoded into the IDE.
I think it should be because it simply mirrors the file reloading check Lazarus already does when it regains focus and, that is part of Lazarus (hardcoded as you put it.)

Either way, I'm perfectly happy with the package from DomingoGP but, I think including that functionality in Lazarus (as part of Lazarus, not just an add-on package) would add polish to Lazarus.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

 

TinyPortal © 2005-2018