;; PMM = POOR MAN'S MARKUP ;; Emacs-Time-stamp: "2007-11-10 19:58:34" (setq file-stamp "Emacs-File-stamp: \"/home/ysverdlov/leninist.biz/lb-pmm.el\"") ;; (defun lb-pmm-transform-shadow-copies-go-lower-than-global-minimum (re &optional flag) "Easy" (let (_rc) (if (looking-at "[ \t]+") ;; 1 of 2. (if flag (replace-match "") (goto-char (match-end 0)))) (when (looking-at "[0-9]+") (setq _rc (string-to-int (match-string-no-properties 0))) (if flag (replace-match "") (goto-char (match-end 0)))) (if (looking-at "[ \t]+") ;; 2 of 2. (if flag (replace-match "") (goto-char (match-end 0)))) (if (not (looking-at re)) (error "%s: %s" "Expecting looking-at" re)) _rc)) ;; (defun lb-pmm-transform-shadow-copies-looking-at (find str re &optional del) "Check for ##{{## or ##}}##, maybe deleting it. If ARG1 is non-nil, search-forward-string '##' and error if not found when regexp ARG3 does not have a '('. If it does have a '(' just return nil to prevent the ball from rolling. ARG2, if non-nil, is a string to check after using regexp ARG3. If ARG4 is non-nil, delete stuff" ;; (let (_pt0 _pt1 flag _rc) (if (null str) (setq str "")) (when (or (not find) ;; Should be looking at one! (and ;; ;; That's interesting. ;; "Build" .tx files: check for words. ;; "Build" .tx files: then, check remaining stuff for... numbers. ;; "Build" .tx files: then, check remaining stuff for... STUFF. ;; "Build" .tx files: then, ... in other words, tokenize .tx and check! ;; If a token begins with "##" it should match lb-re-both-shadow! (when (search-forward-string "##" nil ;;;;;;;;;;t ;; If re is plain (no choice), ;; - FIRST INVOCATION found one. ;; - must find one, so return nil here. (if (string-match "[|]" re) t)) (goto-char (match-beginning 0)) t))) (if (not (looking-at re)) (error "%s: %s" "Expecting looking-at" re) (if (and (not (string= "" str)) (not (string= str (match-string-no-properties 1)))) (error "%s: %s" "Expecting" str) (setq _rc (cons (match-beginning 0) (match-end 0))) (if del (replace-match "") ;; After FIRST INVOCATION will goto-char (car _rc)! (goto-char (match-end 0)))))) _rc)) ;; HELPER. (defun lb-pmm-transform-shadow-copies-get (&optional arg1-t-or-cons) "Returns a list for FIRST and SECOND INVOCATION: nth 0 = beg of ##{{## or ##}}## nth 1 = end of '' '' FIRST INVOCATION: ARG1 't' Find a pair (usually under __ALPHA_LVL9__). Point moved to beginning of ##{{## ##}}## or, Point moved to beginning of ##{{## 123 ##}}## SECOND INVOCATION: ARG1 nil Find next pair (usually in first paragraph). Point *NOT* moved. THIRD INVOCATION: ARG1 is what was returned by SECOND INVOCATION. Cut-n-paste. " ;; (let (lb-pt0-here lb-pt1-here lb-pt0-there lb-pt1-there lb-str-there lb-err0 lb-err1 (lb-pt-orig (point)) ;; WARNING - 2006.12.08 - do *NOT* remove '|' from ;; next one, it serves as a flag! (lb-re-both-shadow "##\\({{\\|}}\\)##") ;; WARNING - 2006.12.08 - do *NOT* use '|' in next two: (lb-re-beg-shadow (concat "##" "\\({{\\)" "##")) (lb-re-end-shadow (concat "##" "\\(}}\\)" "##")) (lb-str-beg-shadow (concat "##" "{{" "##")) (lb-str-end-shadow (concat "##" "}}" "##")) lb-acceptable-minimum lb-str lb-len _rc) ;; FIRST INVOCATION. (when (and arg1-t-or-cons (not (listp arg1-t-or-cons))) ;; Check regexp! ;; All '##' should be involved in this tragedy unless otherwise. ;; The following '^##' is the '##' in (occur "search.*##") (if (or (not (string-match "^##" lb-re-both-shadow)) (not (string-match "^##" lb-re-beg-shadow)) (not (string-match "^##" lb-re-end-shadow))) (error "%s: %s" "For some funny reason" (concat "Expecting '##' at start of all" "lb-*-*-shadow"))) ;; Not expecting to be looking-at "##" (if (looking-at "##" ;;;;;;;;;;lb-re-both-shadow) ) (error "%s: %s" (concat "First invocation?" " When non-nil + looking-at" lb-re-both-shadow) "ARG1 should be a cons of points")) (setq _rc (lb-pmm-transform-shadow-copies-looking-at ;; Please go looking for one. t ;; Do not check string, only check regexp. ;; String will be checked by next invocation. nil ;; The '|' in lb-re-both-shadow will cause search ARG3 2b 't'! lb-re-both-shadow ;; No delete: nil)) ) ;; 1ST ;; SECOND INVOCATION. (when (not arg1-t-or-cons) (save-excursion ;; 1 of 2 ... sorta. ;; ################################# ;; ##{{## - THIS ONE - ARG1 === nil (setq lb-pt0-here (car (lb-pmm-transform-shadow-copies-looking-at nil "{{" lb-re-beg-shadow nil))) ;; \\(123\\)? (setq lb-acceptable-minimum (lb-pmm-transform-shadow-copies-go-lower-than-global-minimum lb-re-end-shadow)) ;; ##}}## - THIS ONE (setq lb-pt1-here (cdr (lb-pmm-transform-shadow-copies-looking-at nil "}}" lb-re-end-shadow nil))) ;; ################################# ;; ##{{## - THATA ONE - ARG1 === t (setq lb-pt0-there (cdr (lb-pmm-transform-shadow-copies-looking-at t "{{" lb-re-beg-shadow nil))) ;; ##}}## - THATA ONE (setq lb-pt1-there (car (lb-pmm-transform-shadow-copies-looking-at t "}}" lb-re-end-shadow nil))) ;; 2007.11.10 (setq lb-str-there (buffer-substring-no-properties lb-pt0-there lb-pt1-there)) ;; Checks. Extent of first pair. (when (/= (- lb-pt1-here lb-pt0-here) ;; 13 if no lb-acceptable-minimum inbetween -beg- and -end-. (+ (length lb-str-beg-shadow) (length " ") (if (not lb-acceptable-minimum) 0 (+ (length " ") (length (int-to-string lb-acceptable-minimum)))) (length lb-str-end-shadow))) (setq lb-err0 "Should have a spc. or spc.integer.spc inbetween") (setq lb-err1 "##{{## ##}}##")) ;; Checks. Extent of second pair. (when (and ;; 2007.11.10 ;; ##{{##Dual Power.##}}## (not (string-match "[.]\\(\\)?$" lb-str-there)) (< (setq lb-len (- lb-pt1-there lb-pt0-there)) ;; 100 too small. ;; 150 too big. 150) (if (not lb-acceptable-minimum) t ;; Has to be exactly equal. Use M-= to measure length! (/= lb-len lb-acceptable-minimum))) (setq lb-err0 (concat "Second pair should be a full sentence" (if (not lb-acceptable-minimum) "" (concat "\n or " (int-to-string lb-len) " /= " (int-to-string lb-acceptable-minimum))))) (setq lb-err1 ;; "##{{## ##}}##" (concat " >>> " (buffer-substring-no-properties lb-pt0-there lb-pt1-there) " <<< "))) ;; Checks. Distance inbetween pairs. (when (> (- lb-pt0-there lb-pt1-here) ;; 300 ;; 550 ;; THE SOVIET UNION'S GREAT PATRIOTIC WAR 800 ;; Intervention Begins. Soviet Russia Becomes a ) (setq lb-err0 "Distance between pairs") (setq lb-err1 "IS A LOT")) ;; Checks. DONE. (when lb-err0 (if (file-exists-p lbg-text-indextx) (rename-file lbg-text-indextx "~/foo" t)) ;; Called within temp-buffer by lb-tx-make-or-refresh-indextx. ;; (lb-tx-delete-indexes) (error "%s: %s" (concat lb-err0 " (see ~/foo)") (concat lb-err1 (_-buffer-substring-from-)))) ;; Must always return a pair upon SECOND INVOCATION. (setq _rc (cons lb-pt0-there lb-pt1-there))) ) ;; 2ND ;; THIRD INVOCATION. (when (and arg1-t-or-cons ;; (not (listp arg1-t-or-cons)) (save-excursion ;; Good to go. Probably. (setq lb-str (buffer-substring-no-properties (car arg1-t-or-cons) (cdr arg1-t-or-cons))) ;; 2 of 2 ... sorta. ;; ################################# ;; ##{{## - THIS ONE - ARG1 === nil (setq lb-pt0-here (car (lb-pmm-transform-shadow-copies-looking-at nil "{{" lb-re-beg-shadow t))) ;; \\(123\\)? (setq lb-acceptable-minimum (lb-pmm-transform-shadow-copies-go-lower-than-global-minimum lb-re-end-shadow t)) ;; ##}}## - THIS ONE (setq lb-pt1-here (cdr (lb-pmm-transform-shadow-copies-looking-at nil "}}" lb-re-end-shadow t))) ;; ################################# (insert ;; ON-THE-FLY. (with-temp-buffer (insert lb-str) (goto-char (point-min)) ;; PAGE 21 in en/1981/1HU376/20051214/099.tx (while (search-forward-regexp lb-re-bracketed-para-integer nil t) ;; Do not delete blank line from this number that's part ;; of blank line of next number. PAGE 207: en/1981/1HU376 (replace-match "\n\n\n")) (goto-char (point-min)) (while (search-forward-regexp lb-re-__ nil t) (_-para-delete)) ;; fix! ;; This is the true length! Must do check here, now. ;; fix! ;; Ignore trailing white-space! A lot when ^M are right-justified! (buffer-string)) "\n") ;; ################################# ;; ##{{## - THATA ONE - ARG1 === t (setq lb-pt0-there (car (lb-pmm-transform-shadow-copies-looking-at t "{{" lb-re-beg-shadow t))) ;; ##}}## - THATA ONE (setq lb-pt1-there (cdr (lb-pmm-transform-shadow-copies-looking-at t "}}" lb-re-end-shadow t)))) ) ;; 3RD _rc)) ;; (lb-pmm-transform-shadow-copies) (defun lb-pmm-transform-shadow-copies nil "Search from top of buffer. If ARG1 is non-nil and non-list, assumes looking for to-here. Moves point to beginning of to-here. If ARG1 is nil, assumes looking for from-here. Leaves point where it was (preceding call: ARG1 is 't'). Deletes '##{{##' and '##}}##'. Do checks on points returned by above two cons cells. If ARG1 is a list, assumes list is pointing to from-here. Replaces '##{{## ##}}##' with contents of from-here" ;; (let (lb-cons-to-here lb-cons-from-here lb-err0 lb-err1 _rc) ;;; "en/1982/3HU357/20051223/099.tx" ;;; __ALPHA_LVL2__ ;;; ##{{## ##}}## ;;; ;;;

