;;; Functions to play with netscape's history file ;;; Waider, 20/02/2001 (defvar nhist-filename (expand-file-name "~/.netscape/history.dat")) (defvar nhist-load-time nil) (defvar nhist-alist nil) (defun nhist-load( &optional force) (save-excursion (save-window-excursion (let ((buf (get-buffer-create " *nhist*"))) (set-buffer buf) (goto-char (point-min)) (if (or force (eobp)) (setq nhist-load-time nil)) (if (linkfarm-newer nhist-load-time (nth 5 (file-attributes nhist-filename))) () (setq nhist-alist nil) (erase-buffer) (message "Loading nhist...") (shell-command (concat "/usr/bin/db1_dump185 -p " nhist-filename) buf nil) (setq nhist-load-time (current-time)) (message "Loading nhist...done") ;; get an idea of how we're doing... (let ((maxlines (/ (count-lines (point-min) (point-max)) 2))) (message "Parsing nhist...[%s lines]" maxlines) (goto-char (point-min)) (if (re-search-forward "^HEADER=END" (point-max) t) (while (re-search-forward "^\\(\\(http\\|ftp\\|file\\):.*\\)\\\\00$" (point-max) t) (let ((linkurl (buffer-substring (match-beginning 1) (match-end 1))) (count 0)) (forward-line 1) (while (and (not (eolp)) (< count 16)) (setq count (+ 1 count)) (cond ((looking-at "\\\\\\\\") ;; !!!! (forward-char 2)) ((looking-at "\\\\") (forward-char 3)) (t (forward-char 1)))) (let ((linktitle (buffer-substring (point) (save-excursion (end-of-line) (forward-char -3) (point))))) ;; BOGUS. Why can't I nconc all the time? Hmm? (if nhist-alist (nconc nhist-alist (list (cons linktitle linkurl))) (setq nhist-alist (list (cons linktitle linkurl))))) (forward-line 1))))) (message "Parsing nhist...done")) ;;(kill-buffer buf) )))) (defun nhlist-find( source search ) (let ((case-fold-search t)) (nhist-load) ;; update lists if required XXX (delete nil (mapcar (function (lambda(x) (if (string-match search (cond ((eq source 'title) (car x)) ((eq source 'url) (cdr x)) (t (concat (car x) "\n" (cdr x))))) x nil))) nhist-alist)))) (defun nhlist-find-by-title( search ) (nhlist-find 'title search)) (defun nhlist-find-by-url( search ) (nhlist-find 'url search)) (defun nhlist-popup(source search) (interactive "Swhere? \nswhat? ") (if (null source) (setq source 'both)) (let ((buf (get-buffer-create " *netscape history*"))) (save-excursion (set-buffer buf) (and buffer-read-only (toggle-read-only nil)) (erase-buffer) (setq truncate-lines t) (local-set-key [(return)] 'nhlist-browse-url-at-point) (local-set-key [mouse-2] 'browse-url-at-mouse) (insert (mapconcat (function (lambda(x) (format "%-20s\t%s" (substring (car x) 0 (min 20 (length (car x)))) (cdr x)))) (nhlist-find source search) "\n")) (sort-lines nil (point-min) (point-max)) (goto-char (point-min)) (insert "PAGE TITLE \tPAGE URL\n") (insert "===============================================================================\n") (toggle-read-only t) (display-buffer buf nil) (shrink-window-if-larger-than-buffer (get-buffer-window buf))))) (defun nhlist-browse-url-at-point() (interactive) (message "Sending URL to browser...") (cond ((< (current-column) 20) (move-to-column 20) (forward-char 1))) ;; tab (call-interactively 'browse-url-at-point) (message "Sending URL to browser...done"))