iarticle-katolaz-formatting-paragraphs.mw - tgtimes - The Gopher Times Err bitreich.org 70 hgit clone git://bitreich.org/tgtimes git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/tgtimes URL:git://bitreich.org/tgtimes git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/tgtimes bitreich.org 70 1Log /scm/tgtimes/log.gph bitreich.org 70 1Files /scm/tgtimes/files.gph bitreich.org 70 1Refs /scm/tgtimes/refs.gph bitreich.org 70 1Tags /scm/tgtimes/tag bitreich.org 70 1README /scm/tgtimes/file/README.md.gph bitreich.org 70 i--- Err bitreich.org 70 iarticle-katolaz-formatting-paragraphs.mw (6147B) Err bitreich.org 70 i--- Err bitreich.org 70 i 1 .SH katolaz Err bitreich.org 70 i 2 fold, fmt, par: get your text in order Err bitreich.org 70 i 3 .2C 19v Err bitreich.org 70 i 4 . Err bitreich.org 70 i 5 .PP Err bitreich.org 70 i 6 If you happen to read plain text files (e.g., phlog posts), you have Err bitreich.org 70 i 7 probably noticed that, especially on gopher, the lines of a text file Err bitreich.org 70 i 8 tend to be wrapped all to a similar length. Some authors are very strict Err bitreich.org 70 i 9 on the matter, and like all the lines to be "justified" (i.e., all Err bitreich.org 70 i 10 adjusted to have exactly the same length, by inserting a few spaces to Err bitreich.org 70 i 11 get the count right). Some other authors (including myself) just do not Err bitreich.org 70 i 12 allow any line to be longer than a certain amount of characters (in this Err bitreich.org 70 i 13 case, as you might have noticed, the magic number is 72). But how to Err bitreich.org 70 i 14 they manage to do that? Err bitreich.org 70 i 15 . Err bitreich.org 70 i 16 .PP Err bitreich.org 70 i 17 Most common editors have a command to format a paragraph ('M-q' in Err bitreich.org 70 i 18 Emacs, 'gwip' or '{gq}' in vim normal mode, etc.). But obviously, Err bitreich.org 70 i 19 there are several Unix tools that can help you getting the right Err bitreich.org 70 i 20 formatting for your files. We are talking of fold(1), fmt(1), and Err bitreich.org 70 i 21 par(1), so keep reading if you want to know more. Err bitreich.org 70 i 22 . Err bitreich.org 70 i 23 .PP Err bitreich.org 70 i 24 The oldest one is probably fold(1) (and it is also the only one to be Err bitreich.org 70 i 25 defined in the POSIX standard...). It will just break each line to make Err bitreich.org 70 i 26 it fit a given length in characters (by default, 72, which is indeed a Err bitreich.org 70 i 27 magic number). Let's see how to wrap the lines of this post at 54 Err bitreich.org 70 i 28 characters: Err bitreich.org 70 i 29 . Err bitreich.org 70 i 30 .1C Err bitreich.org 70 i 31 .DS Err bitreich.org 70 i 32 $ fold -w 54 20190213_fold.txt | head -10 Err bitreich.org 70 i 33 fold, fmt, par: get your text in order Err bitreich.org 70 i 34 ============================================ Err bitreich.org 70 i 35 If you happen to read plain text files (e.g., phlog po Err bitreich.org 70 i 36 sts), you have Err bitreich.org 70 i 37 probably noticed that, especially on gopher, the lines Err bitreich.org 70 i 38 of a text file Err bitreich.org 70 i 39 tend to be wrapped all to a similar length. Some autho Err bitreich.org 70 i 40 rs are very strict Err bitreich.org 70 i 41 on the matter, and like all the lines to be "justified Err bitreich.org 70 i 42 $ Err bitreich.org 70 i 43 .DE Err bitreich.org 70 i 44 . Err bitreich.org 70 i 45 .2C 4v Err bitreich.org 70 i 46 .PP Err bitreich.org 70 i 47 Notice that fold(1) did not really think twice before breaking "posts" Err bitreich.org 70 i 48 or "authors" across two lines. This is pretty inconvenient, to say the Err bitreich.org 70 i 49 least. You can actually force fold(1) to break stuff at blank spaces, Err bitreich.org 70 i 50 using the '-s' option: Err bitreich.org 70 i 51 . Err bitreich.org 70 i 52 .1C Err bitreich.org 70 i 53 . Err bitreich.org 70 i 54 .DS Err bitreich.org 70 i 55 $ fold -w 54 -s 20190213_fold.txt |head -10 Err bitreich.org 70 i 56 fold, fmt, par: get your text in order Err bitreich.org 70 i 57 ============================================ Err bitreich.org 70 i 58 Err bitreich.org 70 i 59 If you happen to read plain text files (e.g., phlog Err bitreich.org 70 i 60 posts), you have Err bitreich.org 70 i 61 probably noticed that, especially on gopher, the Err bitreich.org 70 i 62 lines of a text file Err bitreich.org 70 i 63 tend to be wrapped all to a similar length. Some Err bitreich.org 70 i 64 authors are very strict Err bitreich.org 70 i 65 on the matter, and like all the lines to be Err bitreich.org 70 i 66 $ Err bitreich.org 70 i 67 .DE Err bitreich.org 70 i 68 . Err bitreich.org 70 i 69 .2C 3v Err bitreich.org 70 i 70 .PP Err bitreich.org 70 i 71 Nevertheless, the output of fold(1) is still quite off: it breaks lines Err bitreich.org 70 i 72 at spaces, but it does not "join" broken lines to have a more consistent Err bitreich.org 70 i 73 formatting. This is where fmt(1) jumps in: Err bitreich.org 70 i 74 . Err bitreich.org 70 i 75 .1C Err bitreich.org 70 i 76 .DS Err bitreich.org 70 i 77 $ fmt -w 54 20190213_fold.txt |head -10 Err bitreich.org 70 i 78 fold, fmt, par: get your text in order Err bitreich.org 70 i 79 ============================================ Err bitreich.org 70 i 80 Err bitreich.org 70 i 81 If you happen to read plain text files (e.g., phlog Err bitreich.org 70 i 82 posts), you have probably noticed that, especially on Err bitreich.org 70 i 83 gopher, the lines of a text file tend to be wrapped Err bitreich.org 70 i 84 all to a similar length. Some authors are very strict Err bitreich.org 70 i 85 on the matter, and like all the lines to be Err bitreich.org 70 i 86 "justified" (i.e., all adjusted to have exactly the Err bitreich.org 70 i 87 same length, by inserting a few spaces to get the Err bitreich.org 70 i 88 $ Err bitreich.org 70 i 89 .DE Err bitreich.org 70 i 90 . Err bitreich.org 70 i 91 .2C 5v Err bitreich.org 70 i 92 .PP Err bitreich.org 70 i 93 Now we are talking: fmt(1) seems to be able to to "the right thing" Err bitreich.org 70 i 94 without much effort, and it has a few other interesting options as well. Err bitreich.org 70 i 95 Just have a look at the manpage. Simple and clear. Err bitreich.org 70 i 96 . Err bitreich.org 70 i 97 .PP Err bitreich.org 70 i 98 Last but not least, par(1) can do whatever fmt(1) and fold(1) can do, Err bitreich.org 70 i 99 plus much, much more. For instance: Err bitreich.org 70 i 100 . Err bitreich.org 70 i 101 .1C Err bitreich.org 70 i 102 .DS Err bitreich.org 70 i 103 $ par 54 < 20190213_fold.txt | head -10 Err bitreich.org 70 i 104 fold, fmt, par: get your text in order Err bitreich.org 70 i 105 ============================================ Err bitreich.org 70 i 106 Err bitreich.org 70 i 107 If you happen to read plain text files (e.g., phlog Err bitreich.org 70 i 108 posts), you have probably noticed that, especially on Err bitreich.org 70 i 109 gopher, the lines of a text file tend to be wrapped Err bitreich.org 70 i 110 all to a similar length. Some authors are very Err bitreich.org 70 i 111 strict on the matter, and like all the lines to be Err bitreich.org 70 i 112 "justified" (i.e., all adjusted to have exactly the Err bitreich.org 70 i 113 same length, by inserting a few spaces to get the Err bitreich.org 70 i 114 $ Err bitreich.org 70 i 115 .DE Err bitreich.org 70 i 116 . Err bitreich.org 70 i 117 .1C Err bitreich.org 70 i 118 .PP Err bitreich.org 70 i 119 will give more or less the same output as fmt(1). But: Err bitreich.org 70 i 120 . Err bitreich.org 70 i 121 .1C Err bitreich.org 70 i 122 .DS Err bitreich.org 70 i 123 $ par 54j < 20190213_fold.txt | head -10 Err bitreich.org 70 i 124 fold, fmt, par: get your text in order Err bitreich.org 70 i 125 ============================================ Err bitreich.org 70 i 126 Err bitreich.org 70 i 127 If you happen to read plain text files (e.g., phlog Err bitreich.org 70 i 128 posts), you have probably noticed that, especially on Err bitreich.org 70 i 129 gopher, the lines of a text file tend to be wrapped Err bitreich.org 70 i 130 all to a similar length. Some authors are very Err bitreich.org 70 i 131 strict on the matter, and like all the lines to be Err bitreich.org 70 i 132 "justified" (i.e., all adjusted to have exactly the Err bitreich.org 70 i 133 same length, by inserting a few spaces to get the Err bitreich.org 70 i 134 $ Err bitreich.org 70 i 135 .DE Err bitreich.org 70 i 136 . Err bitreich.org 70 i 137 .1C Err bitreich.org 70 i 138 .PP Err bitreich.org 70 i 139 will additionally "justify" your lines to the prescribed width, while: Err bitreich.org 70 i 140 something like: Err bitreich.org 70 i 141 . Err bitreich.org 70 i 142 .1C Err bitreich.org 70 i 143 .DS Err bitreich.org 70 i 144 $ head file.h Err bitreich.org 70 i 145 * Err bitreich.org 70 i 146 * include/linux/memory.h - generic memory definition Err bitreich.org 70 i 147 * Err bitreich.org 70 i 148 * This is mainly for topological representation. We define the Err bitreich.org 70 i 149 * basic "struct memory_block" here, which can be embedded in per-arch Err bitreich.org 70 i 150 * definitions or NUMA information. Err bitreich.org 70 i 151 * Err bitreich.org 70 i 152 * Basic handling of the devices is done in drivers/base/memory.c Err bitreich.org 70 i 153 * and system devices are handled in drivers/base/sys.c. Err bitreich.org 70 i 154 * Err bitreich.org 70 i 155 $ Err bitreich.org 70 i 156 .DE Err bitreich.org 70 i 157 . Err bitreich.org 70 i 158 .1C Err bitreich.org 70 i 159 .PP Err bitreich.org 70 i 160 can be easily transformed into: Err bitreich.org 70 i 161 . Err bitreich.org 70 i 162 .1C Err bitreich.org 70 i 163 .DS Err bitreich.org 70 i 164 $ par 40j < file.h Err bitreich.org 70 i 165 * Err bitreich.org 70 i 166 * include/linux/memory.h - generic Err bitreich.org 70 i 167 *memory definition Err bitreich.org 70 i 168 * Err bitreich.org 70 i 169 * This is mainly for topological Err bitreich.org 70 i 170 * representation. We define the basic Err bitreich.org 70 i 171 * "struct memory_block" here, which can Err bitreich.org 70 i 172 * be embedded in per-arch definitions Err bitreich.org 70 i 173 * or NUMA information. Err bitreich.org 70 i 174 * Err bitreich.org 70 i 175 * Basic handling of the devices is Err bitreich.org 70 i 176 * done in drivers/base/memory.c and Err bitreich.org 70 i 177 * system devices are handled in Err bitreich.org 70 i 178 * drivers/base/sys.c. Err bitreich.org 70 i 179 * Err bitreich.org 70 i 180 * Memory block are exported via Err bitreich.org 70 i 181 * sysfs in the class/memory/devices/ Err bitreich.org 70 i 182 * directory. Err bitreich.org 70 i 183 * Err bitreich.org 70 i 184 * Err bitreich.org 70 i 185 $ Err bitreich.org 70 i 186 .DE Err bitreich.org 70 i 187 . Err bitreich.org 70 i 188 .2C 12v Err bitreich.org 70 i 189 .PP Err bitreich.org 70 i 190 Pretty neat, right? Err bitreich.org 70 i 191 . Err bitreich.org 70 i 192 .PP Err bitreich.org 70 i 193 To be honest, par is not the typical example of a unix tool that Err bitreich.org 70 i 194 "does exactly one thing", but it certainly "does it very well" all the Err bitreich.org 70 i 195 things it does. The author of par(1) felt the need to apologise in the Err bitreich.org 70 i 196 manpage about the style of his code and documentation, but I still think Err bitreich.org 70 i 197 par(1) is an awesome tool nevertheless. Err bitreich.org 70 i 198 . Err bitreich.org 70 i 199 .PP Err bitreich.org 70 i 200 .IP "fold(1)" Err bitreich.org 70 i 201 appeared in BSD1 (1978-1979) Err bitreich.org 70 i 202 . Err bitreich.org 70 i 203 .IP "fmt(1)" Err bitreich.org 70 i 204 appeared in BSD1 (1978-1979) Err bitreich.org 70 i 205 . Err bitreich.org 70 i 206 .IP "par(1)" Err bitreich.org 70 i 207 was developed by Adam Costello in 1993, as a replacement for fmt(1). Err bitreich.org 70 .