Ver código fonte

Add "Writing mdoc"

Causal Agent 1 ano atrás
Acessado por: Curtis McEnroe <> ID da chave GPG: CEA2F97ADCFCD77C
2 arquivos alterados com 139 adições e 0 exclusões
  1. +138
  2. +1

+ 138
- 0
002-writing-mdoc.7 Ver arquivo

@@ -0,0 +1,138 @@
.Dd September 27, 2018
.Os "Causal Agency"
.Nm Writing mdoc
.Nd semantic markup
I recently learned how to write man pages
so that I could document
a bunch of little programs I've written.
Modern man pages are written in
.Xr mdoc 7 ,
whose documentation is also available from
.Lk .
.Xr mdoc 7
differs from many other markup languages
by providing
.Dq semantic markup
rather than just
.Dq physical markup.
What this means is that
the markup indicates what something is,
not how to format it.
For example,
.Ql \&Ar
macro is used to indicate
command-line arguments
rather than one of the macros
for bold, italic or underline.
This frees each author of having to choose
and enables consistent presentation
across different man pages.
Another advantage of semantic markup
is that information can be extracted from it.
For example,
.Xr makewhatis 8
can easily extract the name and short description
from each man page
thanks to the
.Ql \&Nm
.Ql \&Nd
I use the same information
to generate an Atom feed for these documents,
though in admittedly a much less robust way than
.Xr mandoc 1 .
When it comes to actually writing
.Xr mdoc 7 ,
it can take some getting used to.
The language is of
.Xr roff 7
so its syntax is very particular.
Macros cannot appear inline,
but must start on new lines
beginning with
.Ql \&. .
Sentences should likewise
always start on a new line.
Since I'm in the habit of writing with
semantic line breaks,
I actually find these requirements
fit in well.
The more frustrating syntax limitation to me
is the rule against empty lines.
Without them,
it can be quite difficult to edit a lengthy document.
lines with only a
.Ql \&.
on them are allowed,
but this still causes visual noise.
To alleviate that,
I have a
.Xr vim 1
syntax file for
.Xr mdoc 7
which conceals the lone dots:
.Bd -literal -offset indent
if exists("b:current_syntax")

runtime! syntax/nroff.vim
unlet! b:current_syntax

setlocal sections+=ShSs
syntax match mdocBlank /^\\.$/ conceal
setlocal conceallevel=2

let b:current_syntax = "mdoc"
It also adds the
.Xr mdoc 7
section header and subsection header macros to the
.Cm sections
option to make
.Xr vim 1 Ap s
.Ic {
.Ic }
aware of them.
With that,
I've found writing man pages pleasant and rewarding.
I've started writing other documents with
.Xr mdoc 7
as well,
as you can see here.
.Lk "Semantic Linefeeds"
.An June Aq Mt
This document is produced from
.Xr mdoc 7
source available from
.Lk "Code Toilet"

+ 1
- 0
Makefile Ver arquivo

@@ -1,6 +1,7 @@
WEBROOT = /usr/local/www/

TXTS += 001-make.txt
TXTS += 002-writing-mdoc.txt

all: $(TXTS)