;;; Emacs-Time-stamp: "2007-11-16 19:33:26" ;;; Emacs-File-stamp: "/home/ysverdlov/leninist.biz/lia-tx.el" (if (not (boundp 'my-1stletter+lastname)) "foobar" my-1stletter+lastname) (defvar t2h-data-ext "tx" "File extension for hybrid raw-data files") (defvar t2h-regexp-sgml-name (concat "\\([0-9][0-9][0-9][0-9]\\)" "[-]" "\\(.*\\)" "[-]" "\\([^-]+\\)$") "*Regexp that matches name= value from SGML TOC") (defvar t2h-regexp-textfile-filename (concat "\\([0-9][0-9][0-9]\\)" "\\(h?[-]\\)" "\\([0-9][0-9][0-9]\\)" "[.]" t2h-data-ext "$") "*Regexp that matches filename of a textfile; 'h' means from HTML") (defvar t2h-regexp-src "v[0-9][0-9][a-z][a-z][0-9][0-9]h?[:]?[:]?x?t?p?9?7?" "*Regexp that matches a source's volume, publisher and year") ;;; lb-defvar: (defvar t2h-regexp-textfile ;;; lb-defvar: (defvar t2h-regexp-vpst (unless (featurep '_) (load-file "~/leninist.biz/_.el")) (unless (featurep 'lb-defvar) (load-file "~/leninist.biz/lb-defvar.el")) ;;; ############################################ ;; Copied here from abbycln.el (2005.10.10) (set-register ?p "
\n\n\n") (set-register ?\[ "") (set-register ?\] "") ;;; ############################################ ;; Moved here from lia.el (2005.10.10) (defvar t2h-format-time-string "%Y-%m-%dT%T%z" "For example, to produce full ISO 8601 format, use \"%Y-%m-%dT%T%z\"") (defvar t2h-format-time-string-spelled-out "%B %e, %Y" "See .updat in lenin/css/works.css") (defvar t2h-regexp-separator-para (concat "[\n]" "\\([ \t]*[\n]\\)+") "*Regexp that separates paragraphs (newline at beginning and end)") (defvar t2h-regexp-number-as-paragraph (concat t2h-regexp-separator-para "\\([0-9]+\\)" t2h-regexp-separator-para) "*Regexp that finds a paragraph that has only one word: a number") (defun _-tx-grab-volume-__-titles nil "Interactive function to grab __TITLE__s for a volume when in dired mode, e.g, ~/www.marxists.org/archive/lenin/works/cw/v25zz99h/ SEE: _-sgml-grab-volume-anchor-titles" (interactive) (let (_-dir _-bfn _-file _-supratitle _-rc) (if (not (string= "dired-mode" major-mode)) (message "%s: %s" "Use this function in" "dired-mode") ;; Get directory. (save-excursion (goto-char (point-min)) (if (looking-at "[ \t]+") (goto-char (match-end 0))) (setq _-dir (buffer-substring-no-properties (point) (save-excursion (end-of-line) (1- (point))))) (setq _-dir (concat _-dir "/"))) ;; Get directory listing. (find-file (with-temp-file (setq _-bfn (concat temporary-file-directory (make-temp-name "t2h-"))) (loop for file in (directory-files _-dir nil ;; fix? how about .txq files? "[.]tx$" nil) do (insert file) (newline 1)) (sort-lines nil (point-min) (point-max)) (write-region (point-min) (point-max) _-bfn) _-bfn)) ;; Replace with __TITLE__ data (progn (goto-char (point-min)) (while (search-forward-regexp "\\([^\n]+\\)[\n]" nil t) (setq _-file (match-string-no-properties 1)) (replace-match (with-temp-buffer (save-match-data ;; Delete everything except __TITLE__ data. (progn (insert-file-contents-literally (concat _-dir _-file)) (setq _-pt0 (goto-char (point-min))) (while (search-forward "__TITLE__" nil t) ;; SUPRATITLE. (setq _-supratitle (save-match-data (save-excursion (search-backward-regexp "[\n][ \t\r]*[\n]") (goto-char (car (_-where-double-newlines))) (if (looking-at "__SUPRATITLE__") (car (_-para t t t)))))) (delete-region _-pt0 (match-end 0)) ;; Delete "*" before some titles in Volume 45. (if (looking-at "[ \t\n\r]*\\([*]\\)") (replace-match "" nil nil nil 1)) (if _-supratitle (insert _-supratitle ". ")) (setq _-pt0 (search-forward-regexp "[\n][ \t\r]*[\n]"))) ;; If not found, delete EVERYTHING. (delete-region _-pt0 (point-max))) ;; Delete endnotes. (progn (goto-char (point-min)) (while (search-forward-regexp "[\\^][\\^][0-9]+[\\^][\\^]" nil t) (replace-match ""))) ;; Delete footnotes. (progn (goto-char (point-min)) (while (search-forward-regexp "//[^/]+//" nil t) (replace-match "") (setq _-pt0 (point)) (search-forward-regexp "[\\][\\][^\\]+[\\][\\]" nil t) (delete-region _-pt0 (match-end 0)))) ;; Replace blank lines. (progn (goto-char (point-min)) (while (search-forward-regexp "[\n][ \t\n\r]*[\n]" nil t) (replace-match "qerlh198347hf984982"))) ;; Replace newlines. (progn (goto-char (point-min)) (while (search-forward-regexp "[ \t\r]*[\n][ \t\r]*" nil t) (replace-match " "))) ;; Insert newlines. (progn (goto-char (point-min)) (while (search-forward "qerlh198347hf984982" nil t) (replace-match "\n"))) ;; Delete leading spaces. (progn (goto-char (point-min)) (while (search-forward-regexp "^[ \t\r]+" nil t) (replace-match ""))) ;; Delete trailing spaces. (progn (goto-char (point-min)) (while (search-forward-regexp "[ \t\r]$" nil t) (replace-match ""))) ;; Compress spaces. (progn (goto-char (point-min)) (while (search-forward-regexp "[ \t\r][ \t\r]+" nil t) (replace-match " "))) ;; Insert file name. (progn (goto-char (point-min)) (while (and (< (point) (point-max)) (search-forward-regexp "$" nil t)) (insert "\t" _-file) (forward-char 1))) (buffer-string))))))) _-rc)) (global-set-key [f2 f4] 'tx-editing-merge-closing-paragraphs) (defun tx-editing-merge-closing-paragraphs (arg1p) "" (interactive "p") (let (tx-pt0 tx-pt1 tx-cons tx-re tx-rc) (if (_-blank-line-p) (tx-editing-compress-here-multiple-newlines)) ;; 2007.03.21 (if (and (_-blank-line-p) (save-excursion (looking-at-backward-become-forward (concat "
" _-whitespace-wM "*"))) (not (looking-at (concat _-whitespace-noM "*" "")))) (insert "
")) (if (_-blank-line-p) (_-delete-line)) ;; 2007.03.21 (progn (setq tx-cons (_-where-double-newlines)) (if (not (sbr (setq tx-re "
") (car tx-cons))) (error "%s: %s" "Paragraph missing (backward)" tx-re)) (if (not (sfr (setq tx-re "" (car (_-where-double-newlines))) (_-move-backward-whitespace t) (if (looking-at (concat "\\([ \t]*[\r]\\)?" "[ \t]*
" "\\([ \t]*[\r]\\)?")) (replace-match (concat (if (null (match-string-no-properties 1)) (match-string-no-properties 2) (match-string-no-properties 1)))))) (progn (sfr ";;
;;
(while (and (goto-char tx-pt1) (looking-at (concat ">" _-whitespace-wM "*" "\\(" "
" _-whitespace-wM "*" "" _-whitespace-wM "*" "\\)+" ))) (replace-match "" t t nil 1)) ;; (if (not (looking-at ">")) (error "%s: %s" "Expecting" "
")
(search-forward ">") (delete-region tx-pt0 (point))))
(if (_-blank-line-p) (_-delete-line))
;; 2007.02.24
(when (looking-at-backward-become-forward "[-][ \t]+[\r][\n]")
(lb-abbyycln-join-a-hyphen-control-M)
(end-of-line)
(forward-char 1))
(insert "
")
(forward-word 1)
(recenter)
tx-rc))
(defun t2h-save-buffer-control-M nil
"Stick this into a keyboard macro to align paragraphs on ^M."
;;
(interactive "*")
(let (t2h-cons
t2h-rc)
(progn (set-buffer-modified-p t)
(t2h-fill-paragraph-control-M)
(bsb))
;; (goto-char (cdr (_-where-double-newlines)))
;; Skip over certain paragraphs BEFORE moving forward.
(when (looking-at lia-re-para-vpst) ;; ASSUMES two newlines before VPST.
(sfr _-^whitespace-wM)
(t2h-save-buffer-control-M)) ;; recursive
;; Move forward
(if (sfr "[^ \t\n\r]" nil t)
(goto-char (car (_-where-double-newlines)))
(end-of-buffer)
(occur "\\(&\\|\"\\| -\\|- \\)")
)
;; Skip over certain paragraphs AFTER moving forward.
(if (looking-at (concat "__" "\\("
"TRANSMARKUP"
"\\|" "TEXTFILE_BORN"
"\\|" "TITLE"
"\\)" "__"))
(t2h-save-buffer-control-M))
(if (looking-at (concat "
. ;; If blank line, try moving forward. (if (_-blank-line-p) (sfr "[^ \t\n\r]" nil t)) ;; If still blank line, at end of buffer by definition. (when (_-blank-line-p) (setq t2h-started-at-end-of-buffer t) (sbr "[^ \t\n\r]" nil t)) (goto-char (car (_-where-double-newlines)))) ;; When paragraph has a ^M... (when (and ;; (buffer-modified-p) (progn (setq t2h-newlines (_-where-double-newlines)) (goto-char (car t2h-newlines)) t) (save-excursion (search-forward-regexp "[\r]" (cdr t2h-newlines) t)) (progn (goto-char (car t2h-newlines)) (_-move-backward-whitespace) (setq t2h-pt0-original (point)) (goto-char (cdr t2h-newlines)) (_-move-forward-whitespace) (setq t2h-pt1-original (point)) (goto-char (car t2h-newlines)) (setq t2h-str0-original (buffer-substring-no-properties t2h-pt0-original t2h-pt1-original)))) (with-temp-buffer (insert t2h-str0-original) (goto-char (point-min)) (search-forward-regexp _-^whitespace-wM) (progn ;; Delete whitespace between ^M (or =) and newline (goto-char (cdr (setq t2h-newlines (_-where-double-newlines)))) (when t2h-fpcm-debug (setq t2h-fpcm-str (concat "DELETE WHITESPACE @ END OF LINE")) (message "%s" (concat (current-time-string) " " t2h-fpcm-str))) (while (search-backward-regexp (concat "[\r=]" "\\([-][0-9]+\\|[-]sic\\)?" ;1 "\\([ \t]+\\)" ;2 "\n" ) (car t2h-newlines) t) (replace-match "" t t nil 2))) (progn ;; Delete newlines, or change to space. (goto-char (cdr (setq t2h-newlines (_-where-double-newlines)))) (when t2h-fpcm-debug (setq t2h-fpcm-str (concat "DELETE NEWLINES, OR CHANGE TO SPACE")) (message "%s" (concat (current-time-string) " " t2h-fpcm-str))) (while (search-backward-regexp (concat ;; 2006.05.10 "[^\r \t=]" "\\([ \t]*\\)" ;1 "\\([\n]\\)" ;2 "\\([ \t]*\\)" ;3 ) (car t2h-newlines) t) (replace-match (if (or (> (length (match-string-no-properties 1)) 0) (> (length (match-string-no-properties 3)) 0)) "" " ") nil nil nil 2))) (progn ;; Insert newlines after "^M". (progn (setq t2h-newlines (_-where-double-newlines)) (setq t2h-pt0 (1- (goto-char (cdr t2h-newlines))))) (when t2h-fpcm-debug (setq t2h-fpcm-str (concat "INSERT NEWLINES AFTER ^M")) (message "%s" (concat (current-time-string) " " t2h-fpcm-str))) (while (search-backward-regexp ;; 2007.04.05 ;; "\r" ;; t2h-re-MN tx-re-fill-paragraph (car t2h-newlines) t) (setq t2h-pt0 (point)) (forward-char 1) (if (looking-at "[-][0-9]+") (goto-char (match-end 0))) (if (looking-at "[-]sic") (goto-char (match-end 0))) (insert "\n") (if (looking-at "[ \t]+") (replace-match "")) (goto-char t2h-pt0))) (progn ;; Untabify. (progn ;; Compress multiple spaces/tabs before untabify. (when t2h-fpcm-debug (setq t2h-fpcm-str (concat "COMPRESS MULTIPLE SPACES")) (message "%s" (concat (current-time-string) " " t2h-fpcm-str))) ;; 2007.01.10 ;; (cms) (setq t2h-newlines (_-where-double-newlines)) (_-compress-multiple-spaces (car t2h-newlines) (cdr t2h-newlines))) (progn ;; Untabify. (setq t2h-newlines (_-where-double-newlines)) (when t2h-fpcm-debug (setq t2h-fpcm-str (concat "UNTABIFY")) (message "%s" (concat (current-time-string) " " t2h-fpcm-str))) (untabify (car t2h-newlines) (cdr t2h-newlines)))) (progn ;; Include first tag? ;; If yes, insert blank line to separate, delete at end. (goto-char (car (setq t2h-newlines (_-where-double-newlines)))) (if (and (looking-at "[ \t]*<[a-zA-Z]") (search-forward ">") (looking-at "[ \t\n\r]+") (setq t2h-exclude-1st-tag t)) (replace-match "\n\n"))) (progn ;; Include word with "//*//"? ;; It is usually preceded by "[space]=[newline][newline]". ;; If yes, insert blank line to separate, delete at end. (goto-char (car (setq t2h-newlines (_-where-double-newlines)))) (if (and (not t2h-exclude-1st-tag) (looking-at (concat "[^ \t\n\r]+//" ;; fix! ;; Use _-re-footnote-marker-global "[*]+" "\\(//\\)")) (setq t2h-exclude-1st-tag t)) (replace-match "//\n\n" nil nil nil 1))) (progn ;; Include __FOO__? (goto-char (car (setq t2h-newlines (_-where-double-newlines)))) (if (and (not t2h-exclude-1st-tag) (looking-at (concat t2h-regexp-__ "\\([ \t\n\r]+\\)")) (setq t2h-exclude-1st-tag t)) (replace-match "\n\n" nil nil nil 2))) (progn ;; If
is only thing after last ^M, move it. ;; Move to end of paragraph. (goto-char (cdr (setq t2h-newlines (_-where-double-newlines)))) (when (and ;; Is last character ">"? (and (search-backward-regexp _-^whitespace-wM nil ;; OK t) (looking-at ">")) ;; Is this tag ? (and (search-backward-regexp "[<]" nil ;; OK t) (looking-at "")) ;; Is previous character ^M? (and (search-backward-regexp _-^whitespace-noM nil ;; OK t) (looking-at "\r")) ;; Backup over whitespace (including ^M) to append . (_-move-backward-whitespace t)) (delete-region (point) (cdr t2h-newlines)) (insert " "))) (progn ;; Fill. (progn ;; Measure longest line, up to (not including) ^M. (progn (setq t2h-newlines (_-where-double-newlines)) (setq t2h-pt0 (goto-char (car t2h-newlines))) ;; 2007.04.05 ;; fix? why optional trailing whitespace? (setq t2h-regexp "[ \t\r]*$") ) (when t2h-fpcm-debug (setq t2h-fpcm-str (concat "MEASURE LONGEST LINE")) (message "%s" (concat (current-time-string) " " t2h-fpcm-str))) (while (search-forward-regexp (concat ;; 2006.05.19 "[\r]" t2h-regexp) (cdr t2h-newlines) t) (if (> (setq t2h-longest-new ;; 2006.05.19 (1- (- (point) t2h-pt0)) (- (match-beginning 0) t2h-pt0)) t2h-longest) (setq t2h-longest t2h-longest-new)) (progn (end-of-line) ;; Break-out when point at end of paragraph: (if (= (point) (cdr t2h-newlines)) (setq t2h-regexp "oilkaoiq;kfklqo;lkasdlasj") (if (< (point) (cdr t2h-newlines)) ;; goto next line. (forward-char 1)))) (setq t2h-pt0 (point))) ;; (setq t2h-longest (+ t2h-longest t2h-grow-padding))) (progn ;; Lengthen short lines. (progn (setq t2h-newlines (_-where-double-newlines)) ;redun (setq t2h-pt0 (goto-char (cdr t2h-newlines)))) (when t2h-fpcm-debug (setq t2h-fpcm-str (concat "LENGTHEN SHORT LINES")) (message "%s" (concat (current-time-string) " " t2h-fpcm-str))) (while (search-backward-regexp ;; 2007.04.05 ;; "[\r]" ;; t2h-re-MN tx-re-fill-paragraph (car t2h-newlines) t) (setq t2h-pt0 (point)) (save-excursion (beginning-of-line) (setq t2h-pt1 (point))) ;; Too short. No such thing as "too long". (if (< 0 (setq t2h-increment (- (min t2h-longest t2h-longest-max) (- t2h-pt0 t2h-pt1)))) (insert (substring t2h-spaces 0 t2h-increment)) ) (beginning-of-line))) ) ;; end Fill. (progn ;; Delete blank line above if something separated during fill. (if (and t2h-exclude-1st-tag (goto-char (car (_-where-double-newlines))) (search-backward-regexp "[^ \t\n\r]" nil t) (progn (forward-char 1) t) (looking-at "\n\n+")) (replace-match "\n"))) (setq t2h-str1-original (buffer-string))) ;; DO IT! (progn (goto-char t2h-pt0-original) (delete-region t2h-pt0-original t2h-pt1-original) (insert t2h-str1-original) (goto-char t2h-pt0-original) (_-move-forward-whitespace)) (progn (_-compress-multiple-newlines) (recenter (+ t2h-user-recenter-from-top (count-lines (save-excursion (goto-char (car (_-where-double-newlines)))) (point)))) ;; (search-forward-regexp "[^ \t\n\r]" nil t) ;; (jump-to-register 't2h-fpc-control-M) ;; (save-buffer 0) ;; (not-modified) )) (if t2h-started-at-end-of-buffer (end-of-buffer)) ) t2h-rc)) ;; (local-set-key [f2 f6] 't2h-fill-paragraph-control-M-buffer) (defun t2h-fill-paragraph-control-M-buffer (args) "" ;; (interactive "p") (let (my (t2h-ptr (point-to-register 't2h-fpc-control-M-buffer))) (goto-char (point-min)) (while (search-forward-regexp "[\r]" nil t) (forward-char -1) (t2h-fill-paragraph-control-M) (goto-char (cdr (_-where-double-newlines)))) ;; fix? just return to nearest blank line? ;; ;;(jump-to-register 't2h-fpc-control-M-buffer) ;; (goto-char (point-max)) ;; DO: 4 lines matching "\\(&\\|\"\\| -\\|- \\)" in buffer 025h-502.tx. (t2h-save-buffer-control-M) )) (defun _-get-buffer-points (arg1n) "Returns pair of buffer points from current point and ARG1 points to the right if ARG1 is positive; to the left if ARG1 is negative" ;; (let ( _rc) (progn (if (= 0 arg1n) (error "%s: %s" "This argument is nonsense" (int-to-string arg1n))) (setq _cons (cons (setq _pt-left (if (> arg1n 0) (point) (if (>= (setq _pt (+ (point) arg1n)) (point-min)) _pt))) (setq _pt-right (if (< arg1n 0) ;; just switched ">" to "<" (point) (if (<= ;; just switched ">" to "<" (setq _pt (+ (point) arg1n)) (point-max)) ;; "min" to "max" _pt))) )) ;; Do not error check. (when nil (if (or (null (cdr _cons)) (null (car _cons))) (error "%s: %s" "Invalid pair of points" (prin1-to-string _cons)) (setq _rc _cons))) (setq _rc _cons) )_rc)) ;; fix! _-buffer-substring-no-properties ;; fix! _-buffer-substring ;; Optional ARG2 that lowers (or raises) ARG1 to point-max (or point-min). ;; (_-buffer-substring 10) ;; (_-buffer-substring -10) (defun _-buffer-substring (arg1n) "Smarter version of same function without '_-'" ;; (let ((_cons (_-get-buffer-points arg1n)) _rc) (save-match-data (setq _rc (buffer-substring (car _cons) (cdr _cons))) )_rc)) ;; (_-buffer-substring-no-properties 10) ;; (_-buffer-substring-no-properties -10) (defun _-buffer-substring-no-properties (arg1n) "Smarter version of same function without '_-'" ;; (let ((_cons (_-get-buffer-points arg1n)) _rc) (save-match-data (setq _rc (buffer-substring-no-properties (car _cons) (cdr _cons))) )_rc)) (defun kill-word-sgml-my (arg) "" (interactive "p") ;; (key-binding "\M-d" ) => kill-word ;; (key-binding [(meta d)] ) => kill-word (let ((_pt-orig (point)) _pt-del-to-left _pt-del-to-right _tag-contents _rc) ;; fix! 2007.07.12 ;; Use looking-at-backward-become-forward ;; instead of buffer-substring-no-properties ! ;; ;; Point (black box) is to *right* of character with "_" to its right. ;; Or, left edge of black box is "insertion pointer". ;; Character to *right* of "_" will be reverse-video. ;; ;; fix! in addition to, test !
;;
;; -------------------------------------------------------------------
;; ESC d: TEST HERE.
;; ESC d: _ =>
;; ESC d: <_p> =>
;; ESC d:
TEST HERE. ;; ESC d: _
=> < class="closing">
;; ESC d: <_p class="closing"> => < class="closing">
;; ESC d:
;; ESC d: => FIX?
;; ESC d: =>
;; ESC d: =>
;; ESC d: =>
;; ESC d: =>
;; ESC d: =>
;; ESC d: =>
;; ESC d: => " if point after name of open/close tag.
;;
;; Changed mind: do other one.
;; If outside markup, delete optional whitespace + tag.
(when (not (_-sgml-markup-p))
;;
(when (and (> arg 0)
(looking-at
(concat "" _-whitespace-wM "*" "<")))
(kill-region _pt-orig
(setq _pt-del-to-right (save-excursion (sfs ">")
(match-end 0))))
(setq _rc (- _pt-del-to-right _pt-orig)))
;;
(when (and (< arg 0)
(looking-at-backward
(concat ">" _-whitespace-wM "*" "")))
(kill-region _pt-orig
(setq _pt-del-to-left (save-excursion (sbs "<")
(match-beginning 0))))
(setq _rc (- _pt-del-to-left _pt-orig))))
;; If inside markup, ...
(when (and (_-sgml-markup-p)
(setq _tag-contents
(buffer-substring-no-properties
(save-excursion (sbs "<")
(1+ (setq _pt-del-to-left
(1- (match-end 0)))))
(save-excursion (sfs ">")
(1- (setq _pt-del-to-right
(1+ (match-beginning 0))))))))
(if (string-match "'" _tag-contents)
(error "%s: %s" "Found inside SGML tag" "'")
;; Backward delete and point near end of tag contents.
(if (and (< arg 0)
(looking-at (concat _-whitespace-wM "*" "/?"
_-whitespace-wM "*" ">")))
(setq _rc (_-sgml-del-tag))
;; Forward delete and point near beginning of tag contents.
(if (and (> arg 0)
(looking-at-backward (concat "<" _-whitespace-wM "*" "/?"
_-whitespace-wM "*" "")))
(setq _rc (_-sgml-del-tag))
;; No attributes.
(if (not (string-match "\"" _tag-contents))
(setq _rc (progn (goto-char _pt-del-to-left)
(kill-region _pt-del-to-left
_pt-del-to-right)
(- _pt-del-to-right _pt-del-to-left)))
;; Got attributes.
(when t
;; If point in middle of word, delete whole word.
(if (> arg 0) (skip-syntax-backward "w_"))
(if (< arg 0) (skip-syntax-forward "w_"))
;;
(if (> arg 0) (kill-word 1))
(if (< arg 0) (backward-kill-word 1))))))))
_rc))
(defun backward-kill-word-sgml-my (arg)
""
(interactive "p")
(let (
_rc)
;; 2007.06.19 - fix! - does not kill " ")
(insert "\n^^" (int-to-string (setq tx-n-note (1+ tx-n-note)))
"^^ "))
(t2h-fill-paragraph-control-M)
(goto-char (cdr (_-where-double-newlines)))
(_-move-forward-whitespace)
(recenter)
tx-rc))
(defun tx-merge-recto (arg1)
"Merge recto file 999-001.tx into current buffer (a verso) before
deleting recto file."
(interactive "p*")
(let (tx-pg tx-vol tx-pf tx-re
(tx-ht 30)
tx-rc)
(save-match-data
(save-excursion
(save-restriction
(goto-char (point-min))
(while (search-forward-regexp t2h-regexp-vpst nil t)
(if tx-pg
(error "%s: %s" "Expecting just one" (match-string 0)))
(setq tx-vol (match-string-no-properties 1))
(setq tx-pg (match-string-no-properties 2))
(if (string-match "[13579]$" tx-pg)
(error "%s: %s" "Must have just one" "even (verso) page"))
(setq tx-pf (buffer-file-name)))
(if (not
(string-match
(setq tx-re (concat "/"
(format "%03d" (string-to-int tx-vol))
"[h]?" ;; old HTML to .tx files.
"[-]"
"\\("
(format "%03d" (string-to-int tx-pg))
"\\)"
"h?"
".tx$"
))
tx-pf))
(error "%s: %s" tx-pf tx-re))
(if (not (file-exists-p
(setq tx-pf
(replace-match
(format "%03d" (1+ (string-to-int tx-pg)))
t t tx-pf 1))))
(error "%s: %s" "File not found" tx-pf))
(progn
(goto-char (setq tx-pt (point-max)))
(insert "\n\n")
(insert-file-contents-literally tx-pf)
(goto-char tx-pt)
(flush-lines "")
(progn (basic-save-buffer-1) (delete-file tx-pf))
)
(occur "pg=")
(if (< (window-height (selected-window)) tx-ht)
(shrink-window
(- 0 (- tx-ht (window-height (selected-window))))))
)))
(cmn) ;; compress-multiple-newlines
(ispell-buffer)
(delete-other-windows)
tx-rc))
;;; ############################################
;;; /usr/share/emacs/20.7/lisp/simple.el
;;; Missing "delete-blank-line" from simple.el !
;;; Why defalias? delete-blank-lines says:
;;; "On isolated blank line, delete that one."
;;; NOTE: Does not count ^M (\r) as whitespace.
(defalias 'delete-blank-line 'delete-blank-lines)
(provide 'lia-tx)
;;; ############################################
" with point after "r".
(save-match-data
(kill-word-sgml-my (- arg))
;; 2006.10.03
(save-excursion
(if (tx-editing-insert-_-_-_)
(setq _rc (point))))
(if _rc (goto-char _rc))
(recenter)
)_rc))
;;
;; fix! use "tx-" instead of "my-" and make interactive!
;;
(defun my-find-file-hooks-tx-kill-word nil
""
(let (_rc)
(when (string-match
(concat "[.]txq?\\([.]" my-1stletter+lastname "\\)?$")
(buffer-file-name))
;;
;; (key-binding "\M-\177" ) => backward-kill-word
;;2007.07.12 (local-set-key [(meta d)] 'kill-word-sgml-my)
;;2007.07.12 (local-set-key "\M-\177" 'backward-kill-word-sgml-my))
(local-set-key [f2 backspace] 'backward-kill-word-sgml-my)
;; 2006.12.15 - why did not think of this before?
(local-set-key [f2 ?d] 'kill-word-sgml-my) ;; E.g., M-d
;; fix: (local-set-key [f2 del] 'kill-word-sgml-my)
)
_rc))
;;; NO! 2007.07.12
;;;(add-hook 'find-file-hooks 'my-find-file-hooks-tx-kill-word)
(defun tx-find-file-hooks-sgml-mode (&optional arg1)
""
(interactive "p")
;; /usr/share/emacs/20.7/lisp/textmodes/sgml-mode.el
;; 2006.08.18
;; DO NOT DO THIS: Screws things up!
;; (load "sgml-mode") ;; Need: sgml-mode-common (for comment-start, -end).
;;
;; (sgml-mode-common sgml-tag-face-alist sgml-display-text)
(make-local-variable 'comment-start)
(make-local-variable 'comment-end)
(make-local-variable 'comment-indent-function)
(make-local-variable 'comment-start-skip)
(make-local-variable 'comment-indent-function) ;; duplicated!
(setq
comment-start ""
comment-indent-function 'sgml-comment-indent
;; This will allow existing comments within declarations to be
;; recognized.
comment-start-skip "--[ \t]*"
)
)
(add-hook 'find-file-hooks 'tx-find-file-hooks-sgml-mode)
;; (my-find-file-hooks-tx-font-lock)
(defun my-find-file-hooks-tx-font-lock (&optional arg1pf)
""
(if (string-match
(concat "[.]txq?\\([.]" my-1stletter+lastname "\\)?$")
(if arg1pf arg1pf (buffer-file-name)))
(progn (turn-on-font-lock)
;;
(if (member 'lb-db-fill-paragraph-non-interactive
local-write-file-hooks)
(remove-hook 'local-write-file-hooks
'lb-db-fill-paragraph-non-interactive))
;;
;; fix? will html-font-lock-keywords always be here?
(setq font-lock-keywords html-font-lock-keywords)
(font-lock-fontify-buffer))))
(add-hook 'find-file-hooks 'my-find-file-hooks-tx-font-lock)
(defun my-write-file-hooks-compress-multiple-newlines nil
""
(if (string-match
(concat "[.]txq?\\([.]" my-1stletter+lastname "\\)?$")
(buffer-file-name))
(add-hook 'local-write-file-hooks
'_-compress-multiple-newlines t)))
(add-hook 'find-file-hooks 'my-write-file-hooks-compress-multiple-newlines)
(defun my-write-file-hooks-fill-paragraph-control-M nil
""
(if (string-match
(concat "[.]tx[qt]?\\([.]" my-1stletter+lastname "\\)?$")
(buffer-file-name))
(add-hook 'local-write-file-hooks
't2h-fill-paragraph-control-M t)))
(add-hook 'find-file-hooks 'my-write-file-hooks-fill-paragraph-control-M)
(defun my-write-file-hooks-t2h-textfiles-born-stamp nil
""
(when (string-match
(concat "[.]txq?\\([.]" my-1stletter+lastname "\\)?$")
(buffer-file-name))
(add-hook 'local-write-file-hooks
't2h-insert-textfiles-born-stamp t)
(local-set-key [f2 ?w] 't2h-insert-__written__)
;; f2 s runs the command 2C-split
;; (local-set-key [f2 ?s] 't2h-insert-__supratitle__)
(local-set-key [f2 ?t] 't2h-insert-__title__)))
(add-hook 'find-file-hooks 'my-write-file-hooks-t2h-textfiles-born-stamp)
;;; ############################################
;; Moved here from tx2html.el
(defvar t2h-regexp-__
(concat "__" "\\([*:A-Z_0-9]+\\)" "__")
"*Regexp that matches __PLACE_HOLDER__") ;; lenin/howto/tx2html.el
(defun t2h-insert-textfiles-born-stamp () ;; UTIL?
""
(interactive) ;; (defun time-stamp
(let (t2h-point-beg
t2h-rc)
(save-excursion
(goto-char (point-min))
(while (search-forward "__TITLE__" nil t)
(search-forward-regexp t2h-regexp-separator-para)
(setq t2h-point-beg (match-beginning 0))
(unless (looking-at "__TEXTFILE_BORN__")
(progn (goto-char t2h-point-beg)
(search-forward-regexp t2h-regexp-separator-para))
(replace-match
(concat "\n\n"
"__TEXTFILE_BORN__ "
(format-time-string t2h-format-time-string) "\n\n\n"
"__TRANSMARKUP__ \""
(if (or
(string= my-lastname user-real-login-name)
(string= my-1stletter+lastname user-real-login-name))
;; (concat "R. " my-Lastname)
(concat "Y. Sverdlov")
"Foo Bar")
"\"\n\n\n")))))
(cmn)
t2h-rc))
(defun _-tex2html (&optional arg1tx2something) ;; UTIL?
"Change TeX stuff to HTML stuff
- if optional ARG1 is non-nil, runs _-tx2something
- _-tex2html_entities
- modifies Tex \\null and \\thinspace
- deletes {}
- changes '\\ ' to ' '
- changes '\%' to '%'
- changes '$...$'
"
;; ~wget/www.tug.org/ftp/tex/impatient/book.pdf
;; Finished through page: 30. 2004.05.14.
;; Do NOT write a function to convert -ultimate-html2tex to compensate
;; for laziness... although make exceptions for special characters like
;; '$\{$'. pp. 15
(let (t2h-letx string point _msnp2)
;; 2006.02.14: Turn off by default, to retain ^M line ends.
(if arg1tx2something (_-tx2something))
;;
(_-tex2html_entities)
;; fix! \thinspace
;; GROUPS. Example, {\bf bold face} pp. 15
;; xyz
;; fix!
;; Do these last.
;;
;; CONTROL SYMBOLS. pp. 10-11.
(goto-char (point-min))
;;
;; CONTROL WORDS. pp. 10-11.
(goto-char (point-max))
(while (search-backward-regexp
"\\([\\]null\\|[\\]thinspace\\)[^a-z]" nil t)
(replace-match "~" t t nil 1)
(if (looking-at (concat "\\({}\\|"
;; 2006.12.14 - what is "[ \n]+" about?
;; "[ \n]+"
;; 2006.12.14 - just do {} again.
"{}"
"\\)"))
(replace-match "")))
;;
;; "OTHER".
(goto-char (point-min))
(while (search-forward "{}" nil t)
(replace-match ""))
(goto-char (point-min))
(while (search-forward "[\\] " nil t)
(replace-match " "))
;;
;; SPECIAL CHARACTERS. pp. 15
;; $ $$$$$$$$$ NOT EXPECTING ANY DOLLAR SIGNS$$$ IN CHARACTER DATA:
;; $$$$$$$$$ find . -follow -name '*.tx' | xargs -i egrep -Hi '\$' '{}' | grep
;; '^..v[0-9]' | awk '{sub(/\$[\\][}{]\$/, "}}}}{{{{") ; print;}' | grep
;; '[$]' | less
;; # ######### only volume 13 has "'" from OCR converted to "’";
;; #########
;; & &&&&&&&&& &&&&&&&&&
;; % %%%%%%%%%
(goto-char (point-min))
(while (search-forward "\\%" nil t)
(replace-match "%"))
;; _ --------- NOT EXPECTING ANY UNDERSCORES IN CHARACTER DATA:
;; --------- find . -follow -name '*.tx' | grep '^..v[0-9]' | xargs -i egrep
;; -Hi '_' '{}' | awk '{sub(/__[a-zA-Z_*0-9]+__/, "") ; print;}' | grep
;; '_' | sort | less
;; "For the others, you need something more elaborate:"
;; "^" should not occur (see: t2h-text-while-body-endnotes-anchor).
;; "~" is "i dunno" from OCR output (see error in _-find-file).
;; "{" "}"
(goto-char (point-min))
(while (search-forward-regexp "[$][\\]\\([}{]\\)[$]" nil t)
(replace-match (match-string 1)))
;; "\"
(goto-char (point-min))
(while (search-forward-regexp "[$][\\]backslash[$]" nil t)
(replace-match "\\\\"))
nil))
(defun _-tex2html_entities nil ;; UTIL
";; fix! This defun should share strings with
_-html_entities-to-tex ... which does not exist 2007.07.06!!!"
;; fix!
;; fix!
;; fix!
;; fix!
;; fix!
;; fix!
;; fix!
;; fix!
;; fix!
;; fix!
;; fix!
;; fix!
;; fix!
;; fix!
;; fix!
;; fix!
;; How is this different from _.el: _-tex2sgml
(let (t2h-letx
(t2h-pt-close-head 0)
)
;; 2006.11.27 - If HTML, only make changes if after open BODY tag.
(goto-char (point-min))
(if (and (search-forward "