;; Variables. ;; Emacs-Time-stamp: "2007-08-01 00:16:36" (setq file-stamp "Emacs-File-stamp: \"/home/ysverdlov/leninist.biz/lb-defun.el\"") (setq lb-filestamp file-stamp) (defalias 'hostname (symbol-function 'system-name)) ;; WARNING: Will search for "search" during debugging, so, risky to exclude it! (defalias 'search-forward-string (symbol-function 'search-forward)) (defalias 'search-backward-string (symbol-function 'search-backward)) ;; (defalias 'msn (symbol-function 'match-string-no-properties)) (defalias 'sfr (symbol-function 'search-forward-regexp)) (defalias 'sfs (symbol-function 'search-forward-string)) ;; why not defined now? (defalias 'fsd (symbol-function 'file-name-sans-directory)) (defalias 'sbr (symbol-function 'search-backward-regexp)) (defalias 'sbs (symbol-function 'search-backward-string)) (defalias 'bfn (symbol-function 'buffer-file-name)) (defalias 'bsf (symbol-function '_-buffer-substring-from-)) (defalias 'wdn (symbol-function '_-where-double-newlines)) (defalias '_-buffer-to-list (symbol-function '_-something-to-list)) ;; wie.com - 2007.07.11 (defalias 'gcpm (lambda nil "" nil (goto-char (point-min)))) (defalias 'sex (symbol-function 'save-excursion)) ;;; JUST: use M-x bookmark-save (interactive function). ;;; (defalias 'bms (symbol-function 'bookmark-save)) ;; howto? ;; Echo file that just got deleted using (delete-file FILENAME) ... ? ;; Add prefix argument to continue from point. 2006.10.06. (defun ispell-continue (arg) ;; () "Continue a halted spelling session beginning with the current word." ;; (interactive) (interactive "p") ;; 2006.10.06 - from ispell.el (if (= 4 arg) (set-marker ispell-region-end (point-max))) (if (not (marker-position ispell-region-end)) (message "No session to continue. Use 'X' command when checking!") (if (not (equal (marker-buffer ispell-region-end) (current-buffer))) (message "Must continue ispell from buffer %s" (buffer-name (marker-buffer ispell-region-end))) (ispell-region ;; find beginning of current word: (car (cdr (ispell-get-word t))) (marker-position ispell-region-end))))) (defun lb-interactive-test (arg1) (interactive "p") (message (prin1-to-string arg1))) ;; fix? ;; basic-save-buffer ? (no "-1"). ;; ;; (defalias 'bsb (symbol-function 'basic-save-buffer-1)) (defun bsb nil "" (let ( _rc) ;; Cannot do a defalias if these needed. (time-stamp) (_-compress-multiple-newlines) (basic-save-buffer-1) _rc)) (defalias 'file-name-sans-directory (symbol-function 'file-name-nondirectory)) (defalias 'sc (symbol-function 'shell-command)) (defalias 'delete-hook 'remove-hook) ;; fix! foo.html in HTML runs it; Emacs-Lisp in XML does not. (defalias 'hhmts-update-timestamp 'psgml-html-update-timestamp) ;; f2 f2 runs the command 2C-two-columns ;; which is an interactive compiled Lisp function in `two-column'. ;; (2C-two-columns &optional BUFFER) ;; (global-set-key [f2 f2] 'tx-editing-insert-__progress_comment__) ;; (global-set-key [f2 f2] 'tx-editing-insert-__printers) (global-set-key [f2 f2] 'tx-editing-contextual-insert-) ;; (global-set-key [f2 f3] 't2h-save-buffer-control-M) ;; (global-set-key [f2 f9] 'lb-mu-htmm-to-html) ;; forward-word is an interactive built-in function. (global-set-key [C-right] 'lb-forward-word) (global-set-key [C-right] 'forward-word) (defun lb-forward-word (&optional arg) "This adds a post hook to the usual definition" ;; (interactive "p") (let (lb-rc) ;; MAIN (forward-word 1) ;; POST HOOK (if (looking-at "\\(>\\)[ \t\n\r]") (goto-char (match-end 1))) lb-rc)) ;; "/usr/share/emacs/20.7/lisp/textmodes/paragraphs.el" (global-set-key [C-down] 'lb-forward-paragraph) (global-set-key [C-down] 'forward-paragraph) (defun lb-forward-paragraph (&optional arg) "This adds a post hook to the usual definition. Leave backward-paragraph alone since we are usually scrolling down, not up" ;; (interactive "p") (or arg (setq arg 1)) (let (lb-rc) ;; MAIN (forward-paragraph arg) ;; POST HOOK (recenter) lb-rc)) (defun error (&rest args) "" ;; (let ((_-pt (point)) (_-pf "~/foo")) (if (file-exists-p _-pf) (delete-file _-pf)) (write-region (point-min) (point-max) _-pf) (when nil (save-excursion (set-buffer "*Messages*") (goto-char (point-max)) (insert "For buffer contents: " "(progn (find-file-literally \"" _-pf "\")" " (goto-char " (int-to-string _-pt) "))\n"))) (progn (find-file _-pf) (goto-char _-pt)) ;; Continue with default action from subr (this is whole defun for error): (while t (signal 'error (list (apply 'format args)))))) (defun error (&rest args) (while t (signal 'error (list (apply 'format args))))) (defun lb-something-to-html (&optional arg1) "See global-set-key in lb-edits.el. EDITING .htmm: Create .html from .htmm by inserting data that is subject to change. EDITING .tx: Create index.html (and children) from .tx file(s)" (_-dfun-hook "lb-something-to-html") ;; (let (lb-pf-in lb-msnp0 lb-msnp1 lb-year-folder lb-rc) (save-match-data (when (or ;; Buffer attached to file. (setq lb-pf-in (bfn)) ;; Dired. (if (setq lb-pf-in (_-dired-get-fullpath)) (setq lb-pf-in (concat lb-home lb-pf-in "2000000/foo." lb-ext-tx)))) (cond ;; .htmm ((string-match (concat "[.]" lb-ext-htmm "$") lb-pf-in) (lb-mu-htmm-to-html lb-pf-in)) ;; .tx ((string-match (concat "[.]" lb-ext-tx "$") lb-pf-in) ;; Refresh index.txt (lb-tx-make-or-refresh-indextx ;; Chop off book instance (YYYYMMDD subdirectory). (concat (file-name-directory lb-pf-in) "..")) ;; (setq lb-year-folder (command-line-normalize-file-name-then-some (concat (file-name-directory lb-pf-in) "../.."))) ;; (lb-ht ;; Year: (nth (1- (length (split-string lb-year-folder "/"))) (split-string lb-year-folder "/")))) ;; error (t (error "%s: %s" "File extension not recognized" lb-pf-in)))) ) lb-rc)) ;; (lb-anyformat-what-page) (defun lb-anyformat-what-page (&optional arg1) " fix! Use lb-tx-page-point instead! Interactively messages 'page N'. When called non-interactively with ARG1 1, same as interactively. When called with a non-nil ARG1, returns cons ('N' . point) where point is to (right | left) of page number" ;; (interactive "p") ;; fix! (lb-tx-what-page) gives a different answer (numbers at top). (let (lb-str lb-pt lb-re) (save-match-data (save-excursion ;; NOTE: Do NOT error if search fails! That's the whole point! ;; en/1984/AP470/index.txt.log ;; 2006.11.23 - Added true page number after beg. pt. ;; PG# 2329 ;; PG# 2329 4 ;; [4] (if (and (setq lb-re (concat "PG#" ;; 2006.11.23 ;; _-whitespaces-noM " " "\\([0-9]+\\)" ;; 2006.11.23 ;; _-whitespaces-noM " " ;; 2006.11.23 ;; lb-re-bracketed-integer "\\([-]?[0-9]+\\)" )) (if ;; 2006.11.23 - true page number in PG# above. ;; 2006.11.23 - _-where-page-numbers was unbound. ;; (string= "top" _-where-page-numbers) t (search-backward-regexp lb-re nil t) (search-forward-regexp lb-re nil t))) ;; Point is value stored in file, not search endpoint. (progn (setq lb-pt (match-string-no-properties 1)) (setq lb-str (match-string-no-properties 2))) ;; fix! ;; Store regexp in variable. ;; (if (and (setq lb-re (concat "")) ;; fix? ;; Will _-where-page-numbers apply to SGML files? ;; It does not matter: we assume SGML comments can only ;; have true page number always *ABOVE* markup. (if ;; 2006.11.23 - We assume the one above has true page #. ;; 2006.11.23 - _-where-page-numbers was unbound. ;; (string= "top" _-where-page-numbers) t (search-backward-regexp lb-re nil t) (search-forward-regexp lb-re nil t))) (progn (setq lb-str (match-string-no-properties 1)) (setq lb-pt (if ;; 2006.11.23 ;; (string= "top" _-where-page-numbers) t (match-beginning 0) (match-end 0)))) ;; Default: raw ASCII text file. ;; Do not end search with "nil t" (need to fail when default). (setq lb-re lb-re-bracketed-para-integer) (if (string= "top" _-where-page-numbers) (if (not (search-backward-regexp lb-re nil t)) (if (not (search-forward-regexp lb-re nil t)) (error "%s: %s" lb-re (_-buffer-substring-from-))))) (progn (setq lb-str (lb-tx-what-page)) (setq lb-pt (if (string= "top" _-where-page-numbers) (lb-tx-page-point "page-beg") (lb-tx-page-point "page-end")))))))) (if (and (numberp arg1) (= 1 arg1)) (message (concat "page " lb-str)) (if (null arg1) lb-str (cons lb-str lb-pt))) )) ;; (lb-checkup-and-mail-it nil) (defun lb-checkup-and-mail-it nil ; 2005.05.28 "DOCUMENTATION" (let (lb-rc (my-temp-name (concat (temp-directory) "/" (make-temp-name "my-temp-name")))) (with-temp-file my-temp-name ;; (if (setq lb-rc (lb-batch-files-exist nil)) (insert "lb-batch-files-exist\n" lb-rc "\n")) ;; ) (if (< 0 (_-file-bytes my-temp-name)) (_-mail lb-mail-recipient lb-filestamp my-temp-name)) (delete-file my-temp-name))) ;; (looking-at-backward "[ ]+") (defun looking-at-backward (arg1re) "NEW 2007.08.01" (let (pt0 _pt-beg _pt-end (pt-original (point)) (_looking-at-backward--backup-factor 1000) ;; 5000) _rc) ;; fix! greedy / greediness ... ;; fix! searching forward, [ ]+ will move point further than backward. ;; fixed? Only problem is how far back to start for BIG buffers. (save-restriction (save-excursion (if (> (- (point) 3) _looking-at-backward--backup-factor) (forward-char (- 0 _looking-at-backward--backup-factor)) (goto-char (point-min))) ;; (progn (setq _pt-end nil) (while (and (sfr arg1re pt-original t) (setq _pt-beg (match-beginning 0)) (setq _pt-end (match-end 0)) ;; (not (= pt-original _pt-end))) ;; If match found but not da bomb, be ;; conservative and re-do search one point past ;; beginning of this match-beginning. (goto-char _pt-beg) (forward-char 1))) ;; (if (and _pt-end ;; Found at least 1. (= _pt-end pt-original) ;; Last one is da bomb. t) (setq _rc _pt-beg)) )) _rc)) ;; (looking-at-backward-OBSOLETE "[ ]+") (defun looking-at-backward-OBSOLETE (arg1re) "" (let (pt0 (pt-original (point)) _rc) ;; fix! greedy / greediness ... ;; fix! searching forward, [ ]+ will move point further than backward. (save-restriction (save-excursion (when (and (search-backward-regexp arg1re nil t) (= pt-original (match-end 0)) (setq _rc (match-beginning 0))) ;; fix? ;; Somehow the only way to get this to be the opposite ;; of looking-at is to: ;; (1) goto point min ;; (2) while search forward regexp using (point) as lower bound. ;; VERY EXPENSIVE! (while (and (progn ;; 2007.07.31 - "Beginning of buffer" if point-min!!! (forward-char -1) t) (looking-at arg1re) (= pt-original (match-end 0))) (setq _rc (match-beginning 0)))))) _rc)) (defun looking-at-backward-become-forward (arg1re) "If stuff to LEFT of point matches regexp ARG1, move to 'match-beginning 0' and then do a looking-at using ARG1" (let ( _rc) (if (and (setq _rc (looking-at-backward arg1re)) (goto-char _rc)) (looking-at arg1re)))) ;; (string-match-substitute "AAAAAAAA" "BEG" "::AAAAAAAA -->") (defun string-match-substitute (arg1reold arg2strnew arg3str) "Modeled after substitute CL-NEW CL-OLD CL-SEQ but ARG1 is before string, ARG2 is after string and ARG3 is string" (let ( lb-rc) (save-match-data (string-match arg1reold arg3str) (setq lb-rc (replace-match arg2strnew t t arg3str))) lb-rc)) (defun lb-date nil "Now" ;; (lb-date) => "2005.05.22 19:57:48 -0700" (with-temp-buffer ;; (shell-command "822-date" t) (insert (format-time-string "%Y.%m.%d %T %z")) (buffer-substring-no-properties (point-min) (point-max)))) (defun lb-list-index-text (arg1path-begin-with-lang) "Indirect way of calling lb-list-files-of-type-" ;; (lb-list-index-text lb-lang) ;; (lb-list-index-text "es/1974") (let (lb-rc) (lb-list-files-of-type- lb-file-txt arg1path-begin-with-lang))) (defun lb-list-index-html (arg1lang &optional arg2yr) "" ;; (lb-list-index-html lb-lang) (let (x) (lb-list-files-of-type- (concat lb-file-indexhtml ;; 2006.11.17 (if (string= "index" lb-file-indexhtml) ".html") ) arg1lang))) ;; (lb-list-files-of-type- lb-file-txt "en/1976") ;; (lb-list-files-of-type- lb-file-txt "en/1976/GPSPW2PP") (defun lb-list-files-of-type- (arg0-name arg1path-begin-with-lang &optional ) " ARG1 is passed to '-name' in find command. ARG2 is path pre-pended with lb-home and passed to find command." ;; (let (lb-str lb-depth _rc) (when arg1path-begin-with-lang ;; Delete leading slash. (if (string-match "^/" arg1path-begin-with-lang) (setq arg1path-begin-with-lang (substring arg1path-begin-with-lang 1))) ;; Add trailing slash. (if (not (string-match "/$" arg1path-begin-with-lang)) (setq arg1path-begin-with-lang (concat arg1path-begin-with-lang "/"))) ) (with-temp-buffer (setq lb-depth (int-to-string (+ 1 (- 3 (length (split-string arg1path-begin-with-lang "/")))))) (shell-command (concat "find " lb-home "" arg1path-begin-with-lang " -follow" " -mindepth " lb-depth " -maxdepth " lb-depth " -name " arg0-name) t) ;; fix! ;; find: /home/cymbala/leninist.biz/en/.#HTML: No such file or directory ;; why? 2007.07.31 ;; happens while creating en/HTML ! ;; ;;; ;;; /home/cymbala/leninist.biz/en/1939/HCPSU364/index.html ;;; /home/cymbala/leninist.biz/en/1926/MD152/index.html ;;; find: /home/cymbala/leninist.biz/en/.#HTML: No such file or directory ;;; cymbala@debian:~$ ;;; cymbala@debian:~$ #find ~/leninist.biz/en/ -follow -mindepth 3 -maxdepth 3 -name index.html ;;; cymbala@debian:~$ ;;; ;; fixed with this? (progn (goto-char (point-min)) (flush-lines "^find: ")) (setq _rc (buffer-string))) _rc)) (defun lb-get-id-from-path (&optional arg1pf arg2flag-partial) "Return, for example, 'en/1984/AP470'" ;; ;; (lb-get-id-from-path "~/leninist.biz/en/1984/AP470/.db") ;; (lb-get-id-from-path "~/leninist.biz/en/1984/" ) ;; (lb-get-id-from-path "~/leninist.biz/en/1984/" t) ;; (lb-get-id-from-path "~/leninist.biz/en/1984" t) ;; (lb-get-id-from-path "~/leninist.biz/en/" t) ;; (lb-get-id-from-path "~/leninist.biz/en" t) ;; (lb-get-id-from-path "en/1973/WICIR317" t) ;; (lb-get-id-from-path "en/1973/WICIR317/" t) ;; (lb-get-id-from-path "~/leninist.biz/en/1981/1HU376/index.html") (let (lb-str lb-pf _rc) (setq lb-pf (if arg1pf arg1pf (buffer-file-name))) (if (string-match (concat lb-re-path-year+book) lb-pf) (setq _rc (match-string 0 lb-pf)) (if arg2flag-partial (if (string-match (concat lb-re-path-year) lb-pf) (setq _rc (match-string-no-properties 0 lb-pf)) (if (string-match (concat "/" lb-re-lang "/?$") (file-name-directory lb-pf)) (setq _rc (match-string-no-properties 1 lb-pf)))))) (if (and _rc (string-match "/$" _rc)) (setq _rc (replace-match "" t t _rc))) _rc)) ;; fix! use proper _rc for other "lb-get-*" functions. ;; fix! use proper _rc for other "lb-get-*" functions. ;; fix! use proper _rc for other "lb-get-*" functions. (defun lb-get-lang-from-path (&optional arg1pf) "" ;; (lb-get-lang-from-path "~/leninist.biz/en/titl.htmm") (let (my my-pf) (if (not (string-match (concat lb-domain "/" lb-re-lang "/") (setq my-pf (if arg1pf arg1pf (buffer-file-name))))) nil (match-string-no-properties 1 my-pf)))) (defun lb-get-year-from-path (&optional arg1pf) "" ;; (lb-get-year-from-path "~/leninist.biz/en/1984/AP470/.db") (let (lb-str) (nth 1 (split-string (setq lb-str (lb-get-id-from-path arg1pf)) "/")))) (defun lb-get-titlpgs-from-path (&optional arg1pf) "" ;; (lb-get-titlpgs-from-path "ist.biz/en/1976/UFPAA244/20050713/.pageobjs.tx") (let (my my-pf) (if (not (string-match (concat (if nil lb-domain "") "/" lb-re-path-year+book) (setq my-pf (if arg1pf arg1pf (buffer-file-name))))) nil (match-string-no-properties 3 my-pf)))) (defun lb-testing-error-foo (arg1) "" ;; (if (file-exists-p "~/foo") (delete-file "~/foo")) (with-temp-buffer (insert (if (stringp arg1) arg1 (prin1-to-string arg1))) (write-region (point-min) (point-max) "~/foo")) (error "%s" "~/foo")) ;; 2007.03.23 (defun el-demonstrate-interactive-p (arg1) "" (interactive "p") (message "%s" (prin1-to-string arg1))) (defun bug nil "" (error "%s: %s" "Bug-ging from here" (_-buffer-substring-from-))) (provide 'lb-defun) ;;; ;