;;; The treacherous attack by fascist Germany. ... ;;; ;;;

;;; ##{{##The treacherous attack by fascist Germany.##}}## The ... ;;; imperialist bourgeoisie ... (goto-char (point-min)) (while (and (setq lb-cons-to-here (lb-pmm-transform-shadow-copies-get t)) (progn (goto-char (car lb-cons-to-here)) t)) ;; This one will delete "##{{##" and "##}}##" from "from-here". ;; This one will delete "##{{##" and "##}}##" from "to-here" and ;; copy text from "from-here" to "to-here". (lb-pmm-transform-shadow-copies-get ;; This one (no ARGs) checks both pairs. ;; This one returns cons pair of points with bounds of 2nd pair. (lb-pmm-transform-shadow-copies-get))) _rc)) ;; (lb-mu-most-recently-modified-inputs) (defun lb-mu-most-recently-modified-inputs nil "Very conservative idea of when last change to input happened. Looks at: - .tx file - book.htmm - /htm/... - /*.css - /*.el - OTHERS?" ;; (let (_pf _rc) (save-match-data (with-temp-buffer ;; CDATA (insert (_-timestamp (setq _pf lbg-text-indextx)) " " _pf "\n") ;; Template. ;; fix? always book.htmm? (insert (_-timestamp (setq _pf (concat lb-home (lb-get-diskfilename "book")))) " " _pf "\n") ;; Fragments that go into template and CSS (loop for cons in (list ;; fix! do not hardcode. (cons (concat lb-home "htm/") "/[^.].*[.][a-z][a-z]$") ;; .biz/.#lb-pmm.el" (cons (concat lb-home "") "^[^.].*[.]css$") (cons (concat lb-home "") "^[^.].*[.]el$") ) do (loop for file in (directory-files (car cons) t (cdr cons)) do ;; Is it not-directory or symbolic link? (if (and ;; Update webpages from this file: (not (string-match "go-speed-racer" file)) (or (null (nth 0 (file-attributes file))) (eq 'string (type-of (nth 0 (file-attributes file)))))) (insert (_-timestamp file) " " file "\n")))) ;; (sort-lines nil (point-min) (point-max)) (goto-char (1- (point-max))) (setq _rc (_-current-line)) (buffer-string)) ) _rc)) (provide 'lb-pmm) ;;; ;