;;; ateneo-library.el - Function for interacting with the Ateneo de Manila University library ;; Method: Post ;; Fields: ;; datacoll: ;; rizal - General Circulation Collection ;; ref - General Reference Collection ;; fil - Filipiniana / Special Collection ;; ahc - American Historical Collection ;; thesis - Theses Collection ;; serial - Serial Holdings ;; searchstring: ;; R1: Search type ;; V1 - all ;; V3 - title ;; V5 - title (exact) ;; V2 - author ;; V4 - subject (defvar ateneo-library-books nil "Ateneo library book information") (defgroup ateneo nil "Ateneo-specific options.") (defcustom ateneo-library-data-file "~/.opacbooks" "The data file for the Ateneo library circulation section." :type 'string :group 'ateneo) ;;(defun ateneo-library-browse-shelf (regexp) ;; (interactive "MEnter regexp:") ;; (delq (mapcar (lambda (item) ;; (if (string-match regexp ( ;; ) ateneo-library-books))) (defun ateneo-library-read-records (&optional reload) (interactive) (when (or reload (not ateneo-library-books)) (with-current-buffer (find-file-noselect ateneo-library-data-file) (let ((buffer-read-only nil) (modp (buffer-modified-p)) ;; Make sure those parens get cleaned up. ;; This code had better stay simple! (inhibit-quit t)) (goto-char (point-min)) (insert "(\n") (goto-char (point-max)) (insert "\n)") (goto-char (point-min)) (setq ateneo-library-books (read (current-buffer))) (goto-char (point-min)) (delete-char 2) (goto-char (point-max)) (delete-char -2) (set-buffer-modified-p modp) (kill-buffer (current-buffer)))))) (defun ateneo-library-book-cat-no (record) (elt record 0)) (defun ateneo-library-book-title (record) (elt record 1)) (defun ateneo-library-match (record &optional title) (let ((add-this t)) (if (stringp title) (setq add-this (string-match title (or (ateneo-library-book-title record) ""))) (if (listp title) (let ((rest-of-title title) (book-title (ateneo-library-book-title record)) ) (while (and rest-of-title add-this) (setq add-this (string-match (car rest-of-title) book-title) rest-of-title (cdr rest-of-title))))) ) add-this )) (defun ateneo-library-search (&optional title) (ateneo-library-read-records) (let ((matches '()) (case-fold-search t) (record ateneo-library-books)) (while (car record) (if (ateneo-library-match (car record) title) (setq matches (cons (car record) matches))) (setq record (cdr record)) ) matches )) (defun ateneo-library-search-title (search) (interactive "MTitle: ") (ateneo-library-display-book-results (concat "Title: " search) (ateneo-library-search (mapcar 'regexp-quote (split-string search))))) (defvar ateneo-library-book-results-buffer-name "*Books*") (defun ateneo-library-display-book-results (query results) (set-buffer (get-buffer-create ateneo-library-book-results-buffer-name)) (setq buffer-read-only nil) (erase-buffer) (insert "Query: " query "\n") (dolist (book results) (insert (propertize (concat ;; (propertize (ateneo-library-book-title book) 'field 0) ;; (propertize " (" 'field 1) ;; (propertize (ateneo-library-book-cat-no book) 'field 2) ;; ")") (ateneo-library-book-title book) ". " (ateneo-library-book-cat-no book)) 'book book) "\n")) (goto-char (point-min)) (view-mode) (pop-to-buffer (current-buffer)) ) ;(define-derived-mode book-results-mode view-mode "Books" ; "Major mode for book results. ;\\{book-results-mode-map}" ;(eval-after-load 'emacspeak ; (progn ; (ad-disable-advice 'widget-end-of-line 'around 'emacspeak) ; (ad-activate 'widget-end-of-line))) ;(define-derived-mode book-details-mode view-mode "Book details" ; "Major mode for book details. ;\\{book-details-mode-map}" ; (use-local-map book-details-mode-map)) (defun ateneo-library-book-info () (interactive) (let ((book (get-text-property (point) 'book))) (if (not book) (error "No book under point.")) (set-buffer (get-buffer-create "*Book details*")) (setq buffer-read-only nil) (erase-buffer) (insert "Call No: " (elt book 0) "\n") (insert "Title: " (elt book 1) "\n") (cond ((> (length (elt book 2)) 1) (insert "Authors: " (car (elt book 2)) "\n") (dolist (author (cdr (elt book 2))) (insert " " author "\n") )) ((= (length (elt book 2)) 1) (insert "Author: " (car (elt book 2)) "\n"))) (insert "Publisher: " (elt book 3) "\n") (insert "Date: " (number-to-string (elt book 4)) "\n") (insert "Details: " (elt book 5) "\n") (cond ((> (length (elt book 6)) 1) (insert "Subjects: " (car (elt book 6)) "\n") (dolist (subject (cdr (elt book 6))) (insert " " subject "\n") )) ((= (length (elt book 6)) 1) (insert "Subject: " (car (elt book 6)) "\n"))) (view-mode) (goto-char (point-min)) (pop-to-buffer (current-buffer)) )) (defun ateneo-library-show-cat-no () (interactive) (message (mapconcat 'emacspeak-get-phonetic-string (downcase (elt (get-text-property (point) 'book) 0)) " "))) ;(define-key book-results-mode-map "\r" 'ateneo-library-book-info) ;(define-key book-results-mode-map "c" 'ateneo-library-show-cat-no)