You are not logged in.

#1 2023-04-17 17:51:24

Tx86
Banned
Registered: 2021-07-24
Posts: 39

Invoke format in nano

I'm doing a personal project that I had started some time ago where I had been copying text from a website and saving it into text files. After a long hiatus, I decided to pick it back up, but the website's formatting has changed since then. This means that if I wanted everything to be uniform, I'd either have to format what I have (which is well over 90 files), or start completely over (I'd rather not).

In nano, there is an option in the help section which describes using Alt+F to invoke a program to format/arrange/manipulate the buffer. However, when I press Alt+F, it tells me "No formatter is defined for this type of file". After searching all over the Internet for a way to even understand what this is supposed to mean (clearly something in a configuration file, no doubt), I have come up with absolutely nothing definitive on how to fix this. What program can I use to format text in nano, and how to I get nano to recognize the program when I try to invoke it?

Offline

#2 2023-04-17 23:01:15

Stefan Husmann
Member
From: Germany
Registered: 2007-08-07
Posts: 1,391

Re: Invoke format in nano

Section 8.2 of nanos texinfo-documentation is about syntax highlighting in nano, and there is a short hint, that you need external programs to do the formatting, and thes programs must fit to the textfiles you want to format. I wonder if there are such formatters for cut'n'pasted webside contents.

Offline

#3 2023-04-17 23:24:50

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,521
Website

Re: Invoke format in nano

Why would you use nano for this?  Whatever command you would try to call with Alt+F in nano could just be run on all the files at once outside of nano.  This command would depend on how the "format" needs to change - but tools like sed or awk would likely come in handy.  If you want to know how to convert some of the file(s), post examples of the input and how you want the result.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#4 2023-04-18 06:50:43

seth
Member
Registered: 2012-09-03
Posts: 50,983

Re: Invoke format in nano

For html see https://archlinux.org/packages/extra/x86_64/tidy/ - whether and how that integrates w/ nano, I've no idea nor care.

Offline

#5 2023-05-24 18:32:22

Tx86
Banned
Registered: 2021-07-24
Posts: 39

Re: Invoke format in nano

Trilby wrote:

Why would you use nano for this?  Whatever command you would try to call with Alt+F in nano could just be run on all the files at once outside of nano.  This command would depend on how the "format" needs to change - but tools like sed or awk would likely come in handy.  If you want to know how to convert some of the file(s), post examples of the input and how you want the result.

I'm just used to nano, it's all I've ever used to make, view, or edit .txt files. I've eyeballed sed and awk over the years, but I've never bothered to take it seriously. Some examples of the editing I need done would be to remove or add indentation, or surround each number with [ ] (Ex: [3], [15], [33]), or just other little stuff that, up to this point, has been easy to do in nano itself before the website changed everything so drastically.

Offline

#6 2023-05-24 18:53:51

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,521
Website

Re: Invoke format in nano

But you'd have to do 90 files one by one?  Open each one in nano, then hit some key combination to get some "formatting" to happen, then another to save / exit, and then do this all again for file number 2, then 3, up to 90?

Width proper text-processing tools, you'd just type your "formatting" command once, and run it on all 90 files at once, e.g.:

sed 's/[0-9]\+/[&]/g' *.txt

(note this is probably *not* the sed command you'd want to use, as it is a strictly literal instatiation of your described goal of "surround each number with []" - I suspect there are exceptions, and other details in the real goal).


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#7 2023-05-24 19:13:50

Tx86
Banned
Registered: 2021-07-24
Posts: 39

Re: Invoke format in nano

Trilby wrote:

But you'd have to do 90 files one by one?  Open each one in nano, then hit some key combination to get some "formatting" to happen, then another to save / exit, and then do this all again for file number 2, then 3, up to 90?

Width proper text-processing tools, you'd just type your "formatting" command once, and run it on all 90 files at once, e.g.:

sed 's/[0-9]\+/[&]/g' *.txt

(note this is probably *not* the sed command you'd want to use, as it is a strictly literal instatiation of your described goal of "surround each number with []" - I suspect there are exceptions, and other details in the real goal).


This would theoretically be even better if I could get it to work properly. Maybe I need to find some material on how to use sed properly. Who knows, maybe it'll change the very way I do things.

Offline

#8 2023-05-24 19:31:53

seth
Member
Registered: 2012-09-03
Posts: 50,983

Re: Invoke format in nano

Maybe be morespecific about the task.
Next to the aforementioned tidy there's https://archlinux.org/packages/extra/x86_64/astyle/
It's not like the problem of mass-formating text (for which an interactive texteditor is hardly a good tool) hasn't been tackled before.

Offline

Board footer

Powered by FluxBB