source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* texi2mdoc: When using @def style commands, indent the "explanation"
@ 2015-02-28 13:17 kristaps
  0 siblings, 0 replies; only message in thread
From: kristaps @ 2015-02-28 13:17 UTC (permalink / raw)
  To: source

Log Message:
-----------
When using @def style commands, indent the "explanation" block as it's
supposed to be, where subsequent @defx commands aren't indented.

Modified Files:
--------------
    texi2mdoc:
        extern.h
        main.c
        util.c

Revision Data
-------------
Index: main.c
===================================================================
RCS file: /home/cvs/mdocml/texi2mdoc/main.c,v
retrieving revision 1.53
retrieving revision 1.54
diff -Lmain.c -Lmain.c -u -p -r1.53 -r1.54
--- main.c
+++ main.c
@@ -498,9 +498,45 @@ dodefn(struct texi *p, enum texicmd cmd,
 		abort();
 	}
 
-	texivspace(p);
-	if (NULL != blk)
-		parseto(p, pos, blk);
+	if (NULL == blk)
+		return;
+
+	/*
+	 * All "block" definitions have their block bodies indented
+	 * unless they have the "x" form of the command following.
+	 * E.g.,
+	 *   @deffn some function
+	 *   @deffnx another
+	 *   An explanation.
+	 *   @end deffn
+	 * With this loop, we delay opening the indented block until we
+	 * skipped past conformant macros.
+	 */
+	for (;;) {
+		switch (peekcmd(p, *pos)) {
+		case (TEXICMD_DEFFNX):
+		case (TEXICMD_DEFMACX):
+		case (TEXICMD_DEFTPX):
+		case (TEXICMD_DEFTYPEFNX):
+		case (TEXICMD_DEFTYPEFUNX):
+		case (TEXICMD_DEFTYPEMETHODX):
+		case (TEXICMD_DEFTYPEVARX):
+		case (TEXICMD_DEFTYPEVRX):
+		case (TEXICMD_DEFUNX):
+		case (TEXICMD_DEFVARX):
+		case (TEXICMD_DEFVRX):
+			texivspace(p);
+			parseeoln(p, pos);
+			continue;
+		default:
+			break;
+		}
+		break;
+	}
+	teximacro(p, "Bd -filled -offset indent");
+	p->seenvs = 1;
+	parseto(p, pos, blk);
+	teximacro(p, "Ed");
 }
 
 static void
Index: extern.h
===================================================================
RCS file: /home/cvs/mdocml/texi2mdoc/extern.h,v
retrieving revision 1.19
retrieving revision 1.20
diff -Lextern.h -Lextern.h -u -p -r1.19 -r1.20
--- extern.h
+++ extern.h
@@ -427,7 +427,9 @@ void	parseto(struct texi *, size_t *, co
 void	texiabort(struct texi *, const char *)
 		__attribute__((noreturn));
 enum texicmd
-	texicmd(struct texi *, size_t, size_t *, struct teximacro **);
+	texicmd(const struct texi *, size_t, size_t *, struct teximacro **);
+enum texicmd
+	peekcmd(const struct texi *, size_t);
 void	texierr(struct texi *, const char *, ...)
 		__attribute__((format(printf, 2, 3)))
 		__attribute__((noreturn));
Index: util.c
===================================================================
RCS file: /home/cvs/mdocml/texi2mdoc/util.c,v
retrieving revision 1.18
retrieving revision 1.19
diff -Lutil.c -Lutil.c -u -p -r1.18 -r1.19
--- util.c
+++ util.c
@@ -591,7 +591,7 @@ parseword(struct texi *p, size_t *pos, c
  * index after the command name.
  */
 enum texicmd
-texicmd(struct texi *p, size_t pos, size_t *end, struct teximacro **macro)
+texicmd(const struct texi *p, size_t pos, size_t *end, struct teximacro **macro)
 {
 	size_t	 i, len, toksz;
 
@@ -824,6 +824,23 @@ parseeoln(struct texi *p, size_t *pos)
 
 	if (*pos < BUFSZ(p) && '\n' == BUF(p)[*pos])
 		advance(p, pos);
+}
+
+/*
+ * Peek to see if there's a command after subsequent whitespace.
+ * If so, return the macro identifier.
+ * This DOES NOT work with user-defined macros.
+ */
+enum texicmd
+peekcmd(const struct texi *p, size_t pos)
+{
+	size_t		end;
+
+	while (pos < BUFSZ(p) && ismspace(BUF(p)[pos]))
+		pos++;
+	if (pos == BUFSZ(p) || '@' != BUF(p)[pos])
+		return(TEXICMD__MAX);
+	return(texicmd(p, pos, &end, NULL));
 }
 
 /*
--
 To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2015-02-28 13:17 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-28 13:17 texi2mdoc: When using @def style commands, indent the "explanation" kristaps

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).