;; TOC = Table of Contents. ;; Emacs-Time-stamp: "2007-11-22 09:48:41" (setq file-stamp "Emacs-File-stamp: \"/home/ysverdlov/leninist.biz/lb-toc.el\"") ;;; ======================================================= ;; ~/leninist.biz/en/1973/WICIR313/index.tab ;; (setq arg1drctn "PREV") ;; (setq arg2up9 "UP0" ) ;; (setq arg3lbg-i-from1 3 ) ;; --------------------------------- ;; (lb-ht-get-adjacent "PREV" "UP0" 1) => nil ;; (lb-ht-get-adjacent "NEXT" "UP0" 1) => 2 ;; (lb-ht-get-adjacent "PREV" "UP0" 2) => 1 ;; (lb-ht-get-adjacent "NEXT" "UP0" 2) => 3 ;; (lb-ht-get-adjacent "PREV" "UP0" 3) => nil ...nothing before intro. ;; (lb-ht-get-adjacent "NEXT" "UP0" 3) => 4 ;; (lb-ht-get-adjacent "PREV" "UP0" 4) => 3 ;; (lb-ht-get-adjacent "NEXT" "UP0" 4) => 5 ;; (lb-ht-get-adjacent "PREV" "UP0" 5) => nil ...first LVL3. ;; (lb-ht-get-adjacent "NEXT" "UP0" 5) => 6 ;; (lb-ht-get-adjacent "PREV" "UP0" 6) => 5 ;; (lb-ht-get-adjacent "NEXT" "UP0" 6) => 7 ;; (lb-ht-get-adjacent "PREV" "UP0" 7) => 6 ;; (lb-ht-get-adjacent "NEXT" "UP0" 7) => nil ;; (lb-ht-get-adjacent "PREV" "UP0" 8) => 5 ;; (lb-ht-get-adjacent "NEXT" "UP0" 8) => nil ;; (lb-ht-get-adjacent "PREV" "UP0" 9) => nil ;; (lb-ht-get-adjacent "NEXT" "UP0" 9) => 10 ;; (lb-ht-get-adjacent "PREV" "UP0" 10) => nil ...start of 2nd LVL3 group. ;; (lb-ht-get-adjacent "NEXT" "UP0" 10) => 11 ;; (lb-ht-get-adjacent "PREV" "UP0" 11) => 10 ;; (lb-ht-get-adjacent "NEXT" "UP0" 11) => 12 ;; (lb-ht-get-adjacent "PREV" "UP0" 12) => 11 ;; (lb-ht-get-adjacent "NEXT" "UP0" 12) => nil ;; (lb-ht-get-adjacent "PREV" "UP0" 13) => nil ;; (lb-ht-get-adjacent "NEXT" "UP0" 13) => 14 ;; (lb-ht-get-adjacent "PREV" "UP0" 14) => 13 ;; (lb-ht-get-adjacent "NEXT" "UP0" 14) => 15 ;; (lb-ht-get-adjacent "PREV" "UP0" 15) => 14 ;; (lb-ht-get-adjacent "NEXT" "UP0" 15) => 16 ;; (lb-ht-get-adjacent "PREV" "UP0" 16) => 15 ;; (lb-ht-get-adjacent "NEXT" "UP0" 16) => nil ;; --------------------------------- ;; (lb-ht-get-adjacent "PREV" "UP1" 1) => nil ;; (lb-ht-get-adjacent "NEXT" "UP1" 1) => nil ;; (lb-ht-get-adjacent "PREV" "UP1" 2) => nil ;; (lb-ht-get-adjacent "NEXT" "UP1" 2) => nil ;; (lb-ht-get-adjacent "PREV" "UP1" 3) => 2 ;; (lb-ht-get-adjacent "NEXT" "UP1" 3) => 9 ;; (lb-ht-get-adjacent "PREV" "UP1" 4) => 2 ;; (lb-ht-get-adjacent "NEXT" "UP1" 4) => 9 ;; (lb-ht-get-adjacent "PREV" "UP1" 5) => 4 ;; (lb-ht-get-adjacent "NEXT" "UP1" 5) => 8 ;; (lb-ht-get-adjacent "PREV" "UP1" 6) => 4 ;; (lb-ht-get-adjacent "NEXT" "UP1" 6) => 8 ;; (lb-ht-get-adjacent "PREV" "UP1" 7) => 4 ;; (lb-ht-get-adjacent "NEXT" "UP1" 7) => 8 ;; (lb-ht-get-adjacent "PREV" "UP1" 8) => 2 ;; (lb-ht-get-adjacent "NEXT" "UP1" 8) => 9 ;; (lb-ht-get-adjacent "PREV" "UP1" 9) => 3 ;; (lb-ht-get-adjacent "NEXT" "UP1" 9) => 17 ;; (lb-ht-get-adjacent "PREV" "UP1" 10) => 9 ;; (lb-ht-get-adjacent "NEXT" "UP1" 10) => 13 ;; (lb-ht-get-adjacent "PREV" "UP1" 11) => 9 ;; (lb-ht-get-adjacent "NEXT" "UP1" 11) => 13 ;; (lb-ht-get-adjacent "PREV" "UP1" 12) => 9 ;; (lb-ht-get-adjacent "NEXT" "UP1" 12) => 13 ;; (lb-ht-get-adjacent "PREV" "UP1" 13) => 10 ;; (lb-ht-get-adjacent "NEXT" "UP1" 13) => 17 ;; (lb-ht-get-adjacent "PREV" "UP1" 14) => 10 ;; (lb-ht-get-adjacent "NEXT" "UP1" 14) => 17 ;; (lb-ht-get-adjacent "PREV" "UP1" 15) => 10 ;; (lb-ht-get-adjacent "NEXT" "UP1" 15) => 17 ;; (lb-ht-get-adjacent "PREV" "UP1" 16) => 10 ;; (lb-ht-get-adjacent "NEXT" "UP1" 16) => 17 ;; --------------------------------- ;; (lb-ht-get-adjacent "PREV" "UP2" 1) => nil ;; (lb-ht-get-adjacent "NEXT" "UP2" 1) => nil ;; (lb-ht-get-adjacent "PREV" "UP2" 2) => nil ;; (lb-ht-get-adjacent "NEXT" "UP2" 2) => nil ;; (lb-ht-get-adjacent "PREV" "UP2" 3) => nil ;; (lb-ht-get-adjacent "NEXT" "UP2" 3) => nil ;; (lb-ht-get-adjacent "PREV" "UP2" 4) => nil ;; (lb-ht-get-adjacent "NEXT" "UP2" 4) => nil ;; (lb-ht-get-adjacent "PREV" "UP2" 5) => 2 ;; (lb-ht-get-adjacent "NEXT" "UP2" 5) => 9 ;; (lb-ht-get-adjacent "PREV" "UP2" 6) => 2 ;; (lb-ht-get-adjacent "NEXT" "UP2" 6) => 9 ;; (lb-ht-get-adjacent "PREV" "UP2" 7) => 2 ;; (lb-ht-get-adjacent "NEXT" "UP2" 7) => 9 ;; (lb-ht-get-adjacent "PREV" "UP2" 8) => nil ;; (lb-ht-get-adjacent "NEXT" "UP2" 8) => nil ;; (lb-ht-get-adjacent "PREV" "UP2" 9) => nil ;; (lb-ht-get-adjacent "NEXT" "UP2" 9) => nil ;; (lb-ht-get-adjacent "PREV" "UP2" 10) => 3 ;; (lb-ht-get-adjacent "NEXT" "UP2" 10) => 17 ;; (lb-ht-get-adjacent "PREV" "UP2" 11) => 3 ;; (lb-ht-get-adjacent "NEXT" "UP2" 11) => 17 ;; (lb-ht-get-adjacent "PREV" "UP2" 12) => 3 ;; (lb-ht-get-adjacent "NEXT" "UP2" 12) => 17 ;; (lb-ht-get-adjacent "PREV" "UP2" 13) => 3 ;; (lb-ht-get-adjacent "NEXT" "UP2" 13) => 17 ;; (lb-ht-get-adjacent "PREV" "UP2" 14) => 3 ;; (lb-ht-get-adjacent "NEXT" "UP2" 14) => 17 ;; (lb-ht-get-adjacent "PREV" "UP2" 15) => 3 ;; (lb-ht-get-adjacent "NEXT" "UP2" 15) => 17 ;; (lb-ht-get-adjacent "PREV" "UP2" 16) => 3 ;; (lb-ht-get-adjacent "NEXT" "UP2" 16) => 17 ;;; ======================================================= ;; ~/leninist.biz/en/1976/GPSPW3PP/index.tab ;; (setq arg1drctn "NEXT") ;; (setq arg2up9 "UP0" ) ;; (setq arg3lbg-i-from1 30 ) ;; --------------------------------- ;; (lb-ht-get-adjacent "PREV" "UP1" 28) ;; (lb-ht-get-adjacent "NEXT" "UP1" 28) ;; (lb-ht-get-adjacent "PREV" "UP0" 30) ;; (lb-ht-get-adjacent "NEXT" "UP0" 30) ;; (defun lb-ht-get-adjacent (arg1drctn arg2up9 arg3lbg-i-from1) "Called by lb-ht-common-__. ARG1 is 'PREV' or 'NEXT'. ARG2 is 'UP0' or 'UP1' or 'UP2'. ARG3 is lbg-i-from1 (may be able to do without this ARG). Returns list with three items: 1. integer of section located (1-based), 2. cons pointing to desired NUMERIC and ALPHA within section (nth), 3. section located as a list with 6 members" ;; (_-dfun-hook "lb-ht-get-adjacent") ;; (let (lb-arg2up9-int lb-volunteer-ARG3 lb-lowest-lvl-here lb-drctn-offset lb-candidate lb-rc-i lb-lowest-numeric-for-nth-function lb-lowest-alpha-for-nth-function lb-set-rc-flag lb-cnt-2-2 lb-rc) ;; fix! ;; file:///home/login/leninist.biz/en/1973/WICIR313/CHAPTER-IV ;; After using ">>" for going from "CHAPTER IV" to "Conclusion", ;; "<<" does *NOT* point back to "CHAPTER IV" but "<" does! ;; fix? ;; When would it error? Never? Input values probably controlled. ;; NOTE: BELOW: 1st call of (lb-ht-toc-get-headings : ARG3 is nil. ;; NOTE: BELOW: 2nd call of (lb-ht-toc-get-headings : ARG3 is t. ;; NOTE: BELOW: 3rd call of (lb-ht-toc-get-headings : ARG3 is t. (if (< arg3lbg-i-from1 1) (error "%s: %s" "too small" (prin1-to-string arg3lbg-i-from1)) (if (> arg3lbg-i-from1 (1- (length lbg-sections))) (error "%s: %s" "too big" (prin1-to-string arg3lbg-i-from1)))) (progn ;; GLOBALS. (setq lb-arg2up9-int (_-string-to-int arg2up9)) ;; (setq lb-volunteer-ARG3 (lb-ht-toc-get-headings arg3lbg-i-from1 nil ;; very important! nil )) ;; How far down? UP0 is possible with LVL1, 2 and 3. ;; How far down? UP1 is possible with LVL2 and 3. ;; How far down? UP2 is possible with LVL3. (setq lb-lowest-lvl-here (cond ((or (nth 5 lb-volunteer-ARG3) (nth 4 lb-volunteer-ARG3)) 3) ((or (nth 3 lb-volunteer-ARG3) (nth 2 lb-volunteer-ARG3)) 2) ((or (nth 1 lb-volunteer-ARG3) (nth 0 lb-volunteer-ARG3)) 1))) ;; Pointers into candidate pointing to lowest level. ;; If 3 down, use nth 4 (NUMERIC) and 5 (ALPHA). ;; If 2 down, use nth 2 (NUMERIC) and 3 (ALPHA). ;; If 1 down, use nth 0 (NUMERIC) and 1 (ALPHA). (setq lb-lowest-alpha-for-nth-function (1+ (setq lb-lowest-numeric-for-nth-function ;; (+ -2 (* 2 1)) => 0 ;; (+ -2 (* 2 2)) => 2 ;; (+ -2 (* 2 3)) => 4 (+ -2 (* 2 lb-lowest-lvl-here))))) ;; (setq lb-drctn-offset (if (string= "PREV" arg1drctn) -1 (if (string= "NEXT" arg1drctn) +1 (error "%s: %s" "Invalid choice" arg1drctn)))) ;; (cond ;; lb-cnt-2-2 ((= lb-arg2up9-int 0) ;; UP0 ;; Always take first one. (setq lb-cnt-2-2 1)) ((and ;; UP1 and UP2. (>= lb-arg2up9-int 1) ;; 3 - 1 = is GE 1. ;; 3 - 2 = is GE 1. ;; 2 - 1 = is GE 1. ;; 2 - 2 = is not GE 1. If at LVL2, cannot go up 2 levels. ;; 1 - 1 = is not GE 1. If at LVL1, cannot go up. ;; 1 - 2 = is not GE 1. If at LVL1, cannot go up. (>= (- lb-lowest-lvl-here lb-arg2up9-int) 1) ;; Where to find a non-nil UP-cell? ;; If looking L, ... 1 or 2 non-nil hops? (if (= -1 lb-drctn-offset) ;; ... if this one is non-nil at the UP-level, count it. ;; (Take second available cell, this one included.) (or (nth (- lb-lowest-numeric-for-nth-function (* 2 lb-arg2up9-int)) lb-volunteer-ARG3) (nth (- lb-lowest-alpha-for-nth-function (* 2 lb-arg2up9-int)) lb-volunteer-ARG3)) ;; If looking R, ... always one non-nil hop. ;; ... if this one is nil at the UP-level, count it. ;; ... if this one is non-nil at the UP-level, count it. ;; (Take first available cell to the right.) ;; (Contents of this cell at UP-level does not matter.) t)) (setq lb-cnt-2-2 1)) (t ;; DEFAULT (setq lb-cnt-2-2 0))) ;; ------------------------------------------------------- ;; FEEDBACK when testing containing PROGN. (list (list (cons arg1drctn lb-drctn-offset) (cons arg2up9 lb-arg2up9-int) arg3lbg-i-from1) (if (/= lb-lowest-lvl-here (string-to-int (nth 1 (assoc arg3lbg-i-from1 lbg-sections-max-levels-list)))) (error "%s: %s" "CHECK" "lbg-sections-max-levels-list") lb-lowest-lvl-here) (list lb-lowest-numeric-for-nth-function lb-lowest-alpha-for-nth-function) lb-cnt-2-2 lb-volunteer-ARG3)) ;;; ^ FEEDBACK (when ;; Loop or not to loop? (and ;; ------------------------------------------------------- ;; If at lb-lowest-lvl-here= LVL3, "UP0" "UP1" "UP2" valid. ;; If at lb-lowest-lvl-here= LVL2, "UP0" "UP1" valid. ;; If at lb-lowest-lvl-here= LVL1, "UP0" valid. ;; If at lb-lowest-lvl-here= LVL1, "UP1" and "UP2" invalid. ;; If at lb-lowest-lvl-here= LVL2, "UP2" invalid. (> lb-lowest-lvl-here lb-arg2up9-int) ;; ------------------------------------------------------- ) ;; Loop or not to loop? (loop for lb-i from ;; Start with looking backward one (-1) or forward one (1). 1 to ;; Approx. number of potential hops: a bit more than possible. (1+ (length lbg-sections)) do (if ;; This "if" first thing after "do" of "loop". (or ;; Reasons to BREAK. --------------------------------- ;; ------------------------------------------------------- ;; ------------------------------------------------------- ;; BREAK if t. ----- Nothing available. (not (setq lb-candidate (lb-ht-toc-get-headings (setq lb-rc-i (+ arg3lbg-i-from1 (* lb-i lb-drctn-offset))) nil ;; very important! t ;; very important! )) ) ;; ------------------------------------------------------- ;; BREAK if t. ----- UP0 test. ;; Lateral search (left or right sibling) at lowest level. (and (string= "UP0" arg2up9) (>= lb-lowest-lvl-here 2) ;; Able to look UP one. (if (= -1 lb-drctn-offset) ;; Looking L. ;; Do not use L sibling if parent of this one is non-nil. (or (nth (- lb-lowest-numeric-for-nth-function 2) lb-volunteer-ARG3) (nth (- lb-lowest-alpha-for-nth-function 2) lb-volunteer-ARG3)) ;; DO NOT SEPARATE! (if (= 1 lb-drctn-offset) ;; ;; Looking R. ;; Do not use R sibling if parent of R sibling is non-nil. (or (nth (- lb-lowest-numeric-for-nth-function 2) lb-candidate) (nth (- lb-lowest-alpha-for-nth-function 2) lb-candidate))) ) ;; ------------------------------------------------------- ;; BREAK if t. ----- At LVL3 looking UP1 test to the RIGHT. ;; NOTE: Same test to the LEFT is done at VERY END. (and (string= "UP1" arg2up9) ;; LVL3 ONLY. (= 3 lb-lowest-lvl-here) ;; LOOKING RIGHT ONLY. (= 1 lb-drctn-offset) ;; Anything at LVL1 should act as a block. (or (nth 0 lb-candidate) (nth 1 lb-candidate)) ) ;; ------------------------------------------------------- ) ;; Reasons to BREAK. --------------------------------- ;; BREAK: (setq lb-i 99999) ;; ------------------------------------------------------- ;; No brakes. Maybe use this one. ;; ------------------------------------------------------- ;; ~/leninist.biz/en/1973/WICIR313/index.tab ;; 1 2 ;; 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 ;; x x x x x ;; x x x x x x x x ;; x x x x x x x x x x ;; ;; A i I II III ;; i 1 2 3 i 1 2 i ;; i D C i C I i A A F ;; ------------------------------------------------------- ;; ~/leninist.biz/en/1987/WDM326/index.tab ;; ;; BUG: (6.)(2.)(a) had a left UP0 sibling of (3.)(1.)(c) !!! ;; 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 ;; x x x x x x ;; x x x x x x x x x x x x x x x x x x x x x x x x x ;; x x x x ;; ;; F 1 2 3 4 5 ;; 1 2 3 4 5 1 2 3 4 5 6 1 2 3 i 1 2 3 4 i 1 2 3 4 5 ;; i a b c ;; ;; ------------------------------------------------------- (when ;; Found one? (and (or (nth (- lb-lowest-numeric-for-nth-function (* 2 lb-arg2up9-int)) lb-candidate) (nth (- lb-lowest-alpha-for-nth-function (* 2 lb-arg2up9-int)) lb-candidate)) (setq lb-cnt-2-2 (1+ lb-cnt-2-2))) ;; (when (= 2 lb-cnt-2-2) (setq lb-rc (list lb-rc-i (cons lb-lowest-numeric-for-nth-function lb-lowest-alpha-for-nth-function) lb-candidate)) (setq lb-i 99999)) ;; ;; ------------------------------------------------------- ;; BREAK if t. ----- At LVL3 looking UP1 test to the LEFT. (if (and (string= "UP1" arg2up9) ;; LVL3 ONLY. (= 3 lb-lowest-lvl-here) ;; LOOKING LEFT ONLY. (= -1 lb-drctn-offset) ;; Anything at LVL1 should act as a block. (or (nth 0 lb-candidate) (nth 1 lb-candidate)) ) (setq lb-i 99999)) ) ) ) ) lb-rc)) ;; (lb-ht-toc-table-force-two-td) (defun lb-ht-toc-table-force-two-td nil "An alpha-lvl-1 like CHAPTER I may be squeezed into first column where page number usually go; force to column 2" (_-dfun-hook "lb-ht-toc-table-force-two-td") ;; (let (lb-bound lb-cnt lb-rc) ;;;