bugGNU nano - Bugs: bug #62269, [Wish] a way to save and restore...


You are not allowed to post comments on this tracker with your current authentication level.

bug #62269: [Wish] a way to save and restore anchors

Submitter:  Shi Yanling <sylphenix>
Submitted:  Fri 08 Apr 2022 02:42:52 PM UTC
Severity:  1 - Wish Status:  None
Assigned to:  None Open/Closed:  Open

Jump to the original submission

Wed 22 Jun 2022 07:20:07 AM UTC, comment #7: 

Your ability, Tasos, to think in macros is /fabelhaft/ (as the Germans say).  :)  But the need to first prepare a side buffer, give it a name, and save and close it afterward, and later having to open a side buffer and load the correct file and restore the anchors one by one... it's all far too many keystrokes and too much mental overhead for anyone to actually do this.  Not simples at all.  :)

Benno Schulenberg <bens>
Group administrator
Wed 15 Jun 2022 07:05:32 AM UTC, comment #6: 

Just adding to the conversation that this functionality can be reasonably approximated via very simple macros which you can define in your nanorc. :)

E.g., to 'save' anchors, create a macro that assumes the buffer next to your current window will save anchor-line numbers, then create the following macro:

- go to top of file
- set mark
- go to next anchor (which will create a selection)
- execute "| wc -l | xargs echo 1 + | bc"
- enter
- go back to previous buffer

This saves a single anchor; repeat for all anchors. Optionally remove anchors as you save it. You could also pull off the wc -l stunt before going to top, and use that to return to the line from which you launched the macro. Once you're done, save the buffer containing line numbers.

Similarly, to load from such a file containing anchor lines; open it, place it as the buffer to the right, and then run a macro which does the following:

- buffer right
- cut
- buffer left
- goto
- paste
- place anchor

Repeat until end of anchor file.

Simples :)

Tasos Papastylianou <tpapastylianou>
Sun 08 May 2022 02:33:30 PM UTC, comment #5: 

Interesting mechanism: an anchor at the first line "magically" making nano save the anchors (when --positionlog or 'set positionlog' is active).  This "invisible" mechanism kind of fits the anchors that themselves are normally invisible too.  But from a usability point of view... I doubt that anyone would like this.

However, if you are willing to work on the code for saving an restoring the anchors, then I will help.  And when we get it working, and you've used it privately for a while and are content, you could post the patch to nano-devel and see if anyone else is interested in the feature.

Benno Schulenberg <bens>
Group administrator
Fri 06 May 2022 06:40:28 AM UTC, comment #4: 

Automatically saving/restoring anchors is better. But if there's an option to activate such feature, I won't turn it on by default. As my routine editor, I don't need it to save anchors in most cases, and do not want it to scan over all the lines every time I close a file. So I have to decide whether to turn the option on or not before I open a file.

How about this way. When I insert an anchor at the first line, the feature that automatically save anchors would be activated. When I remove the anchor from the first line, the feature would be deactivated, and the saved anchor data (if exist) would be cleared. Since the first line never needs an anchor, it is a good place to be used as an indicator. I could turn it on or off whenever I want. To restore anchors, just use -P option. While open a file with -P option, the saved anchors (if exist) would be restored, and if anchors are restored, the feature that automatically save anchors would be activated again. Logically, anchors and cursor's position are the same kind of data. I think they could share the same log file and the same option.

In this way, no extra option or keybinding is needed, and doesn't add any action to nano when anchor is not used. To clear all anchors in current file, just remove the anchor from the first line, and reopen the file.

Shi Yanling <sylphenix>
Fri 15 Apr 2022 01:45:03 PM UTC, comment #3: 

Having two functions (one to save anchors, and one to reload them) would require two keybindings.  Of course, the functions could be unbound by default, but that would make them undiscoverable -- unless they are mentioned listed the main ^G list of shortcuts, but I really don't want to burden that list with such exotic functions.

When saving and restoring anchors automatically (activated by an option, just like 'historylog' and 'positionlog'), no such functions are needed.  However, one would probably want to have a function to clear all existing anchors in a buffer, as it would be tedious to have to clear any present anchors one-by-one.

(One way to clear all anchors in a file when no such 'clear' function exists, would be to run 'nano --ignore --position thefile' and exit immediately.  That would resave the cursor position in the ~/.nano/filepos_history file but without the anchors because nano has not seen the 'keepanchors' option (or whatever it would be called).  Not convenient, but not too hard either: nano -IP thefile, ^X, done.)

Benno Schulenberg <bens>
Group administrator
Mon 11 Apr 2022 02:19:40 PM UTC, comment #2: 

Thanks for thinking about my request. I didn't mean that automatically save anchors while saving a file and restore them when reopening the file. My thought was that have two functions, one could export anchors to a specified file, and the other one could import it later. The file is specified by user when the function is called. So that we could have the ability to manually export/import anchors just when we want to. I think it wouldn't add slowdowns to nano. I'm not sure that I can accomplish such a patch. But I'd like to have a try when I have time.

Shi Yanling <sylphenix>
Sun 10 Apr 2022 10:47:52 AM UTC, comment #1: 

Where should those anchors be saved?  In another file in ~/.nano?  I don't want to create any more state files for nano.  Then maybe add them in ~/.nano/filepos_history, at the end of each line?  That would create complications when an old filepos_history file does not yet contain any anchor data, but... it seems feasible to solve that.  However, saving the anchors would require running through all of the lines of the file to see whether anyone has an anchor, which takes some time (not much, but still), and I am loathe to add any more slowdowns to nano.  But you are welcome to provide a patch if this feature is important to you.  No guarantees that it will be applied, though.

Benno Schulenberg <bens>
Group administrator
Fri 08 Apr 2022 02:42:52 PM UTC, original submission:  

I'm trying to code with nano. Anchors are very useful to me, since there are thousands of lines. But anchors can't be saved. When I reopen the code, I have to place those anchors again. I'd like to have the ability to import/export anchors. Or is there any good solution else? Thanks.

Shi Yanling <sylphenix>


(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

No files currently attached


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -email is unavailable- added by tpapastylianou (Posted a comment)
  • -email is unavailable- added by bens (Posted a comment)
  • -email is unavailable- added by sylphenix (Submitted the item)

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.


    Follow 3 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2022-04-29 bens Summary[Wish] save and restore anchors [Wish] a way to save and restore anchors
    2022-04-10 bens Severity3 - Normal 1 - Wish
        Summary[Wish] import/export anchors [Wish] save and restore anchors

    Back to the top

    Powered by Savane 3.13-0159.
    Corresponding source code