;; Poor Man's Markup. ;; Emacs-Time-stamp: "2008-08-17 07:57:14" (setq file-stamp "Emacs-File-stamp: \"/home/ysverdlov/leninist.biz/lb-tx.el\"") ;; (tx-page-number-p) (defun tx-page-number-p nil "Is this paragraph a page number?" (let (_str _rc) (if (and (not (_-blank-line-p)) (string-match lb-re-bracketed-integer-anchored (setq _str (_-normalize-whitespace (car (_-para t t)))))) (setq _rc (match-string-no-properties 0 _str))) _rc)) ;; (defun lb-tx-globals () "2007.06.25" ;; (let (_assoc _rc) (setq _assoc (_-find-file-hooks-__-globals)) ;; (if (setq lb-str (cdr (assoc "__WHERE_PAGE_NUMBERS__" _assoc))) (setq _-where-page-numbers-global lb-str) (makunbound '_-where-page-numbers-global)) ;; (if (setq lb-str (cdr (assoc "__FOOTNOTE_MARKER_STYLE__" _assoc))) ;; (setq lb-re-^^marker^^ (setq _-re-footnote-marker-global (concat "\\^\\^\\(" lb-str "\\)\\^\\^")) (makunbound '_-re-footnote-marker-global)) _rc)) ;; (defun lb-tx-delete-indexes () "" ;; (let ( _rc) (if (file-exists-p lbg-text-indextx) (delete-file lbg-text-indextx)) (if (file-exists-p lbg-text-indextxlog) (delete-file lbg-text-indextxlog)) (if (file-exists-p lbg-text-indextxt) (delete-file lbg-text-indextxt)) _rc)) ;; (lb-tx-make-or-refresh-indextx) ;; dired: M-x lb-tx-make-or-refresh-indextx (defun lb-tx-make-or-refresh-indextx () "If time-stamps or missing files dictate, do this: ... /1981/PCM336$ rm index.txt index.tx.log ... /1981/PCM336$ cat 20*/*.tx > index.tx ... $ [Emacs: create index.tx.log] NOTE: Uses regexps from lb-defvar instead of '*'. If called interactively in dired-mode, uses path from _-dired-get-fullpath, otherwise uses path from lbg-text-indextx" (_-dfun-hook "lb-tx-make-or-refresh-indextx") ;; (interactive) ;; Useful from dired. (let (lb-command lb-pf lb-where-page-numbers lb-path lb-rc) ;; fix! ;; How to automate ``mrm *.html'' via lftp? ;; 2006.11.17 - Decided to drop ".html" extension. ;; How to synch remote website with local drive? ;; --------------------------------- ;; howto fix! ;; Get a directory listing, exclude ".jpg", then run ;; "file" command, deleting ones that are: ;; login@debian:~/leninist.biz/en/1989/HCM243$ file china.html ;; china.html: HTML document text ;; --------------------------------- ;; SEE: (lb-delete-files ...) ;; --------------------------------- ;; nofix! ;; Create set of ".tx.log" files to go along w/ ".tx" files. ;; If ".tx" changes, update ".tx.log". ;; NO! Webpages created from index.tx, so .log for that ONLY! ;; For use with function key from within dired: (if (not (eq 'dired-mode major-mode)) (setq lb-path (file-name-directory lbg-text-indextx)) ;; (setq lb-path (_-dired-get-fullpath)) ;; ;; CASE 1: /home/login/leninist.biz/en/1981/1HU376/20051214: ;; CASE 2: /home/login/leninist.biz/en/1981/1HU376: (if (not (string-match lb-re-path-year+book lb-path)) (setq lb-path nil) ;; Chop-off book-instance? (when (string-match lb-re-path-year+book-instance lb-path) (string-match (concat ;; fix? Chop-off trailing slash? No. Neither method above does. "/?" lb-re-YYYYMMDD "/?$") lb-path) (setq lb-path (replace-match "/" t t lb-path))))) ;; ------------------------------------------------------- ;; ------------------------------------------------------- (when lb-path ;;;(message "%s" (concat "xxx lb-path " lb-path));2007.07.18-ugh-how.did.this.fix.it? ;; ------------------------------------------------------- (when ;; .tx (or (not (file-exists-p ;; fix! why one relative and other absolute? ;; lbg-text-indextx => ;; "~/leninist.biz/en/0000/EROS999/index.tx" ;; lbg-text-indextxt ;; "/home/ysverdlov/leninist.biz/en/0000/EROS999/index.txt" ;; 2007.08.19 - allow more stuff in txt, less in tx__>webpages. ;; lbg-text-indextx lbg-text-indextxt )) (and ;; Got little .tx files? (setq lbg-str-little-tx-files (with-temp-buffer (shell-command (setq lb-command (concat "cd " lb-path " ; " "find " lb-re-YYYYMMDD " -follow" " -mindepth 1 -maxdepth 1 " " -name '" lb-re-tx-100pages "' " " | sort" )) t) (goto-char (point-min)) (while (search-forward-regexp "\n" nil t) (replace-match " ")) (if (string= "" (buffer-string)) nil (buffer-string)))) ;; Was a little .tx changed more recently than big .tx ? (setq lbg-str-little-tx-files-changed (with-temp-buffer (shell-command (setq lb-command (concat "cd " lb-path " ; " "find " lb-re-YYYYMMDD " -follow" " -mindepth 1 -maxdepth 1 " " -name '" lb-re-tx-100pages "' " " -cnewer " ;; 2007.08.19 - allow more stuff in txt, ... ;; lbg-text-indextx lbg-text-indextxt )) t) (if (string= "" (buffer-string)) nil (buffer-string)))) ) ;; and ) ;; or ;; Delete files independently of cat-ing *.tx into index.tx. (with-temp-buffer ;;;(message "%s" (concat "xxx rm files"));2007.07.18-ugh-how.did.this.fix.it? (shell-command (setq lb-command (concat "cd " lb-path " ; " ;; fix? use lbg-text-indextxt ? "rm -f" " " lb-file-txt " " lb-file-tx " " lb-file-tx ".log ; " )) nil (current-buffer)) (setq lb-rc (concat lb-rc (buffer-string)))) ;; Create file. (with-temp-buffer ;;;(message "%s" (concat "xxx create file"));2007.07.18-ugh-how.did.this.fix.it? (shell-command (setq lb-command (concat "cd " lb-path " ; " "awk -f " lb-home ;; "cat " ;; 2007.08.19 "9tx2txt.awk " ;; lb-re-YYYYMMDD "/" lb-re-tx-100pages ;; 2007.08.19 (concat " | awk -f " lb-home "crstrip.awk ") " > " ;; 2007.08.19 - allow more stuff in txt, ... ;; lb-file-tx lb-file-txt ;; 2007.08.19 (progn (lb-lftp-dosomething-file lbg-text-indextxt) nil) ;; " 2>/dev/null" " ; " ;;; fix! ;;; fix! man bash / "Pathname Expansion" ;;; fix! ;;; AWK complains if it cannot find 9999.tx files. ;;; (Shell command failed with no output) ;;; (Shell command succeeded with no output) ;;; "[2][0][0-9][0-9][0-9][0-9][0-9][0-9]/[0-9][0-9][0-9][0-9].tx " )) ;; Use current-buffer as ERROR-BUFFER; will be used for rc. nil (current-buffer)) (setq lb-rc (concat lb-rc (buffer-string)))) ;; ------------------------------------------------------- ;; Checks, with write-file. (with-temp-buffer ;;;(message "%s" (concat "xxx checks"));2007.07.18-ugh-how.did.this.fix.it? (insert-file-contents-literally ;; 2007.08.19 - allow more stuff in txt, less in tx__>webpages. ;; lbg-text-indextx lbg-text-indextxt ) ;; --------------------------------- ;; CHECKS ;; 2007.01.25 ;; Sets lbg-str-time-stamps . (tx-check-buffer lbg-text-indextxt) ;; --------------------------------- ;; ON-THE-FLY: lb-tx-make-or-refresh-indextx ;; Changes acceptable in both index.txt and index.tx ;; Remove all but latest Emacs-Time-stamp . (when (and lbg-str-time-stamps (> (length lbg-str-time-stamps) 1)) ;;;(message "%s" (concat "xxx ON-THE-FLY"));2007.07.18-ugh-how.did.this.fix.it? (goto-char (point-max)) (while (search-backward-string lb-str-emacs-time-stamp nil t) (_-para-delete)) ;; (insert "\n\n" (with-temp-buffer (loop for i in lbg-str-time-stamps do (insert i "\n")) (sort-lines t (point-min) (point-max)) (goto-char (point-min)) (_-current-line)) "\n\n") (message "%s: %s" _defun "Emacs-time-stamps replaced with latest.")) ;; 2007.02.25 - 1st line indentation: join 1st and 2nd if 1st = "
" (goto-char (point-max)) (while (search-backward-regexp (concat "^
" "\\([\n]\\)" _-^whitespace-noM) nil t) (replace-match (concat " " " " " " " " " ") t t nil 1)) ;; fix! likewise for "
" ... make all right-aligned to fixed col. ;; 2006.08.22 ;; __ALPHA_LVL0__ should be last, with 1,2,3 in body (not 0,1,2). (goto-char (point-max)) (search-backward-regexp "_LVL[0-9]__") (if (search-backward "_LVL0_" nil t) (error "%s: %s" "Use 1,2,3 in body" (concat "_LVL0 not at end" "\n" (_-buffer-substring-from-)))) (message "%s: %s" _defun "LVL0 checked.") ;; 2007.04.05 ;; Delete character used to force newline in .tx file before ;; next ^M. (goto-char (point-max)) (while (sbs ;; fix! ;; "_" or "=" to insert newline in middle of line? ;; What about " = \n" or " = \r\n" ? tx-str-fill-paragraph-midline nil t) (replace-match "")) ;; 2007.10.01 (lb-gender-changer) ;; 2007.12.17 - was in tx-check-buffer (lb-pmm-transform-shadow-copies) ;; --------------------------------- ;; WRITE. ;; Write back to disk due to time-stamp. (_-compress-multiple-newlines) (write-region (point-min) (point-max) ;; 2007.08.19 - allow more stuff in txt, ... ;; lbg-text-indextx lbg-text-indextxt ) ) ;; with-temp-buffer ) ;; WAS: .tx NOW: .txt ;; ------------------------------------------------------- (when ;; .txt (or (not (file-exists-p ;; 2007.08.19 - allow more stuff in txt, less in tx__>webpages. ;; lbg-text-indextxt lbg-text-indextx )) (string< (_-timestamp ;; lbg-text-indextxt lbg-text-indextx ) (_-timestamp ;; lbg-text-indextx lbg-text-indextxt ))) ;;;(message "%s" (concat "xxx .txt"));2007.07.18-ugh-how.did.this.fix.it? ;; ------------------------------------------------------- ;; Create file. (with-temp-buffer ;;;(message "%s" (concat "xxx awk"));2007.07.18-ugh-how.did.this.fix.it? (shell-command (setq lb-command (concat "cd " lb-path " ; " "awk -f " lb-home ;; 2007.08.19 ;; "tx2txt.awk " "" "txt2tx.awk " ;; "crstrip.awk " ;; lb-file-tx lb-file-txt " > " ;; lb-file-txt lb-file-tx ;; 2007.08.19 ;; (progn (lb-lftp-dosomething-file lbg-text-indextxt) nil) " ; " )) ;; Use current-buffer as ERROR-BUFFER; will be used for rc. nil (current-buffer)) (setq lb-rc (concat lb-rc (buffer-string)))) ) ;; .txt ;; ------------------------------------------------------- (when ;; .tx.log ;;;(message "%s" (concat "xxx tx.log"));2007.07.18-ugh-how.did.this.fix.it? ;; Function creates it if it does not exist. ;; Function deletes then creates it if timestamp is stale. t ;; ------------------------------------------------------- ;; Create file. (lb-tx-parse-tx-make-log) ) ;; .tx.log ) (if (string= "" lb-rc) (setq lb-rc nil)) lb-rc)) ;; (setq arg1pf "~/leninist.biz/en/1976/HA243/20060412/099odd.tx") ;; (setq arg1pf "~/www.marxists.org/archive/lenin/works/cw/v36pp71/099even.tx") ;; (lb-tx-parse-tx-make-log arg1pf) ;; ;; lb-tx-make-or-refresh-indextx: (lb-tx-parse-tx-make-log) (defun lb-tx-parse-tx-make-log (&optional arg1pf arg2type) "Create a .log from ARG1 unless time-stamp of former is newer. Loop forward searching for non-whitespace; move to end of paragraph; pass paragraph to lb-ht-para-type to determine type. Optional ARG1 is input file, defaults to lbg-text-indextx. Optional ARG2 is type of object (e.g., PG#) to limit log file" (_-dfun-hook "lb-tx-parse-tx-make-log") ;; (let (lb-pf lb-cons-wdn lb-para lb-cons lb-re lb-str lb-pg lb-int lb-roman-page-cnt lb-pt-beg lb-pt-end lb-type lb-log lb-buffer-log lb-buffer-temp (lb-current-buffer (current-buffer)) lb-globals _rc) (if (not arg1pf) (setq arg1pf lbg-text-indextx )) ;; fix! ;; Check page numbers first! Crashed on roman numerals NOT page #s. ;; --------------------------------- ;; fix! ;; If input file is a 100-page text chunk (see lb-tx-merge-odd-even), ;; check for unreasonable page numbers, for example, page numbers from ;; Table of Contents that are not joined with heading. ;; let ;; n-expect-page-first n-expect-page-last ;; (progn (setq n-expect-page-last (string-to-int arg1endpage)) ;; (setq n-expect-page-first (- n-expect-page-last 99))) (progn ;; Maybe delete stale log file. (if (file-exists-p (setq lb-log (concat arg1pf "." lb-ext-txlog))) (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 ;; If logfile does not exist or was deleted. (not (file-exists-p lb-log)) (progn ;; Create temp buffer and read input data from disk. (set-buffer (setq lb-buffer-temp (get-buffer-create (make-temp-name "")))) (_-ifcl arg1pf) (setq lb-globals (_-find-file-hooks-__-globals nil t)) ;; 2007.08.01 (lb-tx-check-page-numbers arg1pf) lb-buffer-temp) (progn ;; Start log file. (when (setq lb-buffer-log (find-buffer-visiting lb-log)) (kill-buffer lb-buffer-log)) ;; (setq lb-buffer-log (find-file lb-log)) (setq _-where-page-numbers ;; fix? This should be done in lb-tx-globals only! (setq _-where-page-numbers-global (cdr (assoc "__WHERE_PAGE_NUMBERS__" lb-globals)))) ;; fixed! No need to insert two newlines beforehand, just one. (insert "\n" _defun "\n\n") lb-log) ;; BEGIN. Temp buffer has copy of index.tx (set-buffer lb-buffer-temp) ;; Converting roman page numbers to negative PG numbers. No page "0". (progn (goto-char (point-min)) (setq lb-roman-page-cnt 0) ;; fix! check sequence ... i ... ii ... iii ... or check it in .log! (while (and (sfr lb-re-bracketed-para-integer nil t) (not (string-match "[0-9]" (match-string-no-properties 0))) (setq lb-roman-page-cnt (1- lb-roman-page-cnt)))) (if (= 0 lb-roman-page-cnt) (setq lb-roman-page-cnt nil)) lb-roman-page-cnt) ;; MAIN. Keep searching for non-whitespace character. (goto-char (point-min)) (while (and (search-forward-regexp "[^ \t\n\r]" nil t) (progn (forward-char -1) (goto-char (setq lb-pt-beg (car (setq lb-cons-wdn (_-where-double-newlines))))) (setq lb-para (buffer-substring-no-properties lb-pt-beg (setq lb-pt-end (cdr lb-cons-wdn)))) (setq lb-type (lb-ht-para-type lb-para lb-type)) t)) ;; fix! Toss this check into step that creates index.tx !! ;; LVL's must have data. (if (and (not (string-match "[ \t\n]" lb-para)) (string-match "__[A-Z]+_LVL[0-9]__" lb-para)) (error "%s: %s" "Missing data" lb-para)) ;; MAIN. (when (or (not arg2type) (string= lb-type arg2type)) ;; fix? One with-temp-buffer per paragraph seems like a lot. (with-temp-buffer (insert ;; First (and maybe only) word of first line: "\n\n" lb-type "" (cond ((or (string= "__WHERE_PAGE_NUMBERS__" lb-type) (string-match (concat "^" lb-re-__-lvl4chunking "$") lb-type) (string-match (concat "^" lb-re-__-titles "$") lb-type)) ;; Retain beg. pt. of __WHERE_PAGE_NUMBERS__ in log file. ;; Retain beg. pt. of lb-re-__-lvl4chunking in log file. ;; Retain beg. pt. of lb-re-__-titles in log file. ;; INSERT: (concat " " ;; Begin point (where-page-numbers). ;; Begin point (chapters/NUMERICs and sections/ALPHAs). ;; Begin point (title and subtitles). (int-to-string lb-pt-beg) ;; Paragraph. "\n" lb-para)) ((string= "PG#" lb-type) ;; Retain beg. pt. of page number. ;; Retain value of page number. ;; INSERT: end point (page numbers). (concat " " (int-to-string (if (string= "top" _-where-page-numbers) lb-pt-beg lb-pt-end)) ;; 2006.11.23 - Add true page number after start point. ;; 2007.03.02 - True PG# for last Roman numeral page is "-1". (concat " " ;; (_-string-to-int "1") ;; (_-string-to-int "[2]") ;; (_-string-to-int "-3-") ;; (_-string-to-int "-3") ;; 2007.02.27 - en/1976/NSO261/ ;; [i] ;; NOTE: Not able to just keep it at level of a string! ;; NOTE: Want PG#s in .log to be independent of top/bottom. ;; Non-Roman numbered pages: (if (setq lb-int (_-string-to-int lb-para)) ;; Will remove brackets: (if (string= "top" _-where-page-numbers) (int-to-string lb-int) ;; If page numbers at bottom, assume they are at top! (int-to-string (1+ lb-int))) ;; 2007.02.27 - Roman numbered page. ;; 2007.03.02 - Already added 1 if PG#'s at bottom (Cabove)! ;; In log file, all PG#'s assumed at *TOP* of page! ;; If i thru xxii and PG#'s at bottom, PG# i is... -21. ;; If i thru xxii and PG#'s at bottom, PG# ii is... -20. ;; If i thru xxii and PG#'s at bottom, PG# xxi is... -1 . ;; If i thru xxii and PG#'s at bottom, PG# xxii is... 1 . ;; --- ;; In log file, all PG#'s assumed at *TOP* of page! ;; If i thru xxii and PG#'s at top, PG# i is... -22. ;; If i thru xxii and PG#'s at top, PG# ii is... -21. ;; If i thru xxii and PG#'s at top, PG# xxi is... -2 . ;; If i thru xxii and PG#'s at top, PG# xxii is... -1 . (progn (setq lb-str lb-roman-page-cnt) (if (string= "bottom" _-where-page-numbers) (if (= -1 lb-roman-page-cnt) (setq lb-str 1) (setq lb-str (1+ lb-str)))) (setq lb-str (int-to-string lb-str)) (setq lb-roman-page-cnt (1+ lb-roman-page-cnt)) lb-str))) ;; Paragraph. "\n" lb-para)) ;; Retain first word of a BIG paragraph. ((string-match (concat "\\([^" (setq lb-re " \t\n\r") "]+\\)[" lb-re ;; SEE 2 lines up. "]") lb-para) ;; INSERT: (concat "\n" (match-string 1 lb-para))) ;; OTHERWISE. One-word paragraph that isn't special. (t ;; INSERT: (concat "\n" lb-para))) ;; Blank line after this "record". "\n\n") (setq lb-str (buffer-string))) (set-buffer lb-buffer-log) (insert lb-str) (set-buffer lb-buffer-temp)) ;; when (goto-char lb-pt-end)) ;; while (kill-buffer lb-buffer-temp) (set-buffer lb-buffer-log) ;; fix? Should be able to control multiple blank lines. (_-compress-multiple-newlines) (basic-save-buffer-1) (kill-buffer (current-buffer)) (set-buffer lb-current-buffer)) (setq _rc lb-log) _rc)) ;; (lb-tx-merge-odd-even "~/leninist.biz/en/1976/HA243/20060412/099even.tx") ;; (lb-tx-merge-odd-even "~/leninist.biz/en/1976/HA243/20060412/199odd.tx") ;; (lb-tx-merge-odd-even "~/leninist.biz/en/1976/HA243/20060412/243odd.tx") ;; ;; (setq arg1pf "~/www.marxists.org/archive/lenin/works/cw/v36pp71/099even.tx") ;; (lb-tx-merge-odd-even arg1pf "PG#") (defun lb-tx-merge-odd-even (&optional arg1pf arg2type) "Combine (edited) 999even.tx and (edited) 999odd.tx into 999.tx. Point data is taken from temporary files created by lb-tx-parse-tx-make-log. ARG1 is path to either an odd or even .tx file. Optional ARG2 is passed to lb-tx-parse-tx-make-log. FIX: If page boundaries are VPST, put a dummy VPST at bottom of file, or fix lb-tx-parse-tx-make-log so it does not skip last page" (interactive) (let (arg1endpage arg1type lb-re arg1pfother arg1pfout arg1pflog arg1pfotherlog arg1pfpoints arg1pfotherpoints lb-cons0 lb-cons1 lb-cons lb-pf lb-pg (page-first "99999") (page-last "-99999") (page-first-default "99999") (page-last-default "-99999") lb-rc) ;; If no first argument, try using buffer-file-name. (if (not arg1pf) (setq arg1pf (bfn))) (if (not (string-match (setq lb-re (concat "/" lb-re-tx-odd-even "$")) arg1pf)) (error "%s: %s" arg1pf lb-re) ;; (setq arg1endpage (match-string-no-properties 1 arg1pf)) (setq arg1type (match-string-no-properties 2 arg1pf)) (if (not (file-exists-p arg1pf)) (error "%s: %s" "File not found" arg1pf)) (if (file-exists-p (setq arg1pfout (replace-match "" t t arg1pf 2))) (error "%s: %s" "File already exists" arg1pfout))) (if (not (file-exists-p (setq arg1pfother (replace-match (if (string= "odd" arg1type) "even" "odd") t t arg1pf 2)))) (error "%s: %s" "File not found" arg1pfother)) ;; fix! ;; Turn into function? ;; Throws an error instead of asking to save buffer. (if (find-buffer-visiting arg1pf) (if (buffer-modified-p (find-buffer-visiting arg1pf)) (error "%s: %s" "Save first" arg1pf) (kill-buffer (find-buffer-visiting arg1pf)))) (if (find-buffer-visiting arg1pfother) (if (buffer-modified-p (find-buffer-visiting arg1pfother)) (error "%s: %s" "Save first" arg1pfother) (kill-buffer (find-buffer-visiting arg1pfother)))) ;; (progn (setq arg1pflog (lb-tx-parse-tx-make-log arg1pf arg2type)) (setq arg1pfotherlog (lb-tx-parse-tx-make-log arg1pfother arg2type)) ;; (setq arg1pfpoints (lb-tx-parse-pg-points arg1pflog)) (setq arg1pfotherpoints (lb-tx-parse-pg-points arg1pfotherlog))) ;; Set bounds. (loop for i in (append arg1pfpoints arg1pfotherpoints) do (if (< (string-to-int (car i)) (string-to-int page-first)) (setq page-first (car i))) (if (> (string-to-int (car i)) (string-to-int page-last)) (setq page-last (car i)))) (if (or (string= page-last-default page-last) (string= page-first-default page-first)) (error "%s: %s" page-last-default page-first-default)) ;; Merge. (with-temp-buffer (loop for i from (string-to-int page-first) to (string-to-int page-last) do (setq lb-pg (int-to-string i)) (setq lb-cons0 (assoc lb-pg arg1pfpoints)) (setq lb-cons1 (assoc lb-pg arg1pfotherpoints)) (if (and lb-cons0 lb-cons1) (error "%s: %s" (concat "Page " lb-pg " found in both") (concat " + " arg1pf " + " arg1pfother))) (if (not (or lb-cons0 lb-cons1)) (error "%s: %s" "Missing page" lb-pg)) (setq lb-cons (if lb-cons0 lb-cons0 lb-cons1)) (setq lb-pf (if lb-cons0 arg1pf arg1pfother)) ;; (goto-char (point-max)) (insert "\n\n") ;; The two arguments START and END are character positions; ;; they can be in either order. ;; (buffer-substring-no-properties ;; (car (cdr lb-cons1)) (cdr (cdr lb-cons1))) ;; The optional third and fourth arguments BEG and END ;; specify what portion of the file to insert. ;; These arguments count bytes in the file, not characters in the buffer. (insert-file-contents-literally lb-pf nil (1- (car (cdr lb-cons))) (1- (cdr (cdr lb-cons)))) (insert "\n\n")) (_-compress-multiple-newlines) ;; fix! ;; Keep just one Emacs-Time-stamp: ... which one? ;; Check for duplicate __EMAIL__ etc. and (1) check for identity; (2) ;; delete 2nd copy. (progn ;; DO SIMULTANEOUSLY! (write-region (point-min) (point-max) arg1pfout) (progn ;; DO SIMULTANEOUSLY! (delete-file arg1pflog) (delete-file arg1pfotherlog) ;; Drop "x" from ".tx" (rename-file arg1pf (substring arg1pf 0 (1- (length arg1pf)))) (rename-file arg1pfother (substring arg1pfother 0 (1- (length arg1pfother)))))) ;; END TEMP BUFFER. ) (setq lb-rc arg1pfout))) ;; (setq lbg-text-indextxlog "~/leninist.biz/en/1973/WICIR313/index.txt.log") ;; (setq arg1pf lbg-text-indextxlog) ;; (setq lb-list (lb-tx-parse-pg-points arg1pf)) (defun lb-tx-parse-pg-points (arg1pf-log) "Return list of conses with page number and boundary points cons cell. Input comes from ARG1, a file created by lb-tx-parse-tx-make-log. If page numbers at top, car of cons cell is point to left of page number. If page numbers at bottom, cdr of cons cell is point to right of page number. - cons cell is the cdr of this return value - page number is the car of this return value" (_-dfun-hook "lb-tx-parse-pg-points") ;; (let (lb-pf lb-rc lb-lag lb-mstr1 lb-mstr2 (lb-re (concat "\n\nPG#" " " "\\([0-9]+\\)" ;; 2006.11.23 " " "\\([-]?[0-9]+\\)" ;; 2006.11.23 (when nil "\n" ;; Allow VPST for LIA, too. ;;"[[]?" "\\([0-9]+\\)" "[]]?" "\\([^\n]+\\)" ) ))) ;; PG# 1333 ;; [4] (with-temp-buffer (_-ifcl arg1pf-log) ;; fix? ;; How does this work? Will log file have globals? ;; For globals, should log file have whole paragraph, not just 1st token? (_-find-file-hooks-__-globals nil (if (not (string-match "[.]log$" arg1pf-log)) t)) (goto-char (setq lb-lag (if (string= "top" _-where-page-numbers) (point-max) (point-min)))) (if (string= "top" _-where-page-numbers) (while (search-backward-regexp lb-re nil t) (setq lb-mstr1 (match-string 1)) (setq lb-mstr2 (match-string 2)) ;; (_-app 'lb-rc (list (cons ;; Either page from pg= or whole string. (if (string-match ;; 2007.03.04 ;; "pg=0*\\([0-9]+\\)" "pg=0*\\([-]?[0-9]+\\)" lb-mstr2) (match-string 1 lb-mstr2) lb-mstr2) (cons (string-to-int lb-mstr1) lb-lag) ))) (setq lb-lag (string-to-int lb-mstr1))) ;; fix! ;; duplicate code! except for direction of search and order of points. (while (search-forward-regexp lb-re nil t) (setq lb-mstr1 (match-string 1)) (setq lb-mstr2 (match-string 2)) ;; (_-app 'lb-rc (list (cons ;; Either page from pg= or whole string. (if (string-match ;; 2007.03.04 ;; "pg=0*\\([0-9]+\\)" "pg=0*\\([-]?[0-9]+\\)" lb-mstr2) (match-string 1 lb-mstr2) lb-mstr2) ;; 2006.04.17: Fixed: Reversed cons cell. (cons lb-lag (string-to-int lb-mstr1)) ))) (setq lb-lag (string-to-int lb-mstr1))) )) lb-rc)) (defun lb-tx-contextual-auto-edit (&optional arg1) "... Use carefully, because user must know what to exepect for end results! To insert page number and remove pair of [POINT], place point on blank line. To remove pair and delete blank lines (instead of insert page number), move point after '' in ''" ;; (interactive "*") (let (lb-rc lb-flag lb-pg (lb-pt (point))) (save-match-data (save-excursion (if (_-trailing-whitespacep 100 t) (error "%s: %s" "+/- 100 characters from here" "trailing whitespace")) ;; PRIORITY: HIGH. ;; Toss "^^" around "*" in a footnote. (when (and (not lb-flag) (progn (if (looking-at "[\n]+[ \t\n\r]*") (goto-char (match-end 0))) t) (progn (goto-char (car (_-where-double-newlines))) t) (looking-at "[ \t\n\r]*\\([*]+\\)[ \t\n\r]*")) (replace-match (concat "
~^^" (match-string-no-properties 1) "^^\n\n")) (setq lb-flag "ADD-^^-IN-FOOTNOTE")) ;; Point before (bottom-of-page) page number and empty VPST. (when (and (not lb-flag) ;; Skip back over whitespace(s) since expecting ;; two newlines before page number. (progn (_-move-backward-whitespace) t) (looking-at (concat lb-re-bracketed-para-integer "\\(" "" "\\)"))) (replace-match "" nil nil nil 2) (setq lb-flag "VPST")) ;; Add page number when point inbetween two pages and ;; in middle of sentence (thus, delete "
" "" pair). (when (and (not lb-flag) (save-excursion (forward-word -2) (looking-at (concat "[-.a-zA-Z]+[ \t\n\r]*
[ \t\n\r]*[\r]" "[\n][ \t]*[\n][ \t]*" "")))) (save-excursion (search-backward-regexp lb-re-bracketed-para-integer) (setq lb-pg (match-string-no-properties 1))) (insert "\n\n" (format "%d" (1+ (string-to-int lb-pg))) "\n\n") (progn (search-backward "
") (replace-match "")) (progn (search-forward "") (replace-match "")) (setq lb-flag "MIDSENTENCE-MIDPAGE")) ;; Join two paragraphs w/ point after "" ;; repeating, with the
^M ;; ;; OPTIONAL: 123 ;; ;;;; learned (when (and (not lb-flag) (save-excursion (forward-char -2) (looking-at (concat "\\(
\\)[ \t]*[\r][\n]" ;(1) "[ \t]*[\n]" "\\([ \t]*" ;(2) (_-del-parens lb-re-bracketed-integer) "[ \t\n\r]*\\)?" "[ \t]*\\(\\)")))) ;(3) (setq lb-flag (match-string-no-properties 2)) (replace-match "" nil nil nil 3) (replace-match "" nil nil nil 1) ;; Delete blank line(s) if no page number. (when (not lb-flag) (search-forward-regexp "\n\\([ \t\n\r]+\\)") (replace-match "\n")) (setq lb-flag "JOIN-PARAGRAPHS")) ;; END. ) ;; Outside of save-excursion (but not save-match-data). (when lb-flag (if (string= lb-flag "VPST") ;; Move point forward to prepare for deleting "
". (forward-word 2)) (when (string= lb-flag "JOIN-PARAGRAPHS") ;; Move point to first word after page number. (search-forward-regexp "[a-zA-Z]") (goto-char (match-beginning 0))) (when (string= lb-flag "ADD-^^-IN-FOOTNOTE" ) (search-forward "*") (search-forward-regexp "\n[ \t\n\r]*")) (recenter) )) lb-rc)) ;; (setq x (lb-tx-get-__ "\\(ALPHA\\|NUMERIC\\)_LVL[12]")) ;; (lb-tx-get-__ "ALPHA_LVL[12]") (defun lb-tx-get-__ (arg1__ &optional arg2deltag) "Search buffer for regexp ARG1 and return list with paragraphs. ARG1 is tag name with or w/o '__' quotes" (let ( lb-rc) (if (not (string-match "__" arg1__)) (setq arg1__ (concat "__" arg1__ "__"))) (save-excursion (goto-char (point-min)) (while ;; (search-forward-regexp arg1__ nil t) (lb-db-__-search- "forward" arg1__) (_-app 'lb-rc ;; 2006.12.28 ;;(buffer-substring-no-properties ;; (car (setq x (_-where-double-newlines))) ;; (cdr x)) (car (_-para nil nil arg2deltag))))) lb-rc)) (defun lb-tx-view-__ (arg1) "???" (interactive "p") (let (lb-rc lb-tagname (lb-scratch "~/*scratch*")) (setq lb-tagname (read-input "__ tag name: ")) (if (file-exists-p lb-scratch) (delete-file lb-scratch)) (setq lb-rc (lb-tx-get-__ lb-tagname)) (find-file lb-scratch) (loop for i in lb-rc do (insert "\n\n" i "\n\n")) (_-compress-multiple-newlines) (delete-other-windows) (goto-char (point-min)) (not-modified))) ;; (tx-check-buffer-LVLs) (defun tx-check-buffer-LVLs (&optional arg1) "" ;; (interactive "p") ;;; CHECK FOR THIS KIND OF ORDER: ;;; ;;; 19 lines matching "_lvl" in buffer 099.tx. ;;; 167:__NUMERIC_LVL1__ ;;; 170:__ALPHA_LVL1__ ;;; 174:__NUMERIC_LVL2__ ;;; 177:__ALPHA_LVL2__ ;;; 181:__ALPHA_LVL3__ ;;; 318:__ALPHA_LVL3__ ;;; 549:__ALPHA_LVL3__ ;;; 554:
\n\\([a-zA-Z]\\)" nil t) (setq msnp-0 (match-string-no-properties 0)) (setq msnp-1 (match-string-no-properties 1)) (setq msnp-2 (match-string-no-properties 2))) (save-excursion (goto-char (match-beginning 0)) (setq _para-prev (car (_-para)))) (if (and ;; letter before
is lowercase. (not (string= msnp-1 (upcase msnp-1))) ;; letter after is lowercase.
(or (not (string= msnp-2 (upcase msnp-2)))
;; ... or uppercase.
t)
(not (string-match "class=\"legal_article\"" _para-prev))
)
(error "%s: %s"
(concat "Page " (lb-tx-what-page) " has extra para break?")
msnp-0))))))
_rc))
(defun lb-tx-check-buffer4-singularities nil
""
;;
(let (
_rc)
(save-match-data
(save-excursion
;; 2007.04.13
(goto-char (point-min))
(when (sfr (concat "\\(" "•" "\\)") nil t)
(error "%s: %s" "Numeric entity 8226"
(_-buffer-substring-from-)))
;; 2007.04.06
;; Uppercase superscripts? See lb-abbyycln.
(when
(not (tx-first-draft-p))
(goto-char (point-min))
(setq case-fold-search nil)
(when (sfr "?SUP>" nil t)
(occur "?SUP>")
(error "%s: %s" "Uppercase superscript"
(_-buffer-substring-from-)))
(setq case-fold-search _orig-case-fold-search))
))
_rc))
(defun lb-tx-check-buffer4-trailing-dash nil
"Check for single trailing dash before carriage return.
No arguments"
;;
(let (_buffer _re
_rc)
(save-excursion
(save-match-data
(when
(and
(if (not (boundp 'TRIGGER-lb-tx-check-buffer4-trailing-dash))
t
(if (not (_-timestamp))
t
(string< TRIGGER-lb-tx-check-buffer4-trailing-dash
(_-timestamp))))
;; fix? This is a global variable?
tx)
(if (setq _buffer (get-buffer "*Occur*"))
(kill-buffer _buffer))
;; fix documentation. How does this work?
(goto-char (point-min))
(when (and
(sfr (setq _re "[^-][-][ ]*[\r]") nil t)
;; 2007.10.08
(not (looking-at (concat "[-]0" _-whitespace-noM))))
;; 2007.07.11
(occur _re)
(error "%s: %s" "Before carriage return, found single hyphen"
(_-buffer-substring-from-)))
)
))
_rc))
;;
(defun lb-tx-move-away-from-page-number-paragraph nil
"Moves point away from a paragraph that is a page number.
Moves backwards or forwards over whitespace depending on
value of _-where-page-numbers.
Useful if page numbers at top of file and point is in
paragraph with first page number"
;;
(let (
_rc)
(if (tx-page-number-p)
(goto-char
(sex
(if (string= "top" _-where-page-numbers)
(end-of-line)
(if (string= "bottom" _-where-page-numbers)
(beginning-of-line)
(error "%s: %s" "Expecting _-where-page-numbers"
"'bottom' or 'top'")))
(if (string= "top" _-where-page-numbers)
(_-move-forward-whitespace t)
(if (string= "bottom" _-where-page-numbers)
(_-move-backward-whitespace t)))
(point))))
_rc))
;;
(defun lb-tx-check-^^-get-list-and-check (arg1style)
"Called once by lb-tx-check-^^.
If both * and 0-9 footnotes co-exist, called twice"
;;
(let (lb-list lb-half
lb-str lb-n lb-n-other
lb-beg lb-end lb-page-end lb-pg
(lb-offset 0) (lb-pt (point))
_rc)
(save-match-data
(save-excursion
;; 2007.07.31
(lb-tx-move-away-from-page-number-paragraph)
(lb-ht-insert-^^-around-footnotes-asteriks)
(progn
(setq lb-pg (lb-tx-what-page))
(setq lb-page-end (lb-tx-page-point "page-end"))
(goto-char (lb-tx-page-point "page-beg")))
(while (and (search-forward-regexp (concat "\\^\\^"
arg1style
"\\^\\^") lb-page-end t)
(or (setq lb-beg (match-beginning 0))
t)
(setq lb-list (append lb-list
(list (match-string-no-properties
0)))))
;; 2007.05.10
(if (string= "" (buffer-substring-no-properties
(- lb-beg (length "")) lb-beg))
(error "%s: %s"
(concat "Open emphasis before marker on page "
(lb-tx-what-page))
(_-buffer-substring-from-)))
)
;;
(when lb-list
(if (oddp (length lb-list))
(error "%s: %s"
(concat
"Page " lb-pg ","
" odd number of items" (prin1-to-string lb-list))
(_-buffer-substring-from-)))
(setq lb-half (/ (length lb-list) 2))
;; What this?
(loop for i from 0 to (1- lb-half)
do
(if (not (string= (nth i lb-list) (nth (+ i lb-half) lb-list)))
(error "%s: %s"
(concat "Mismatch" (prin1-to-string lb-list))
(_-buffer-substring-from-)))
)
;; Check sequence.
(loop for i from 0 to (1- (length lb-list))
do
(setq lb-n (_-string-to-int (setq lb-str (nth i lb-list))))
;; If "***" convert to 3.
(if (not (integerp lb-n))
(if (not (string-match "^^^[*)]+^^$" lb-str))
(error "%s: %s"
"Not ^^999^^ nor ^^***)^^" lb-str)
;; Changed mind!
;; Do *NOT* convert "***..." to integer.
(when
nil
(setq lb-n (- (length lb-str)
(if (string-match "[)]" lb-str)
5 4)))) ;; WHEN.
))
(cond
((or
(string= arg1style
lb-re-footnote-marker-style-*)
(string= arg1style
lb-re-footnote-marker-style-*-paren))
;; If past the half-way mark, these should be anchors
;; in footnotes area.
(when (> lb-offset 0)
(if (not (string= (nth (- i 0 ) lb-list)
(nth (- i lb-offset) lb-list)))
(error "%s: %s"
(concat "Out of order" (prin1-to-string lb-list))
(_-buffer-substring-from-))))
) ;; *
((string= arg1style
lb-re-footnote-marker-style-9)
;; Set using
(unless (and (boundp '_-footnote-marker-sequence)
(string= "continuous" _-footnote-marker-sequence))
(if (/= (1+ (- i lb-offset)) lb-n)
(error "%s: %s"
(concat "Out of order" (prin1-to-string lb-list))
(_-buffer-substring-from-))))
) ;; 0-9
((string= arg1style
lb-re-footnote-marker-style-both)
(error "%s: %s" "How to check sequence?"
arg1style))
) ;; cond
(if (= (1+ i) lb-half) (setq lb-offset lb-half))
) ;; loop
;; Look for "_-_-_"
(goto-char (lb-tx-page-point "page-beg"))
(setq lb-beg (search-forward (nth (1- lb-half) lb-list)))
(setq lb-end (search-forward (car lb-list)))
(if (not (search-backward-regexp lb-re-footnote-div lb-beg t))
(error "%s: %s"
(concat "Missing" lb-re-footnote-div)
(_-buffer-substring-from-))))))
_rc))
(defun lb-tx-check-^^ (&optional arg1not-interactive arg2pg-para)
"Check for matching footnote anchors on current page.
ARG1, if non-nil, supresses tx-editing-insert-_-_-_ when
this called from tx-check-footnotes when that called from
lb-ht-refresh-indextx .
ARG2 is an optional page-paragraph from search immediately before
calling this function"
;;
(let (
_rc)
(save-match-data
;; Suppress action if editing 2-page .tx files for /lenin/.
(when
;; fix! make _-footnote-marker-style buffer-local. How?
;; This sets _-footnote-marker-style
(and (_-find-file-hooks-__-globals nil t)
(boundp '_-footnote-marker-style))
;; fix!
;; Separate function to check _-footnote-marker-style.
;; AND just accept all defvar's starting ``lb-re-footnote-marker-style-''
;; If just above first footnote, try to insert divider.
(if (not arg1not-interactive)
(setq _rc (tx-editing-insert-_-_-_)))
;; SEE ALSO second "(cond" below for checking sequence.
(cond
((or (string= _-footnote-marker-style
lb-re-footnote-marker-style-*)
(string= _-footnote-marker-style
lb-re-footnote-marker-style-*-paren))
;;
(lb-tx-check-^^-get-list-and-check _-footnote-marker-style)
)
((string= _-footnote-marker-style
lb-re-footnote-marker-style-9)
(lb-tx-check-^^-get-list-and-check _-footnote-marker-style)
)
;; 2006.11.16
((string= _-footnote-marker-style
lb-re-footnote-marker-style-both)
(lb-tx-check-^^-get-list-and-check
;; _-footnote-marker-style
lb-re-footnote-marker-style-*
)
(lb-tx-check-^^-get-list-and-check
;; _-footnote-marker-style
lb-re-footnote-marker-style-9
))
;; 2006.12.22
((string= _-footnote-marker-style
lb-re-footnote-marker-style-nil)
nil)
(t (error "%s: %s" "Invalid" "_-footnote-marker-style")))
) ;; when
(if _rc (recenter))
)
_rc))
(defun lb-tx-para-if-not-inside-move-forward-to-start nil
"If point on blank line or to left of whitespace on first line, move
to first non-whitespace character in paragraph"
;;
(let (lb-rc)
;; If at end of last line of paragraph, stay put.
(if (save-excursion
(beginning-of-line)
(looking-at "[ \t]*[\n]"))
;; If in blank line, move forward.
(search-forward-regexp "[ \t\n\r]+"))
(if (looking-at "[ \t]*[^ \t\n\r]") (goto-char (match-end 0))) lb-rc))
;; (lb-tx-para-move-back-and-skipover-re- "__PRINTERS_")
;; (lb-tx-para-move-back-and-skipover-re- "__\\(PRINTERS\\|PPPARAGRAPH\\)_")
(defun lb-tx-para-move-back-and-skipover-re- (&optional arg1re)
"Search backward for first alpha; move to beginning of paragraph; repeat
if looking at ARG1.
Returns point of last skipped-over ARG1, otherwise returns nil"
;;
(let (lb-rc)
;; (lb-tx-para-if-not-inside-move-forward-to-start)
(_-move-backward-whitespace)
(while (and (progn (search-backward-regexp "[^ \t\n\r]")
t)
(progn (goto-char (car (_-where-double-newlines)))
t)
;; fix!
;; Allow a list of expressions; loop over inside an "or".
(if (not arg1re)
nil
(looking-at arg1re))
;;
(setq lb-rc (point))))
lb-rc))
;; (lb-tx-footnote-end)
(defun lb-tx-footnote-end nil
"Return end-point of footnote when point at beginning of footnote text.
End of current footnote is either beginning of next footnote or
end of page contents; if the later, may not be true end-of-footnote if
it continues on next page.
Returns a cons cell where car is endpoint and cdr is either nil or
page number from __NOTE__ paragraph if footnote ends with a
lb-re-footnote-continued of type 'continued on' or error if not
of that type"
;;
(let (lb-rc lb-pt lb-str)
(save-match-data
(save-excursion
;; fix?
;; Inspect here?
;; Simply do 'looking-at' from current point?
;; When would point have to move from non-first footnote to first?
;; Move past footnote marker of this footnote before searching
;; for marker of next footnote.
;; fix?
;; Assume not looking at whitespace?
(_-move-forward-whitespace)
;; fix?
;; Test whether at beginning of footnote or a continuation?
;; Move into body of current footnote.
;; fix? error if not looking-at?
(if (looking-at (concat lb-re-footnote-start
_-re-footnote-marker-global))
(goto-char (match-end 0)))
;; 2006.09.04
(setq lb-pt-page-end (lb-tx-page-point "page-end"))
(if (>= (point) lb-pt-page-end)
;; Could be at %%div-class-notes-start%% !
;; 2008.04.26 - oh, really?
;; 2008.05.13 - yes, really.
;;
;; (error "%s: %s" "Wrong side of point"
;; (concat "\n" (_-buffer-substring-from-))))
(setq lb-rc (point))
(if (search-forward-regexp (concat lb-re-footnote-start
_-re-footnote-marker-global)
lb-pt-page-end t)
;; Easy case: there's another footnote on this page.
(setq lb-rc (match-beginning 0))
;; When no other footnote, return end of page contents.
(setq lb-rc
(lb-tx-page-point "page-end-without-number"
;; 2007.06.20 - "__PRINTERS_"
"__\\(PRINTERS\\|PPPARAGRAPH\\)_"
)
)))
;; Does this footnote continue on next page?
;; __NOTE__ may be before a __PRINTERS_P_999_COMMENT__ !
(if (null lb-rc) (error "%s: %s" "lb-rc is null"
(_-buffer-substring-from-)))
(goto-char lb-rc)
(lb-tx-para-move-back-and-skipover-re- nil)
(setq lb-rc
(cons lb-rc
(if (looking-at lb-re-footnote-continued)
(if (not (string=
;; "on" - 2008.04.26
"on"
(setq lb-str (match-string-no-properties 2))))
(error "%s: %s"
(concat "Got '" lb-str "'"
" but expecting 'on' variation of"
lb-re-footnote-continued)
(_-buffer-substring-from-))
(match-string-no-properties 3)))))))
lb-rc))
;; (lb-tx-goto-page 12)
(defun lb-tx-goto-page (arg1pg &optional arg2flag-insert)
"Move to page ARG1 (string or integer) and return integer ARG1 if
successful.
Optional ARG2, if non-nil, inserts page ARG1 if highest existing
page number is (1- ARG1). If not, an error occurs"
;;
(let (lb-re lb-str lb-current-page lb-pt-moved
lb-rc)
(if (stringp arg1pg) (setq arg1pg (string-to-int arg1pg)))
(save-match-data
(goto-char (point-min))
(progn
(string-match "[[]0[-]9[]][+]" lb-re-bracketed-para-integer)
(setq lb-re (replace-match (int-to-string arg1pg) nil nil
lb-re-bracketed-para-integer)))
;; Have page already?
(if (search-forward-regexp lb-re nil t)
(progn ;; Found a page number paragraph (not at top of buffer).
(if (string= "bottom" _-where-page-numbers)
(goto-char (match-beginning 0))
(goto-char (match-end 0)))
;;(goto-char (lb-tx-page-point "page-beg"))
(setq lb-rc arg1pg))
;; Not found, but could be at top of buffer.
(_-move-forward-whitespace)
(if (and (string-match lb-re-bracketed-integer-anchored
(setq lb-str (car (_-para))))
(= arg1pg (string-to-int
(match-string-no-properties 1 lb-str))))
(progn ;; Page number is at top of file.
(end-of-line)
(_-move-forward-whitespace)
(setq lb-rc arg1pg))
;; Did not find page ANYWHERE.
(when arg2flag-insert
;;; ;; 2006.10.02
;;; ;; Not returning nil if page not found.
;;; ;; Return nil if page not found!
;;;
;;; (error "%s: %s" "Did not find page"
;;; (concat lb-re
;;; "\n" (_-buffer-substring-from-)))
;; Add page.
;; If preceding page does not exist, ERROR.
(if (not (lb-tx-goto-page (1- arg1pg)))
(error "%s: %s"
(concat "Trying to insert page "
(int-to-string arg1pg))
(concat "did not find page "
(int-to-string (1- arg1pg)))))
;; Move to end of preceding page.
(goto-char (lb-tx-page-point "page-end"))
(if (string= "bottom" _-where-page-numbers)
;; Insert page when page numbers at top.
(insert "\n\n~\n\n"
(int-to-string arg1pg)
"\n\n")
(if (string= "top" _-where-page-numbers)
;; Insert page when page numbers at bottom.
(insert "\n\n"
(int-to-string arg1pg)
"\n\n~\n\n")
(error "%s" "%s")))
;;
(search-backward "~")
(setq lb-rc arg1pg)
) ;; Done adding page
)
)
;; 2006.10.02
;; (setq lb-rc arg1pg)
) lb-rc))
;; (lb-tx-check-page-numbers-editing)
(defun lb-tx-check-page-numbers-editing nil
"
Check page numbers if point is at least 95% into buffer"
;;
(if (> (* 100 (/ (+ 0.0 (point)) (point-max))) 94.999)
(lb-tx-check-page-numbers)))
;; (lb-tx-check-page-numbers)
(defun lb-tx-check-page-numbers (&optional arg1pf)
""
;;
(interactive "p")
(let (lb-n lb-re lb-n-lag lb-n-str lb-n-str-lag
_while-loop-init-flag
_while-loop-re
lb-pt-while-search lb-pt-while-search-lag
lb-rc)
;; fix! 2007.11.08 - a. look for "0" .. error.
;; fix! 2007.11.08 - b. look for "1"
;; fix! 2007.11.08 - c1. search backward for non-roman numeral pg#.
;; fix! 2007.11.08 - c2. search forward for roman numeral pg#.
;; fix! 2007.11.08 - d1. search backward and check roman numeral pg#.
;; fix! 2007.11.08 - d2. search forward and check non-roman numeral pg#.
(save-match-data
(save-excursion
(_-compress-multiple-newlines)
;; Check page number at top or bottom.
(cond
((string= "top" _-where-page-numbers)
(goto-char (point-min))
(setq _while-loop-re lb-re-bracketed-para-integer-top-of-file))
;;
((string= "bottom" _-where-page-numbers)
(goto-char (point-max))
(_-move-backward-whitespace t)
(goto-char (car (cdr (_-para))))
(_-move-backward-whitespace nil)
(setq _while-loop-re lb-re-bracketed-para-integer)))
;;
(if (not (looking-at _while-loop-re))
(error "%s: %s" (concat "Expected PG# at "
_-where-page-numbers "-of-file")
(_-buffer-substring-from-)))
(goto-char (point-min))
(while
(and ;; while
;; Tricky! Two page numbers adjacent to one another.
(progn (_-move-backward-whitespace) t)
;;; "/home/ysverdlov/leninist.biz/en/1972/LBI363/20060307/299.tx"
;;; ~^^1^^ The Road to Communism, Moscow, 1961, pp. 501--02.