Skip to content
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 53 lines (42 sloc) 1.64 KB
#!/usr/local/bin/emacs --script
(require 'package)
(add-to-list 'load-path "~/.emacs.d")
(require 'larsen-functions)
(require 'pdf-annot)
(require 'cl)
(setq large-file-warning-threshold nil)
(defun usage ()
(error "You need to provide a pattern to search"))
(defun all-pdf-files (path)
"Recursively find every PDF file starting from PATH."
(directory-files-recursively path ".*\.pdf"))
(defun annotation-contents (annot)
"Return the text content in ANNOT. Newlines are converted to
(replace-regexp-in-string "\n" " " (cdr (assoc 'contents annot))))
(defun get-all-annotations (file)
"Return all annotations saved in FILE, as a concatenation of
their contents."
(let* ((annots (with-current-buffer (find-file file)
(pdf-annot-getannots nil nil))))
(mapconcat 'annotation-contents annots " ")))
(defun search-in-annots (pattern file)
(let ((all-annotations (get-all-annotations file)))
(when all-annotations
(if (string-match pattern all-annotations)
(princ (format "%s: %s\n" file all-annotations))
(cl-defun pdf-search (pattern &optional (path "."))
"Search for PATTERN in the annotations for every PDF file
recursively found starting from PATH. If PATTERN is found in a
file, print its absolute filename and the entire set of
annotations saved in the file."
(message (format "Looking for \"%s\" in %s" pattern path))
(dolist (pdf-file (all-pdf-files path))
(search-in-annots pattern pdf-file)))
((pattern :mandatory "You must provide a PATTERN")
(path :default "."))
(pdf-search pattern path))
You can’t perform that action at this time.