". Add P attributes. (goto-char (point-min)) (while (search-forward lb-re-_-_-_ nil t) (while (search-forward "
" (cdr (lb-tx-what-page t)) t) (replace-match (concat "
")))) ;; (goto-char (point-min)) (while (and (search-forward-regexp lb-re-^^N^^ nil t) (setq lb-n-^^ (match-string 1)) (setq lb-pt-body-^^ (match-beginning 0)) (setq lb-str-visible (int-to-string (setq lb-n-visible (1+ lb-n-visible))))) ;; BODY forw anchor. (replace-match (concat " [" lb-str-visible "]")) ;; BODY back anchor. (progn (goto-char lb-pt-body-^^) (search-backward-regexp "[ \t\n]") (replace-match (concat (match-string 0) "\n" ""))) ;; Move to footnote but not past end of page. (when nil ;; Some footnotes may be missing ^^9^^. (write-region (point-min) (point-max) "~/foo")) (progn (search-forward (concat "^^" lb-n-^^ "^^") (cdr (setq lb-cons (lb-tx-what-page t)))) (replace-match (concat "\n" "[" lb-str-visible "] ")) (progn (goto-char (setq lb-beg (car (_-where-double-newlines)))) (setq lb-end (lb-naletov-footnote-end))) (setq lb-footnote (buffer-substring lb-beg lb-end))) (progn (delete-region lb-beg lb-end) (insert "\n\n\n")) ;; Insert footnote (progn (search-forward "%%notes%%") (beginning-of-line)) (insert "\n\n" (with-temp-buffer (insert lb-footnote) (goto-char (point-max)) (search-backward "
") (replace-match (concat "\n" "[—> main text] " (match-string 0))) (buffer-string)) "\n\n") ;; preceded by: (1) \n\n (2) \n
;;
(goto-char lb-pt-body-^^)) ;while
(_-compress-multiple-newlines)
(progn (goto-char (point-min)) (flush-lines lb-re-_-_-_))
(progn (goto-char (point-min)) (flush-lines "Emacs-Time-stamp"))
(progn (goto-char (point-min))
(search-forward "%%notes%%") (replace-match ""))))
(defun lb-naletov-footnote-end nil
"With point in front of footnote, return end-point of footnote"
;;
(let (lb-str lb-cons)
(save-excursion
(save-match-data
(setq lb-cons (lb-tx-what-page t))
(if (search-forward-regexp (concat lb-re-^^N^^) (cdr lb-cons) t)
(car (_-where-double-newlines))
(goto-char (cdr lb-cons))
(search-backward-regexp "[0-9]")
(car (_-where-double-newlines)))))))
(defun lb-naletov-get-headings (arg1i1 arg3sections)
"ARG1 is section number (one-based).
ARG2 not used to retain 'arg3sections' convention.
ARG3 is list of all sections"
;; (lb-naletov-get-headings 1 lb-sections) => (nil "INTRODUCTION" nil)
(let (lb-pf lb-section lb-max-lvl lb-cons
lb-chap1 lb-sect1 lb-sect2)
(setq lb-max-lvl (lb-naletov-get-max-lvl
(setq lb-section (nth (1- arg1i1) arg3sections))))
(progn (setq lb-chap1 (lb-naletov-get-sect-str (nth (1- arg1i1) arg3sections)
"1" "CHAPTER"))
(setq lb-sect1 (lb-naletov-get-sect-str (nth (1- arg1i1) arg3sections)
"1" "SECTION"))
(setq lb-sect2 (lb-naletov-get-sect-str (nth (1- arg1i1) arg3sections)
"2" "SECTION")))
(when (> lb-max-lvl 1)
(setq lb-chap1 (lb-naletov-get-heading-up arg1i1 arg3sections
lb-chap1 "1" "CHAPTER"))
(setq lb-sect1 (lb-naletov-get-heading-up arg1i1 arg3sections
lb-sect1 "1" "SECTION")))
;;
(if (and (null lb-chap1)
(null lb-sect1)
(null lb-sect2)) nil
(list lb-chap1 lb-sect1 lb-sect2))))
(defun lb-naletov-get-section (arg1pf arg2n arg3list)
"
ARG1 is an index.txt (full path).
ARG2 is a section number (one-based, where 1 retrieves (nth (1- 1)) ).
ARG3 is a list of sections"
;;
;; (setq arg1pf "/home/cymbala/leninist.biz/en/1984/AP470/index.txt")
;; (lb-naletov-get-section arg1pf 1 lb-sections)
;; (lb-naletov-get-section arg1pf 15 lb-sections)
;; MAX:
;; Last section is not real, it just marks end of last real section.
;; (lb-naletov-get-section arg1pf (1- (length lb-sections)) lb-sections)
(let (lb-str)
;;
(if (> arg2n (1- (length arg3list)))
(error "%s: %s" "N too high" (int-to-string arg2n)))
(with-temp-buffer
(_-ifcl
arg1pf nil
(cdr (assoc "PT" (car (nth (1- arg2n) arg3list))))
(cdr (assoc "PT" (car (nth arg2n arg3list)))))
;; on-the-fly
;;
(setq lb-str (buffer-string)))
lb-str))
(defun lb-naletov-gen-text (arg1pf arg2i1 arg3sections)
""
;; (setq arg1pf "/home/cymbala/leninist.biz/en/1984/AP470/index.txt")
;; (lb-naletov-gen-text arg1pf 1 lb-sections)
(let (lb-pf lb-cons lb-re)
(with-temp-buffer
(insert (lb-naletov-get-section arg1pf arg2i1 arg3sections))
;; Delete comments.
(progn (string-match "__$" lb-re-__)
(setq lb-re (replace-match "_COMMENT__" t t lb-re-__)))
(goto-char (point-min))
(while (search-forward-regexp lb-re nil t)
(delete-region (car (setq lb-cons (_-where-double-newlines)))
(cdr lb-cons)))
;; Page numbers.
(lb-naletov-comment-pg-numbers arg1pf)
;; Delete headings from body.
(goto-char (point-min))
(while (search-forward-regexp lb-naletov-re-lvl-real nil t)
(delete-region (car (setq lb-cons (_-where-double-newlines)))
(cdr lb-cons)))
;; Shrink.
(_-compress-multiple-newlines)
(buffer-string))))
(defun lb-naletov-spdw (arg1s arg2p)
"Source (ARG1), page (ARG2) and date as an SGML comment"
(let (lb-pf lb-item lb-www)
(if (integerp arg2p) (setq arg2p (int-to-string arg2p)))
(save-match-data
(loop for lb-item in (reverse (split-string lb-home "/"))
do
(if (and (not lb-www)
(string-match "[a-z0-9]" lb-item))
(setq lb-www lb-item))))
(concat
"")))
(defun lb-naletov-comment-pg-numbers (arg1pf)
""
(let (lb-pf lb-lag (lb-lag-max 0) lb-lag-lag lb-src)
(setq lb-src (save-match-data
(string-match (expand-file-name lb-home) arg1pf)
(replace-match "" nil nil arg1pf)))
(goto-char (point-max))
(while (search-backward-regexp lb-re-para-integer-maybe-bracketed nil t)
(if (and (or (setq lb-lag-lag lb-lag) t)
(or (setq lb-lag (match-string 1)) t)
(or (setq lb-lag-max (max lb-lag-max (string-to-int lb-lag))) t)
lb-lag-lag)
(replace-match (lb-naletov-spdw lb-src lb-lag-lag) t t nil 1)
(replace-match "" t t nil 1))
;; Remove optional brackets.
(progn (goto-char (car (_-where-double-newlines)))
(if (looking-at "[[][]]") (replace-match ""))))
(progn (goto-char (point-min))
(insert "\n\n" (lb-naletov-spdw lb-src lb-lag) "\n\n"))
(progn (goto-char (point-max))
(insert "\n\n" (lb-naletov-spdw lb-src (1+ lb-lag-max)) "\n\n"))))
(defun lb-naletov-parse-tx-make-log (&optional arg1pf)
""
;;
(let (lb-pf lb-cons lb-pt-beg lb-pt-end lb-str lb-type lb-log lb-temp-buffer
;; fix!
(lb-str-defun "lb-naletov-parse-tx-make-log"))
(if (file-exists-p (setq lb-log (concat (if arg1pf arg1pf (bfn)) ".log")))
(if (string-lessp (_-timestamp lb-log) ;"2005-07-20T13:23:18-0700"
(_-timestamp arg1pf)) ;"2005-07-20T18:45:46-0700"
(delete-file lb-log)))
(when (not (file-exists-p lb-log))
(with-temp-buffer
(insert "\n\n" lb-str-defun "\n\n")
(append-to-file (point-min) (point-max) lb-log))
(when arg1pf
(set-buffer (setq lb-temp-buffer
(get-buffer-create (make-temp-name ""))))
(_-ifcl arg1pf))
(goto-char (point-min))
(while (search-forward-regexp "[^ \t\n]" nil t)
(progn (goto-char (setq lb-pt-beg (car (setq lb-cons
(_-where-double-newlines)))))
(setq lb-str (buffer-substring-no-properties
lb-pt-beg (setq lb-pt-end (cdr lb-cons))))
(setq lb-type (lb-naletov-para-type lb-str lb-type)))
(with-temp-buffer
(insert "\n\n" lb-type ""
(if (string-match
(concat "^" lb-naletov-re-lvl "$") lb-type)
(concat " " (int-to-string lb-pt-beg) "\n" lb-str)
(if (string= "PG#" lb-type)
(concat " " (int-to-string lb-pt-end) "\n" lb-str)
(if (string-match "\\([^ \t\n]+\\)[ \t\n]" lb-str)
(concat "\n" (match-string 1 lb-str))
(concat "\n" lb-str))))
"\n\n")
(append-to-file (point-min) (point-max) lb-log))
(goto-char (cdr lb-cons)))
(if arg1pf (kill-buffer lb-temp-buffer))
(with-temp-buffer
(_-ifcl lb-log)
(_-compress-multiple-newlines)
(write-region (point-min) (point-max) lb-log))) lb-log))
(defun lb-naletov-get-tx (arg1subpath)
""
;; BEFORE
;; (lb-naletov-get-tx "en/1984/AP470") => [sorted list of .tx files]
;; AFTER
;; (lb-naletov-get-tx "en/1984/AP470") => ("~/leninist.biz/en/1984/AP470/text")
(let (lb-pf lb-list)
(if (< 1 (length (setq lb-list (lb-naletov-get-copy-dirs arg1subpath))))
(error "%s: %s" "More than one copy" (prin1-to-string lb-list))
(setq lb-pf (car lb-list)))
(when nil
(with-temp-buffer
(shell-command
(concat "find " lb-pf " -type f -name '[0-9][0-9][0-9].tx'") t)
(shell-command
(concat "find " lb-pf " -type f -name '[0-9][0-9][0-9][0-9].tx'") t)
(sort-lines nil (point-min) (point-max))
(_-buffer-to-list)))
(when t
(setq lb-pf (concat lb-home arg1subpath "/index.txt"))
(list lb-pf ))))
(defun lb-naletov-make-tx-logs (arg1subpath)
""
;; (lb-naletov-make-tx-logs "en/1984/AP470")
(let (lb-pf lb-pf-log lb-rc)
(loop for lb-pf in (lb-naletov-get-tx arg1subpath)
do
(with-temp-buffer
(_-ifcl lb-pf)
(setq lb-pf-log (lb-naletov-parse-tx-make-log lb-pf))
(setq lb-rc (append lb-rc (list lb-pf-log))))) lb-rc))
(defun lb-naletov-get-__s (arg1text)
"Return list of all __TAGS__ in file"
;;
(let (lb-str lb-list)
(with-temp-buffer
(progn (_-ifcl arg1text)
(goto-char (point-min)))
(while (search-forward-regexp lb-re-__ nil t)
(setq lb-str (match-string 0))
(if (and (not (string-match "_COMMENT__$" lb-str))
(not (member lb-str lb-list)))
(setq lb-list (append lb-list (list lb-str)))))) lb-list))
(defun lb-naletov-gen-html-includes (arg1pf)
""
;;
(let (lb-str lb-pf)
(goto-char (point-min))
(while (search-forward-regexp (concat "##" "\\([^ \t\n]+\\)"
"##") nil t)
(setq lb-pf (concat (file-name-directory arg1pf)
(match-string 1)))
(replace-match
(with-temp-buffer
(_-ifcl lb-pf)
(lb-naletov-gen-html-includes lb-pf) ;; RECURSIVE.
(buffer-string))))))
(defun lb-naletov-__handler (arg1action arg2var &optional arg3str)
""
;; (lb-naletov-__handler "PUT" "FOO1" "xyyz") => "PUT"
;; (lb-naletov-__handler "GET" "FOO1") => "xyyz"
;; (lb-naletov-__handler "GET" "FOO1" t) => ("__FOO1__" . "xyyz")
;; (lb-naletov-__handler "DEL" "FOO1") => "DEL"
(let (lb-str lb-existing)
(if (not (string-match _-re-__ arg2var)) ;; Accept 'FOO' for ARG2.
(setq arg2var (concat "__" arg2var "__")))
(if (string= "PUT" (upcase arg1action))
(and (or (setq lb-existing (lb-naletov-__handler "GET" arg2var t)) t)
(or (setq lb-naletov-__ (delete lb-existing lb-naletov-__)) t)
(if (stringp arg3str)
(and (setq lb-naletov-__ (append (list (cons arg2var arg3str))
lb-naletov-__))
arg1action)))
(if (string= "GET" (upcase arg1action))
(and (or (setq lb-existing (assoc arg2var lb-naletov-__)) t)
(if arg3str lb-existing (cdr lb-existing)))
(if (string= "DEL" (upcase arg1action))
(and (or (lb-naletov-__handler "PUT" arg2var) t)
arg1action)
(error "%s: %s" "Invalid ARG1" arg1action))))))
(defun lb-assign-nav-__ (arg1current_n1 arg2dir arg3sections arg4hrefs)
""
;;
(let (lb-str lb-list lb-dir-offset lb-href)
(setq lb-dir-offset (if (string= "PREV" arg2dir) -1
(if (string= "NEXT" arg2dir) +1
(error "%s: %s" "Invalid choice" arg2dir))))
(if (and (string= "PREV" arg2dir) (< arg1current_n1 2))
(progn (lb-naletov-__handler "PUT" "PREV_CHAPTER" "")
(lb-naletov-__handler "PUT" "PREV_SECTION" ""))
(if (and (string= "NEXT" arg2dir) (> arg1current_n1
(- (length arg3sections) 2)))
(progn (lb-naletov-__handler "PUT" "NEXT_CHAPTER" "")
(lb-naletov-__handler "PUT" "NEXT_SECTION" ""))
;; Above prevents (nth -1 lb-sections) from happening.
(setq lb-list
(lb-naletov-get-headings (+ arg1current_n1 lb-dir-offset)
arg3sections))
;;; (lb-naletov-get-headings 1 lb-sections) => (nil "INTRODUCTION" nil)
;;; (lb-naletov-get-headings 2 lb-sections)
;;; => ("CHAPTER ONE" "BETWEEN SCIENCE
;;; AND METAPHYSICS" "1. METAPHYSICS AND
;;; ANTI-METAPHYSICS OF POSITIVISM")
;;; (lb-naletov-get-headings 3 lb-sections)
;;; => ("CHAPTER ONE" "BETWEEN SCIENCE
;;; AND METAPHYSICS" "2. METAPHYSICS
;;; OF ``CRITICAL RATIONALISM''")
;;; (lb-naletov-get-headings 16 lb-sections) => (nil "SUBJECT INDEX" nil)
;;; (lb-naletov-get-headings 17 lb-sections) => nil
;;;
(setq lb-href
(concat " href=\""
(cdr (assoc
(+ arg1current_n1 lb-dir-offset)
arg4hrefs)) "." lb-naletov-extension-html "\""))
;; First item in list is nil if Introduction, Conclusion, etc.
;; If first item is not nil, it is a chapter section.
(if (setq lb-str (nth 0 lb-list))
(progn (lb-naletov-__handler "PUT"
(concat arg2dir "_CHAPTER")
(concat "\n\n"
""
(upcase-initials
(downcase (nth 0 lb-list) ))
": " "\n\n"
(nth 1 lb-list)
"" "\n\n"))
(lb-naletov-__handler "PUT"
(concat arg2dir "_SECTION")
(concat "\n\n"
""
(nth 2 lb-list)
"" "\n\n")))
;; Adjacent section is not part of a chapter.
(lb-naletov-__handler "PUT" (concat arg2dir "_CHAPTER") "")
;;
(lb-naletov-__handler "PUT"
(concat arg2dir "_SECTION")
(concat "\n\n"
""
(nth 1 lb-list) ;; "1" is "2" above!
"" "\n\n")))))))
(defun lb-naletov-gen-html (arg1subpath)
""
;; (setq arg1subpath "en/1984/AP470")
;; MAIN: (lb-naletov-gen-html arg1subpath)
(let (lb-pf lb-str lb-pf-log lb-pf-text lb-i0 lb-item lb-cons
lb-pages lb-pg lb-pg-previous lb-sections
lb-html-hrefs lb-html-href
lb-pf-out)
;;
;; $ awk -f ~/leninist.biz/crstrip.awk *.tx > ../index.txt
;;
(setq lb-pf-log (car (lb-naletov-make-tx-logs arg1subpath)))
(setq lb-pf-text (file-name-sans-extension lb-pf-log))
;;
(setq lb-pages (lb-naletov-parse-tx-pts-past-pg lb-pf-log))
;;
(setq lb-sections (lb-naletov-parse-tx-sections lb-pf-log lb-pages))
;; 17 items, first is contents, last is last section (one-based).
;; ~/leninist.biz/en/html.hrefs
;;
;; 17 items, first is first section, last is dummy endpoint (zero-based).
;; (length lb-sections) => 17
;;
(setq lb-html-hrefs (lb-naletov-get-html-hrefs arg1subpath))
;;
(setq lb-__s (lb-naletov-get-__s lb-pf-text))
;;
(with-temp-buffer
(_-ifcl
(setq lb-pf (concat (file-name-directory lb-pf-text) "naletov0.htmm")))
(write-region (point-min) (point-max)
(concat (file-name-sans-extension lb-pf)
"." lb-naletov-extension-html)))
(loop for lb-i0 from 0 to (- (length lb-sections) 2)
do
(setq lb-item (nth lb-i0 lb-sections))
(setq lb-html-href (cdr (assoc (1+ lb-i0) lb-html-hrefs)))
(with-temp-buffer
(progn (fundamental-mode)
(setq local-write-file-hooks nil))
(progn (setq lb-pf (concat lb-home arg1subpath "/"
lb-naletov-file-html-template))
(_-ifcl lb-pf)
;;
(lb-naletov-gen-html-includes lb-pf))
;;
(progn (goto-char (point-min))
(search-forward "%%data%%")
(delete-region (car (setq lb-cons (_-where-double-newlines)))
(cdr lb-cons)))
;; Insert section.
(insert (lb-naletov-gen-text lb-pf-text (1+ lb-i0) lb-sections))
;; Queue data for headings substitution.
(progn (setq lb-list (lb-naletov-get-headings (1+ lb-i0)
lb-sections))
(lb-naletov-__handler "PUT" "CHAPTER_LVL1"
(if (setq lb-str (nth 0 lb-list))
lb-str ""))
(lb-naletov-__handler "PUT" "SECTION_LVL1"
(if (setq lb-str (nth 1 lb-list))
lb-str ""))
(lb-naletov-__handler "PUT" "SECTION_LVL2"
(if (setq lb-str (nth 2 lb-list))
lb-str ""))
(setq lb-str (concat ""
"Alternatives to "
"
Positivism"))
(lb-naletov-__handler "PUT" "TOC" lb-str))
;;
;; Queue data for navigation.
(lb-assign-nav-__ (1+ lb-i0) "PREV" lb-sections lb-html-hrefs)
(lb-assign-nav-__ (1+ lb-i0) "NEXT" lb-sections lb-html-hrefs)
;;
;; __ substitutions.
(lb-naletov-sub-__ lb-naletov-__)
;;
;; Delete __TAGS__
(when nil
;; DO NOT DELETE. Let us see them if they fall through.
(goto-char (point-min))
(while (search-forward-regexp lb-re-__ nil t)
(delete-region (car (setq lb-cons (_-where-double-newlines)))
(cdr lb-cons))))
;; Footnotes
(lb-naletov-footnotes nil)
;; Shrink.
(_-compress-multiple-newlines)
;; Delete last spdw (dummy marker).
(progn (goto-char (point-max))
(search-backward "