How to refresh file after it is updated by an external editor lazarus / 9-Editor ---------------------------------------------------------------------- vfclists · 2024-10-13 00:38 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? ---------------------------------------------------------------------- jamie · 2024-10-18 15:06 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. ---------------------------------------------------------------------- MarkMLl · 2024-10-19 08:31 Quote from: vfclists on October 13, 2024, 02:38:35 amI'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 ---------------------------------------------------------------------- JuhaManninen · 2024-10-19 10:53 Quote from: MarkMLl on October 19, 2024, 10:31:08 amSecond. 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. ---------------------------------------------------------------------- MarkMLl · 2024-10-19 11:02 Quote from: JuhaManninen on October 19, 2024, 12:53:36 pmYes, 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 ---------------------------------------------------------------------- 440bx · 2024-10-19 12:18 Quote from: vfclists on October 13, 2024, 02:38:35 amSometimes 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. ---------------------------------------------------------------------- jamie · 2024-10-19 13:45 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. ---------------------------------------------------------------------- n7800 · 2024-10-19 14:18 Quote from: vfclists on October 13, 2024, 02:38:35 amI'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 · 2024-10-19 14:40 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 · 2024-10-19 15:01 Quote from: 440bx on October 19, 2024, 02:18:45 pmThe 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 · 2024-10-19 17:08 Quote from: n7800 on October 19, 2024, 04:40:14 pmIf 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.h tml#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. ---------------------------------------------------------------------- MarkMLl · 2024-10-19 19:28 Quote from: 440bx on October 19, 2024, 07:08:28 pmIt 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 ---------------------------------------------------------------------- 440bx · 2024-10-19 19:33 Quote from: MarkMLl on October 19, 2024, 09:28:19 pmIt 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. ---------------------------------------------------------------------- MarkMLl · 2024-10-19 20:02 Quote from: 440bx on October 19, 2024, 09:33:59 pmIt'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 ---------------------------------------------------------------------- 440bx · 2024-10-19 21:29 Quote from: MarkMLl on October 19, 2024, 10:02:29 pmThis 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.