I am coming from Notepad++. There is an option that makes the file scroll to the last line after the file changes, is this possible with atom? I tried learning how to write an addon for atom.io to do this but couldn’t figure it out.
I assume that you’re only wanting the file to go to the end when the file is changed by some external process and that you don’t want it to scroll to the end when you change the file like when you’re typing?
Yep that’s correct. I have a log file open in my second monitor in atom. And as things log it adds to the bottom of the file. I need to watch them. Currently im breaking my fingers trying to scroll haha.
Using Atom as a log viewer isn’t something that Atom is well-designed for. I suspect that you will find that even if you get the “scroll-to-the-end” feature you’re looking for, Atom will fail to work well for you in other ways for this use.
I don’t have an idea off the top of my head for how to implement the feature you’re looking for though I’m quite confident that it could be done.
So, the simplest version of this would just be to move the cursor to the bottom of any non-modified buffer when it is updated. It turns out that
onDidChange() fires when a buffer is changed by an external source as well as by Atom.
atom.workspace.observeTextEditors (editor) -> editor.onDidChange -> if not editor.isModified() then editor.moveToBottom()
It would be pretty easy to go further and limit that to one file extension.
Thank you very much sir! I’m very new to n++ and the CoffeScript is confusing me, may you please help me know where to place this?
Drop it into your
init.coffee with the first line unindented. In CoffeeScript, indentation is hugely important, so make sure that any top-level function calls are flush against the left-hand side. If you tell me how your log files look, I can modify it to detect those files.
You are too too nice, thank you sir so much! I need it to work with a specific file name “log.txt”. I sincerely appreciate your help! Excuse my delay in reply!
That’s just a matter of adding another conditional clause.
atom.workspace.observeTextEditors (editor) -> editor.onDidChange -> if not editor.isModified() and editor.getTitle() is "log.txt" then editor.moveToBottom()
Thank you so much testing right now!
I just tested, its not moving to bottom. I even tested with this:
atom.workspace.observeTextEditors (editor) -> editor.onDidChange -> editor.moveToBottom()
I recorded screencast to show you please -
Your video is no longer available.
its not moving to bottom.
Is there a blinking cursor in the document? If you click inside the log file, does it start working?
moveToBottom() might be dependent on having a cursor, but if this is the case, we can create a cursor.
When the file changes my atom doesn’t have focus. But I tried with focus in there it still didn’t work.
I really can’t thank you enough for helping me out like this!
Whoops excuse that please. This video should work:
This is weird. It worked in my initial tests, so now I’ve tested it more and it seems to work most of the time, but not always. You can see how it’s supposed to work in this gif when the final line jumps from 39 to 57, but then when I save it again, more log fills up the bottom two lines of the buffer and the cursor remains at 57. I’m not sure why it doesn’t work sometimes.
Thank you so much for your image and help there! I’ll keep troubleshooting, I’ll definitely learn something in this. Thanks for exposing me to all this with baby steps!
No problem. If I figure out why it’s providing inconsistent results, I’ll let you know.
came here via a web search. Using Atom for logfile monitoring. N++ is for editing. Maybe I got this backwards lol…
Anyway, the init.coffee snip works.
Not necessarily a good plan, even though I showed someone how to do it a couple of years ago. Log files can get huge, potentially, and Atom has performance issues with huge files. Keep that in mind.
I get it. Only using Atom at the moment to I can have a monitor dedicated to log file monitoring. N++ is for config file editing.
Maybe a PowerShell tail type command would be better. Dunno. I like Atom. It’s pretty.