;; Hooks. ;; Emacs-Time-stamp: "2007-11-21 22:50:11" (setq file-stamp "Emacs-File-stamp: \"/home/ysverdlov/leninist.biz/lb-hooks.el\"") ;;; files.el ;;;(defun basic-save-buffer () ;;;(or (run-hook-with-args-until-success 'write-contents-hooks) ;;; (run-hook-with-args-until-success 'local-write-file-hooks) ;;; (run-hook-with-args-until-success 'write-file-hooks) ;;; ;; If a hook returned t, file is already "written". ;;; ;; Otherwise, write it the usual way now. ;;; (setq setmodes (basic-save-buffer-1))) ;; Used by hooks: (defun lb-date-verbal nil "Now" ;; (lb-date-verbal) => "2005 May 31" (with-temp-buffer ;; (shell-command "822-date" t) (insert (format-time-string "%Y %B %d")) (buffer-substring-no-properties (point-min) (point-max)))) (defun lb-date-YYYY.MM.DD nil "Now" ;; (lb-date-verbal) => "2005 May 31" (with-temp-buffer ;; (shell-command "822-date" t) (insert (format-time-string "%Y.%m.%d")) (buffer-substring-no-properties (point-min) (point-max)))) ;; Used by hooks: (defun lb-bfn-to-url (arg1bfn) "" ;; (lb-bfn-to-url (buffer-file-name)) => "http://leninist.biz/lb.el" (let (x) (save-match-data (and (string-match abbreviated-home-dir (setq x (buffer-file-name))) (string-match "^~" (setq x (replace-match "~/" t t x))) (replace-match "http:/" t t x))))) ;; ;; "dired-after-readin-hook" comes after "dired-mode-hook" in dired.el. ;; SEE dired-internal-noselect. ;; - hook dired-mode-hook run at end of (dired-mode. ;; - hook dired-after-readin-hook run after that. ;; (setq dired-mode-hook nil) ;; (add-hook 'dired-mode-hook 'lb-dired-hook-insert-dot-index) ;; (setq dired-after-readin-hook nil) ;; (add-hook 'dired-after-readin-hook 'lb-dired-hook-insert-dot-index) (defun lb-dired-hook-insert-dot-index (&optional arg1) "" (interactive "p") (let (lb-path lb-files lb-rc) (when (string-match (concat lb-re-path-year+book "$") (dired-current-directory)) (setq lb-path (match-string-no-properties 0 (dired-current-directory))) (if (and (not (file-exists-p (concat lb-home lb-path "" lb-file-dot-index))) (and (not (string-match "^AF1H4YV" (system-name))) ;; mta metro laptop - 2007.11.21 (not (string-match "^TYPE9549.gateway.2wire.net" (hostname))) ) (null (directory-files (dired-current-directory) t ;; fix? ;; should use regexp. (concat "^" lb-file-dot-index "$") ))) (lb-db-insert-dot-index-book lb-path))) ;; .index does not appear in dired window until... ;; (revert-buffer) ;;; Signaling: (error "Variable binding depth exceeds max-specpdl-size") ;;; file-name-non-special(expand-file-name "ls" "/:/bin") ;;; call-process("ls" nil t nil "-al" "--" "/home/login/leninist.biz/.") ;;; apply(call-process "ls" nil t nil ("-al" "--" "/home/login/leninist.biz/.")) ;;; insert-directory("/home/login/leninist.biz/" "-al" nil t) ;;; dired-insert-directory("~/leninist.biz/" "-al" nil t) ;;; dired-readin-insert("~/leninist.biz/") ;;; dired-readin("~/leninist.biz/" #) ;;; dired-revert(nil nil) ;;; revert-buffer() lb-rc)) (defun lb-do-auto-fill () "" (let (lb-pf lb-line) (setq lb-line (buffer-substring-no-properties (save-excursion (beginning-of-line) (point)) (save-excursion (end-of-line) (point)))) (do-auto-fill) ;; ;; Why is [SPACE][BACKSPACE] necessary? ;; Why not just [SPACE]? (if (string-match "^__TITLE__[^\n]+: $" lb-line) (insert "\n__SUBTITLE__ ") (if (string-match "^__SUBTITLE__[^\n]+: $" lb-line) (insert "\n__SUBTITLE2__ "))) )) ;; This takes too long every time an .index is opened. ;; Only really needed when adding a new book; SEE: lb-db-insert-dot-index-type ;; ;; But, without it, empty template is *NOT* added to new .index! (add-hook 'find-file-hooks 'lb-db-find-file-hook) (defun lb-db-find-file-hook nil "" (let ((lb-bfn (buffer-file-name))) (when (or (string-match (concat "/" lb-re-file-rawdata) lb-bfn) nil) (local-set-key "\M-q" 'lb-db-fill-paragraph) (local-set-key "\M-a" 'lb-db-fill-paragraph) (setq auto-fill-function 'lb-do-auto-fill) ;; If empty, add first record. (when (string= "" (buffer-string)) (progn (insert "\n0\n\n0") (save-buffer 0)) (progn (lb-db-insert-rec nil) (save-buffer 0)) (lb-db-insert-dot-index-type)) ;; (lb-db-check-dot-index lb-bfn) ;; SEE: lb-db-insert-dot-index-book ;; (lb-db-shell-grep-titl2 lb-bfn) ))) (defun lb-time-stamp-format nil "" (let ((lb-bfn (buffer-file-name))) (if (string-match lb-domain lb-bfn) (set (make-local-variable 'time-stamp-format) "%:y-%02m-%02d %02H:%02M:%02S")))) ; (add-hook 'find-file-hooks 'lb-time-stamp-format) (add-hook 'find-file-hooks 'lb-write-file-hooks-text-mode-formatting) (defun lb-write-file-hooks-text-mode-formatting nil "" (let (lb-rc) ;; (when (or (eq 'text-mode major-mode) ;; (string-match "[.]tx[q]?$" (bfn)) (eq 'text-mode major-mode)) (add-hook 'local-write-file-hooks '_-compress-multiple-newlines t) (add-hook 'local-write-file-hooks 'lb-db-fill-paragraph-non-interactive t)) (when (or (string-match "[.]tx[q]?$" (bfn)) ) (add-hook 'local-write-file-hooks 'tx-check-buffer-noninteractive t) (add-hook 'local-write-file-hooks 'lb-tx-check-^^ t) (add-hook 'local-write-file-hooks 'lb-tx-check-buffer4-singularities t) (add-hook 'local-write-file-hooks 'lb-tx-check-buffer4-trailing-dash t) (add-hook 'local-write-file-hooks 'lb-tx-check-buffer4-para-break-before-last-line t) ;; 2007.08.22 (if (not (save-excursion (or (sbr "" nil t) (sfr "" nil t)))) (add-hook 'local-write-file-hooks 'lb-tx-check-page-numbers-editing t)) ) ;; be sure to return nil so can be used on write-file-hooks nil)) ;; (lb-write-file-hook-sgml-stamps-visible) (add-hook 'local-write-file-hooks 'lb-write-file-hook-sgml-stamps-visible) (defun lb-write-file-hook-sgml-stamps-visible (&optional arg1force) " Optional ARG1, if non-nil, will force this function to do its thing; otherwise change depends upon major-mode" ;; (let (lb-pf nil_rc) (save-excursion (save-match-data (goto-char (point-max)) (while (and (or arg1force (eq 'html-mode major-mode) (eq 'sgml-mode major-mode) (eq 'text-mode major-mode) ;; Raw markup (lb-mu.el). (eq 'xml-mode major-mode)) (search-backward-regexp "class=\"\\(modified\\|self-url\\)\"" nil t)) ;; (save-excursion (when (and (string= "span" (_-sgml-what-element)) (search-forward-string ">")) ;; 2006 Feb 3 (if (sfr (concat ;; 2007.07.31 - stopped working when ;; changed from: ;; 2006 Feb 3 ;; to: ;; Created= 2006 Feb 3 ;; -------------------- ;; _-whitespace-noM "*" ;; "\\([^0-9]*\\)" ;; "\\(.*\\)" "\\(2[0-9][0-9][0-9] [A-Z][a-z]+ [0-9]+\\)") (sex (sfr "\\(\\|