(autoload 'Info-goto-node "info")
(autoload 'Info-find-node "info")
(autoload 'find-function-read "find-func")
(autoload 'pp-to-string "pp")
(autoload 'Man-fontify-manpage "man" nil t)
(autoload 'word-at-point "thingatpt")
(autoload 'list-iso-charset-chars "mule-diag")
(autoload 'list-non-iso-charset-chars "mule-diag")
(defun ee-expand (fname)
"Expand \"~\"s and \"$ENVVAR\"s in file names, but only at the beginning of the string."
(cond ((string-match "^\\$\\([A-Za-z_][0-9A-Za-z_]*\\)\\(.*\\)" fname)
(concat (getenv (match-string 1 fname))
(match-string 2 fname)))
((string-match "^\\(~\\([a-z][0-9a-z_]*\\)?\\)\\(/.*\\)?$" fname)
(concat (expand-file-name (match-string 1 fname))
(match-string 3 fname)))
(t fname)))
(defun ee-setenv (envvar value)
"In case the environment variable ENVVAR was not set set it to VALUE."
(if (null (getenv envvar))
(setenv envvar (ee-expand value))))
(ee-setenv "EEVDIR"
(let ((fname (locate-library "eev")))
(if fname (directory-file-name (file-name-directory fname))
"$HOME/eev-current"))) (ee-setenv "EEVTMPDIR" "$HOME/.eev")
(ee-setenv "EEVRCDIR" "$EEVDIR/rcfiles")
(ee-setenv "EE" "$EEVTMPDIR/ee.sh")
(ee-setenv "EEG" "$EEVTMPDIR/ee.eeg")
(ee-setenv "EEGDB" "$EEVTMPDIR/ee.gdb")
(ee-setenv "EETEX" "$EEVTMPDIR/ee.tex")
(ee-setenv "EEC" "$EEVTMPDIR/ee.c")
(ee-setenv "EETMPC" "$EEVTMPDIR/tmp.c")
(ee-setenv "EEAOUT" "$EEVTMPDIR/ee.aout")
(ee-setenv "S" "$HOME/snarf")
(defvar ee-eevdir (ee-expand "$EEVDIR/")
"The directory where the elisp files for eev live.")
(defvar ee-eevtmpdir (ee-expand "$EEVTMPDIR/")
"The directory where the temporary script files are put.")
(defvar ee-eevrcdir (ee-expand "$EEVRCDIR/")
"The directory where some auxiliary rcfiles for eev are to be found.")
(defvar ee-file (ee-expand "$EE")
"The temporary script file used by `eev'.")
(defvar ee-file-tex (ee-expand "$EETEX")
"The temporary script file used by `eelatex'.")
(defvar ee-file-gdb (ee-expand "$EEGDB")
"The temporary script file used by `eegdb'.")
(defvar ee-file-generic (ee-expand "$EEG"))
(defvar eelatex-eevscript
"cd $EEVTMPDIR/; latex tmp.tex && xdvi tmp.dvi &" "See `eelatex'.")
(defvar ee-anchor-format nil "See `ee-goto-anchor'.")
(defvar ee-hyperlink-prefix "# ")
(defvar ee-comment-prefix "# ")
(put 'ee-anchor-format 'safe-local-variable 'stringp)
(put 'ee-comment-prefix 'safe-local-variable 'stringp)
(put 'ee-hyperlink-prefix 'safe-local-variable 'stringp)
(defvar ee-find-man-flag nil) (defvar ee-find-man-pos-spec-list nil) (defvar ee-buffer-name nil) (defvar ee-arg nil) (defvar ee-info-file nil) (defvar ee-info-code nil) (defvar ee-pop-up-windows nil)
(defvar ee-highlight-spec '(highlight 0.75)) (defvar eeb-highlight-spec '(highlight 0.5))
(defvar eek-highlight-spec '(region 0.75))
(defvar eeflash-default '(highlight 0.5))
(defvar code-c-d-list nil
"Each (code-c-d C D) call generates an entry (C (ee-expand D)) in this list.
A new entry with the same C as a previous one removes the old
one. This list is maintained by `code-c-d-register' and is used
by some functions in \"eev-insert.el\".")
(defun find-fline (fname &rest pos-spec-list)
"Hyperlink to a file (or a directory).
This function is similar to `find-file' but it supports a
\"pos-spec-list\" - see `ee-goto-position'.
Examples:\n
(find-file \"~/.emacs\")
(find-fline \"~/.emacs\")
(find-fline \"~/.emacs\" \"Beginning of the eev block\")"
(find-file (ee-expand fname))
(apply 'ee-goto-position pos-spec-list))
(defun find-node (nodestr &rest pos-spec-list)
"Hyperlink to an info page.
This function is similar to `info' but it supports a
\"pos-spec-list\" - see `ee-goto-position'.
Examples:\n
(info \"(emacs)Lisp Eval\")
(find-node \"(emacs)Lisp Eval\" \"C-x C-e\")"
(Info-goto-node nodestr)
(apply 'ee-goto-position pos-spec-list))
(defun ee-goto-position (&optional pos-spec &rest rest)
"Process the \"absolute pos-spec-lists\" arguments in hyperlink functions.
POS-SPEC, the first element of a pos-spec-list, is treated
specially; if it is a string then jump to the first occurrence of
that string in the buffer, and if it a number jump to the line
with that number in the buffer; if it is nil, do nothing.
The rest of the pos-spec-list, REST, is treated by
`ee-goto-rest'.
Many kinds of hyperlinks - for example,
(find-efunction 'ee-goto-position)
already jump to specific positions of a buffer; those hyperlink
functions support \"relative pos-spec-lists\", and they invoke
`ee-goto-rest' straight away to handle their pos-spec-lists -
they skip the first \"absolute\" pos-spec."
(when pos-spec
(cond ((numberp pos-spec)
(goto-char (point-min))
(forward-line (1- pos-spec)))
((stringp pos-spec)
(goto-char (save-excursion (goto-char (point-min)) (search-forward pos-spec) (point)))) (t (error "This is not a valid pos-spec: %S" pos-spec)))
(if rest (ee-goto-rest rest))))
(defun ee-goto-rest (list)
"Process \"relative pos-spec-lists\".
For each element in LIST, if it is:
a string -> jump to the next occurrence of that string in the
current buffer
a number -> go down that many lines
a list -> evaluate the list (take care!)
anything else generates an error - but users are encouraged to
create their own extended versions of this function and override
the standard definition."
(cond ((null list))
((stringp (car list))
(search-forward (car list))
(ee-goto-rest (cdr list)))
((numberp (car list))
(forward-line (car list))
(ee-goto-rest (cdr list)))
((consp (car list))
(eval (car list))
(ee-goto-rest (cdr list)))
(t (error "Not a valid pos-spec item: %S" (car list)))))
(defun ee-format-as-anchor (tag)
"Convert TAG into an anchor using `ee-anchor-format'."
(if ee-anchor-format
(format ee-anchor-format tag)
(error "`ee-anchor-format' is nil - can't convert string to anchor")))
(defun ee-goto-anchor (&optional tag &rest rest)
"Like `ee-goto-position', but TAG is converted to an anchor.
If the anchor obtained from TAG is not found then issue an error
but do not move point.
For example, if `ee-anchor-format' is \"<<%s>>\" then
(ee-goto-anchor \"foo\" \"bar\")
searches for the first occurrence of \"<<foo>>\" in the current
buffer, then for the first occurrence of \"bar\" after that. If
\"<<foo>>\" is not found then do not move point.
It is good style to set `ee-goto-anchor' globally to nil and only
use anchors in files where `ee-anchor-format' is declared in the
local variables section of the file; see:
(find-node \"(emacs)File Variables\")
(find-node \"(emacs)Specifying File Variables\")
a hint: one way of forcing reloading the local variables by hand
is by running `\\[normal-mode]'.
The glyphs defined in (find-eev \"eev-glyphs.el\") can be used to
make anchors using characters that stand out."
(if tag (goto-char
(save-excursion
(goto-char (point-min))
(search-forward (ee-format-as-anchor tag))
(point))))
(ee-goto-rest rest))
(defun find-anchor (fname &optional tag &rest pos-spec-list)
"Like `find-fline', but TAG is converted to an anchor if not nil.
See `ee-goto-anchor'."
(find-fline fname)
(apply 'ee-goto-anchor tag pos-spec-list))
(defun ee-to (tag &rest pos-spec-list)
"Like `find-anchor', but does not switch to another buffer or file."
(interactive "sAnchor: ")
(apply 'ee-goto-anchor tag pos-spec-list))
(defun find-wottb-call (sexp bufname &rest pos-spec-list)
"Hyperlink to functions that call `with-output-to-temp-buffer'.
First evaluate SEXP with a trick to not let it split the current window,
then switch to the buffer that it created (it must be called BUFNAME),
then go to the position specified by POS-SPEC-LIST.\n
\(This is a horrible hack.)"
(let ((same-window-buffer-names
(cons bufname same-window-buffer-names)))
(eval sexp))
(set-buffer bufname) (apply 'ee-goto-position pos-spec-list))
(defun find-eapropos (regexp &rest pos-spec-list)
"Hyperlink to the result of running `apropos' on REGEXP."
(interactive "sApropos symbol (regexp): ")
(apply 'find-wottb-call '(apropos regexp) "*Apropos*" pos-spec-list))
(defun find-efunctiondescr (symbol &rest pos-spec-list)
"Hyperlink to the result of running `describe-function' on SYMBOL."
(interactive (find-function-read))
(apply 'find-wottb-call '(describe-function symbol) "*Help*" pos-spec-list))
(defun find-evariabledescr (symbol &rest pos-spec-list)
"Hyperlink to the result of running `describe-variable' on SYMBOL."
(interactive (find-function-read 'variable))
(apply 'find-wottb-call '(describe-variable symbol) "*Help*" pos-spec-list))
(defalias 'find-evardescr 'find-evariabledescr)
(defun find-ekeydescr (key &rest pos-spec-list)
"Hyperlink to the result of running `describe-key' on KEY."
(interactive "kFind function on key: ")
(apply 'find-wottb-call '(describe-key key) "*Help*" pos-spec-list))
(defun find-efacedescr (face &rest pos-spec-list)
"Hyperlink to the result of running `describe-face' on FACE."
(interactive (list (read-face-name "Describe face")))
(apply 'find-wottb-call '(describe-face face) "*Help*" pos-spec-list))
(defun find-efaces (&rest pos-spec-list)
"Hyperlink to the result of running `list-faces-display'."
(interactive)
(apply 'find-wottb-call '(list-faces-display) "*Faces*" pos-spec-list))
(defun find-ecolors (&rest pos-spec-list)
"Hyperlink to the result of running `list-colors-display'."
(interactive)
(apply 'find-wottb-call '(list-colors-display) "*Colors*" pos-spec-list))
(defun find-efunctiond (function &rest pos-spec-list)
"Hyperlink to the result of running `disassemble' on FUNCTION."
(interactive (find-function-read))
(apply 'find-wottb-call '(disassemble function) "*Disassemble*"
pos-spec-list))
(defun find-ebufferandpos (buffer-and-pos &rest pos-spec-list)
"Internal use; hyperlink to a \"buffer and pos\" structure.
Emacs has some standard (i.e., non-eev) functions that can be
used as hyperlinks, like `find-function' and `find-variable';
they call internal functions like `find-function-noselect' and
`find-variable-noselect', that return structures of the form
BUFFER-AND-POS, that are conses like (#<buffer foo> . 42). This
function jumps to the position described by a cons like that, and
then processes an optional relative POS-SPEC-LIST using
`ee-goto-rest'.
Functions like `find-efunction' and `find-evariable' (defined in
eev.el) are wrappers around `find-function' and `find-variable'
that add support for a relative pos-spec-list after the symbol."
(if (not (bufferp (car buffer-and-pos)))
(error "Bad (BUFFER . POS): %S" buffer-and-pos))
(switch-to-buffer (car buffer-and-pos))
(goto-char (cdr buffer-and-pos))
(ee-goto-rest pos-spec-list))
(defun find-efunction (symbol &rest pos-spec-list)
"Hyperlink to the result of running `find-function' on SYMBOL.
The `find-function' function of Emacs can be used as a hyperlink
- it finds the Elisp source code of SYMBOL -, but it doesn't
support a POS-SPEC-LIST like this function does."
(interactive (find-function-read))
(apply 'find-ebufferandpos (find-function-noselect symbol) pos-spec-list))
(defun find-evariable (symbol &rest pos-spec-list)
"Hyperlink to the result of running `find-variable' on SYMBOL."
(interactive (find-function-read 'variable))
(apply 'find-ebufferandpos (find-variable-noselect symbol) pos-spec-list))
(defun find-eCfunction (fun &rest pos-spec-list)
"Hyperlink to the source in C for an Emacs primitive."
(interactive (find-function-read))
(apply 'find-ebufferandpos
(find-function-search-for-symbol
fun nil (help-C-file-name (indirect-function fun) 'fun))
pos-spec-list))
(defun find-eCvariable (symbol &rest pos-spec-list)
"Hyperlink to the definition in the C source of an Emacs variable."
(interactive (find-function-read 'variable))
(apply 'find-ebufferandpos
(find-variable-noselect
symbol (help-C-file-name symbol 'var))
pos-spec-list))
(defun find-ebuffer (buffer &rest pos-spec-list)
"Hyperlink to an Emacs buffer (existing or not)."
(interactive "bBuffer: ")
(switch-to-buffer buffer)
(apply 'ee-goto-position pos-spec-list))
(defun find-escratchbuffer (buffer-name &rest pos-spec-list)
"Hyperlink to an empty scratch buffer named BUFFER-NAME.
If a buffer named BUFFER-NAME exists then try to kill it with
`kill-buffer' to create a scratch buffer in its place. If the
buffer contains something precious then `kill-buffer' will ask
the user for confirmation; if the user decides not to kill the
buffer then this function aborts with an error."
(if (get-buffer buffer-name)
(if (kill-buffer buffer-name)
(switch-to-buffer buffer-name)
(error "Not killing the buffer %s" buffer-name))
(switch-to-buffer buffer-name)))
(defun find-eoutput (code &rest pos-spec-list)
"Hyperlink to the output of running CODE in an empty scratch buffer.
CODE is run again every time this hyperlink if followed; compare
with `find-eeffect' and `find-sh'."
(find-escratchbuffer (or ee-buffer-name "*output*"))
(eval code)
(goto-char (point-min))
(apply 'ee-goto-position pos-spec-list))
(defun find-eeffect (ee-buffer-name code &rest pos-spec-list)
"Hyperlink to the effect of running CODE in Emacs.
If the buffer EE-BUFFER-NAME does not exist then create it and
run CODE there; if the buffer already exists then reuse it -
suppose that its contents are already the result of running CODE
and do not run CODE again."
(if (get-buffer ee-buffer-name)
(apply 'find-ebuffer ee-buffer-name pos-spec-list)
(find-ebuffer ee-buffer-name)
(eval code)
(set-buffer-modified-p nil)
(goto-char (point-min))
(apply 'ee-goto-position pos-spec-list)))
(defun find-eoutput-rerun (buffer-name code &rest pos-spec-list)
"Hyperlink to the effect of running CODE in Emacs.
If the buffer BUFFER-NAME does not exist then create it and run
CODE in it. If the buffer already exists, then \"run CODE
again\" (compare with `find-output-reuse'): delete the buffer,
recreate it, and run CODE in it.\n
For simplicity we are deleting the buffer and then recreating it,
but it could be better to just delete the buffer's contents. This
needs to be thought out."
(if (get-buffer buffer-name) (if (not (kill-buffer buffer-name)) (error "Not killing the buffer %s" buffer-name)))
(switch-to-buffer buffer-name) (eval code) (goto-char (point-min))
(apply 'ee-goto-position pos-spec-list))
(defun find-eoutput-reuse (buffer-name code &rest pos-spec-list)
"Hyperlink to the effect of running CODE in Emacs.
If the buffer BUFFER-NAME does not exist then create it and run
CODE in it. If the buffer already exists, then \"reuse
it\" (compare with `find-output-rerun'): switch to it, ignore the
CODE argument, and process the POS-SPEC-LIST."
(if (get-buffer buffer-name) (switch-to-buffer buffer-name) (switch-to-buffer buffer-name) (eval code) (goto-char (point-min)))
(apply 'ee-goto-position pos-spec-list))
(defun find-estring (string &rest pos-spec-list)
"Visit a temporary buffer whose contents are given by STR.
The default name for the buffer is \"*string*\", but this can be
overriden by setting `ee-buffer-name' to another name with a `let'.
If the buffer already exists its contents are destroyed.
The buffer is not made read-only."
(apply 'find-eoutput-rerun (or ee-buffer-name "*string*")
`(insert ,string) pos-spec-list))
(defun find-estring-elisp (string &rest pos-spec-list)
"Visit a temporary buffer whose contents are given by STR.
This function is similar to `find-estring', but this one also
runs `emacs-lisp-mode' in the buffer."
(apply 'find-eoutput-rerun (or ee-buffer-name "*string*")
`(progn (insert ,string) (emacs-lisp-mode)) pos-spec-list))
(defun ee-pp0 (object &optional tick)
"Convert OBJECT (usually a sexp) into a string, for use in hyperlinks.
Quote newlines to make it fit in a single line.
If TICK is non-nil and OBJECT is a list then precede it with a \"'\".
The result of this function is always a string that can be `read' as Lisp."
(let ((str (let ((print-escape-newlines t)
(print-escape-nonascii t) (print-quoted t))
(prin1-to-string object))))
(setq str (replace-regexp-in-string "\r" "\\\\r" str))
(if (and tick (consp object))
(setq str (concat "'" str)))
str))
(defun find-epp0 (object)
"Display a pretty-printed version of OBJECT in the echo area.
This function uses `message' and so it only makes sense to call
it from commands bound to keys, not by sexps that are evaluated
explicitly. Try this: (progn (message \"foo\") \"bar\")"
(message (ee-pp0 object)))
(defun find-epp (object &rest pos-spec-list)
"Visit a temporary buffer containing a pretty-printed version of OBJECT."
(let ((ee-buffer-name (or ee-buffer-name "*pp*")))
(apply 'find-estring (pp-to-string object) pos-spec-list)))
(defun find-efunctionpp (symbol &rest pos-spec-list)
"Visit a temporary buffer containing the pretty-printed Lisp code for SYMBOL."
(interactive (find-function-read))
(let ((ee-buffer-name
(or ee-buffer-name (format "*function %S*" symbol))))
(apply 'find-epp
(symbol-function symbol)
pos-spec-list)))
(defun find-etpat (&rest pos-spec-list)
"Hyperlink to a pretty-version of the result of (text-properties-at (point))."
(interactive)
(let* ((ee-buffer-name
(or ee-buffer-name "*(text-properties-at (point))*")))
(apply 'find-epp (text-properties-at (point)) pos-spec-list)))
(defun find-etpat0 ()
"Show the result of (text-properties-at (point)) in the echo area."
(interactive)
(find-epp0 (text-properties-at (point))))
(defun find-echarsetchars (charset &rest pos-spec-list)
"See: (find-efunction 'list-charset-chars)
Examples: (find-echarsetchars 'mule-unicode-0100-24ff \"733x\")
(find-echarsetchars 'mule-unicode-2500-33ff)"
(interactive (list (read-charset "Character set: ")))
(apply 'find-eoutput-reuse "*charset*"
'(cond ((charsetp charset)
(list-iso-charset-chars charset))
((assq charset non-iso-charset-alist)
(list-non-iso-charset-chars charset))
(t (error "Invalid character set %s" charset)))
pos-spec-list))
(defun find-eccldump (ccl-code &rest pos-spec-list)
"Hyperlink to the result of running `ccl-dump' on CCL-CODE.
Example: (find-eccldump ccl-decode-mule-utf-8)"
(apply 'find-eoutput-reuse "*ccl-dump*"
`(ccl-dump ,ccl-code) pos-spec-list))
(defun find-ekeymapdescr (keymap &rest pos-spec-list)
"Hyperlink to the list of bindings in KEYMAP.
Example: (find-ekeymapdescr isearch-mode-map \"toggle-regexp\")"
(apply 'find-estring (substitute-command-keys "\\<keymap>\\{keymap}")
pos-spec-list))
(defun ee-minor-mode-keymap (mode-symbol)
"An auxiliary function for `find-ekeymapdescr'.
Example: (find-ekeymapdescr (ee-minor-mode-keymap 'eev-mode))"
(cdr (assq mode-symbol minor-mode-map-alist)))
(defun ee-insert (&rest rest)
"Insert characters, strings, or ranges of characters.
Example: (ee-insert '(?a ?z) 10 \"Foo!\")"
(while rest
(let ((o (car rest)))
(cond ((stringp o) (insert o))
((numberp o) (if (char-valid-p o) (insert o)))
((consp o) (mapc 'ee-insert (apply 'number-sequence o)))
(t (error "Not string/int/pair: %S" o))))
(setq rest (cdr rest))))
(defun find-einsert (what &rest rest)
"See `ee-insert'.
Example of use: (find-einsert '((32 1000) 10 (8000 12000)))"
(apply 'find-eoutput-reuse "*einsert*"
`(apply 'ee-insert ',what) rest))
(defun find-sh (command &rest pos-spec-list)
"Hyperlink to the result of running the shell command COMMAND.
If a buffer named COMMAND does not exist then create it and put
there the output or running COMMAND; if a buffer named COMMAND
already exists then reuse it and do not run COMMAND again."
(interactive "sShell command: ")
(if (get-buffer command) (switch-to-buffer command) (switch-to-buffer command) (insert (shell-command-to-string command)) (goto-char (point-min))) (apply 'ee-goto-position pos-spec-list))
(defalias 'find-sh00 'shell-command-to-string)
(defun find-sh0 (command)
"Hyperlink to the result of running the shell command COMMAND.
This function does not create a buffer like `find-sh' does;
instead, it just returns the output of COMMAND as string,
removing a trailing newline from the output if one is found.
Follow a `find-sh0' hyperlink just displays the output of the
COMMAND in the echo area."
(replace-regexp-in-string "\n$" "" (shell-command-to-string command)))
' (defun find-callprocess00 (prog &rest args)
"Example: (find-callprocess00 \"lua\" \"-e\" \"print(1+2)\")"
(with-output-to-string
(with-current-buffer
standard-output
(apply 'call-process prog nil t nil args))))
' (defun find-callprocess0 (&rest args)
"Example: (find-callprocess0 \"lua\" \"-e\" \"print(1+2)\")"
(replace-regexp-in-string "\n$" "" (apply 'find-callprocess00 args)))
(defun ee-split (str) (if (stringp str) (split-string str "[ \t\n]+") str))
(defun ee-unsplit (list) (if (listp list) (mapconcat 'identity list " ") list))
(defun ee-split-and-expand (str) (mapcar 'ee-expand (ee-split str)))
(defun ee-no-trailing-nl (str) (replace-regexp-in-string "\n$" "" str))
(defun find-bgprocess-ne (program-and-args)
(let ((argv (ee-split program-and-args)))
(apply 'start-process (car argv) "*Messages*" argv)))
(defun find-callprocess00-ne (program-and-args)
(let ((argv (ee-split program-and-args)))
(with-output-to-string
(with-current-buffer standard-output
(apply 'call-process (car argv) nil t nil (cdr argv))))))
(defun find-callprocess0-ne (program-and-args)
(ee-no-trailing-nl (find-callprocess00 program-and-args)))
(defun find-comintprocess-ne (name program-and-args)
(let ((argv (ee-split program-and-args)))
(apply 'make-comint name (car argv) nil (cdr argv))
(switch-to-buffer (format "*%s*" name))))
(defun find-bgprocess (program-and-args)
(find-bgprocess-ne (ee-split-and-expand program-and-args)))
(defun find-callprocess00 (program-and-args)
(find-callprocess00-ne (ee-split-and-expand program-and-args)))
(defun find-callprocess0 (program-and-args)
(find-callprocess0-ne (ee-split-and-expand program-and-args)))
(defun find-comintprocess (name program-and-args)
(find-comintprocess-ne name (ee-split-and-expand program-and-args)))
(defun ee-find-comintprocess-ne (dir name program-and-args)
(switch-to-buffer
(with-temp-buffer
(cd dir)
(find-comintprocess-ne name program-and-args)
(current-buffer))))
(defun ee-find-comintprocess (dir name program-and-args)
(ee-find-comintprocess-ne
(ee-expand dir) name (ee-split-and-expand program-and-args)))
(defadvice Man-notify-when-ready (around find-man (man-buffer) activate)
"After rendering a manpage jump to `ee-find-man-pos-spec-list'."
(if (not ee-find-man-flag)
ad-do-it
(switch-to-buffer man-buffer)
(apply 'ee-goto-position ee-find-man-pos-spec-list)
(setq ee-find-man-flag nil)))
(defun find-man (manpage &rest pos-spec-list)
"Hyperlink to a manpage."
(interactive (list (ee-manpagename-ask)))
(setq ee-find-man-flag t
ee-find-man-pos-spec-list pos-spec-list)
(man manpage))
(defun find-w3m (url &rest pos-spec-list)
"Hyperlink to a page in HTML.
Use w3m to render the page as text in an Emacs buffer.
Apply `ee-expand' to URL; this changes URL when it starts with
\"~\" or \"$\". After that if URL starts with \"/\" prepend
\"file://\" to it.
These operations on URL keep \"real urls\" unchanged and convert
several kinds of filenames into urls that w3m can process - but
it doesn't convert relative filenames into urls. See
`expand-file-name'."
(interactive "Murl: ")
(let ((enable-local-variables nil) (w3m-async-exec nil))
(w3m (replace-regexp-in-string "^/" "file:///" (ee-expand url))))
(ee-goto-rest pos-spec-list))
(defun ee-dvipage (fname &optional page xdviargs)
`("xdvi" ,@xdviargs ,@(if page (list (format "+%d" page))) ,fname))
(defun ee-pspage (fname &optional page gvargs)
`("gv" ,@gvargs ,@(if page (list (format "--page=%d" page))) ,fname))
(defun ee-xpdfpage (fname &optional page xpdfargs)
`("xpdf" ,@xpdfargs ,fname ,(format "%s" (or page 1))))
(defun find-dvipage (fname &optional page &rest rest)
(find-bgprocess (ee-dvipage fname page)))
(defun find-pspage (fname &optional page &rest rest)
(find-bgprocess (ee-pspage fname page)))
(defun find-xpdfpage (fname &optional page &rest rest)
(find-bgprocess (ee-xpdfpage fname page)))
(defun find-pdftotext (fname &rest rest)
(apply 'find-sh (format "pdftotext -layout %s -" fname) rest))
(defun find-pstotext (fname &rest rest)
(apply 'find-sh (format "cat %s | pstotext" fname) rest))
(defun find-zpstotext (fname &rest rest)
(apply 'find-sh (format "zcat %s | pstotext" fname) rest))
(defun ee-code-ps (code psfile)
(format "
(defun find-%spage (&optional n &rest comments) (interactive)
(find-pspage %S n))
" code psfile))
(defun ee-code-dvi (code dvifile)
(format "
(defun find-%spage (&optional n &rest comments) (interactive)
(find-dvipage %S n))
" code dvifile))
(defun ee-code-xpdf (code pdffile)
(format "
(defun find-%spage (&optional n &rest comments) (interactive)
(find-xpdfpage %S n))
" code pdffile))
(defun ee-code-pdftotext (code pdffile)
(format "
(defun find-%stext (&rest rest) (interactive)
(apply 'find-pdftotext %S rest))
" code pdffile))
(defun ee-code-pstotext (code psfile)
(format "
(defun find-%stext (&rest rest) (interactive)
(apply 'find-pstotext %S rest))
" code psfile))
(defun ee-code-zpstotext (code zpsfile)
(format "
(defun find-%stext (&rest rest) (interactive)
(apply 'find-zpstotext %S rest))
" code zpsfile))
(defun code-ps (c f) (eval (ee-read (ee-code-ps c f))))
(defun code-dvi (c f) (eval (ee-read (ee-code-dvi c f))))
(defun code-xpdf (c f) (eval (ee-read (ee-code-xpdf c f))))
(defun code-pdftotext (c f) (eval (ee-read (ee-code-pdftotext c f))))
(defun code-pstotext (c f) (eval (ee-read (ee-code-pstotext c f))))
(defun code-zpstotext (c f) (eval (ee-read (ee-code-zpstotext c f))))
(defun find-code-ps (c f) (find-estring-elisp (ee-code-ps c f)))
(defun find-code-dvi (c f) (find-estring-elisp (ee-code-dvi c f)))
(defun find-code-xpdf (c f) (find-estring-elisp (ee-code-xpdf c f)))
(defun find-code-pdftotext (c f) (find-estring-elisp (ee-code-pdftotext c f)))
(defun find-code-pstotext (c f) (find-estring-elisp (ee-code-pstotext c f)))
(defun find-code-zpstotext (c f) (find-estring-elisp (ee-code-zpstotext c f)))
'(
(defun find-dvipage-old (fname &optional n &rest ignore)
"Write into $EE a command that opens the dvi file FNAME at page N.
The command is \"xdvi +N FNAME\".
See `eev'."
(interactive "fDVI file: ")
(let ((command (format "xdvi +%d %s &" (or n 1) fname)))
(eev command nil)
command))
(defun find-pspage-old (fname &optional n &rest ignore)
"Write into $EE a command that opens the ps/pdf file FNAME at page N.
The command is \"gv -page N FNAME\".
See `eev'."
(interactive "fPS or PDF file: ")
(let ((command (format "gv -page %d %s &" (or n 1) fname)))
(eev command nil)
command))
(defun find-dvipagenow (fname &optional page xdviargs)
"Launch an xdvi process browsing the dvi file FNAME, starting at PAGE.
The process is invoked like this: \"xdvi +PAGE $XDVIARGS FNAME\".
XDVIARGS is a list of strings - by default ().
It runs in background and its output (including error messages)
goes to the buffer \"*Messages*\"."
(interactive "fdvi file: ")
(apply 'start-process "xdvi" "*Messages*"
`("xdvi"
,@(if page (list (format "+%d" page)))
,@xdviargs
,(ee-expand fname))))
(defun find-pspagenow (fname &optional page gvargs)
"Launch a gv process browsing the ps or pdf file FNAME, starting at PAGE.
The process is invoked like this: \"gv --page=N $GVARGS FNAME\".
GVARGS is a list of strings - by default ().
It runs in background and its output (including error messages)
goes to the buffer \"*Messages*\"."
(interactive "fPS or PDF file: ")
(apply 'start-process "gv" "*Messages*"
`("gv"
,@(if page (list (format "--page=%d" page)))
,@gvargs
,(ee-expand fname))))
(defalias 'find-dvipage 'find-dvipagenow)
(defalias 'find-pspage 'find-pspagenow)
(defalias 'eebg-xdvi 'find-dvipagenow) (defalias 'eebg-gv 'find-pspagenow)
(defun code-ps (code psfile)
"Define a function `find-CODEpage' as a hyperlink to a page in PSFILE.
See `find-pspage', `code-c-d' and `code-dvi'.
An example:\n
(code-ps \"foo\" \"/tmp/bar.ps\")\n
runs:\n
(defun find-foopage (&optional n &rest comments)
(interactive)
(find-pspage \"/tmp/bar.ps\" n))"
(ee-eval-read-format
"(defun find-%spage (&optional n &rest comments) (interactive)
(find-pspage %S n))"
code psfile))
(defun code-dvi (code dvifile)
"Define a function `find-CODEpage' as a hyperlink to a page in DVIFILE.
See `find-dvipage', `code-c-d' and `code-ps'.
An example:\n
(code-dvi \"foo\" \"/tmp/bar.dvi\")\n
runs:\n
(defun find-foopage (&optional n &rest comments)
(interactive)
(find-dvipage \"/tmp/bar.dvi\" n))"
(ee-eval-read-format
"(defun find-%spage (&optional n &rest comments) (interactive)
(find-dvipage %S n))"
code dvifile))
)
(defun ee-message (object)
"An obsolete hack to debug functions bound to keys. See the code."
(message "%S" object)
object)
(defun ee-message-maybe (object)
"An obsolete hack to debug functions bound to keys. See the code."
(if show-it (message "%S" object))
object)
(defalias 'ee-maybe-showing-it 'ee-message-maybe)
(defun ee-stuff-around-point (chars &optional show-it)
(interactive "MChars: \np") (ee-message-maybe
(save-excursion
(let* ((e (progn (skip-chars-forward chars) (point)))
(s (progn (skip-chars-backward chars) (point))))
(buffer-substring s e)))))
(defun ee-debpkgname-around-point (&optional show-it)
"Return the name of the Debian package around point.
This function is not very smart."
(interactive "p")
(ee-stuff-around-point "a-z0-9-+." show-it))
(defun ee-debpkgname-ask (&optional prompt show-it)
"Ask for the name of a Debian package; the default is the debpkgname at point."
(interactive (list nil t))
(ee-message-maybe
(read-string (or prompt "Debian package name: ")
(ee-debpkgname-around-point))))
(defun ee-manpagename-around-point (&optional show-it)
"Return the manpagename around point.
This function is not very smart - it doesn't understand section names."
(interactive "p")
(ee-stuff-around-point "A-Za-z0-9-+_:." show-it))
(defun ee-manpagename-ask (&optional prompt show-it)
"Ask for the name of a manpage; the default is the manpage name at point."
(interactive (list nil t))
(ee-message-maybe
(read-string (or prompt "Manpage: ")
(ee-manpagename-around-point))))
(defun find-Package (fname &optional packagename &rest pos-spec-list)
"Hyperlink to \"Package: \" achors in Debian package control files.
See: `find-status', `find-available', (find-man \"grep-dctrl\")"
(find-fline fname)
(apply 'ee-goto-position
(if packagename (format "\nPackage: %s\n" packagename))
pos-spec-list))
(defun find-status (packagename &rest pos-spec-list)
"Hyperlink to the info about the package PACKAGENAME in /var/lib/dpkg/status.
This is Debian-specific. See `find-Package'."
(interactive (list (ee-debpkgname-ask)))
(apply 'find-Package "/var/lib/dpkg/status" packagename pos-spec-list))
(defun find-available (packagename &rest pos-spec-list)
"Hyperlink to the info about the package PACKAGENAME in /var/lib/dpkg/available.
This is Debian-specific. See `find-Package'."
(interactive (list (ee-debpkgname-ask)))
(apply 'find-Package "/var/lib/dpkg/available" packagename pos-spec-list))
(defun find-grep-status (grepargs &rest pos-spec-list)
(interactive "sgrep-status ")
(apply 'find-sh (concat "grep-status " grepargs) pos-spec-list))
(defun find-grep-available (grepargs &rest pos-spec-list)
(interactive "sgrep-available ")
(apply 'find-sh (concat "grep-available " grepargs) pos-spec-list))
(defun