*
(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."
(when pos-spec
(cond ((numberp pos-spec) (goto-char (point-min)) (forward-line (1- pos-spec)))
((stringp pos-spec) (goto-char (point-min)) (search-forward pos-spec))
(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\"."
(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-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 code-c-d (c d &rest rest)
(eval (read (ee-concat (apply 'ee-code-c-d c d rest)))))
(defun find-code-c-d (c d &rest rest)
"Use this to inspect the code that a `code-c-d' would run."
(find-estring-elisp (ee-concat (apply 'ee-code-c-d c d rest))))
(defun ee-concat (list &optional sep) (mapconcat 'identity list (or sep "")))
(defun ee-code-c-d (c d &rest rest)
(cons (format "
(setq ee-%sdir %S)
(defun ee-%sfile (str)
(concat (ee-expand ee-%sdir) str))
(defun find-%sfile (str &rest pos-spec-list)
(interactive (list \"\"))
(apply 'find-fline (ee-%sfile str) pos-spec-list))
" c d c c c c) (ee-code-c-d-rest rest)))
(defun ee-code-c-d-rest (rest)
(if rest
(let ((fun (cdr (assq (car rest) code-c-d-keywords))))
(if (not fun)
(error "In (code-c-d %S ...): not a keyword: %S"
c (car rest)))
(apply fun (cdr rest)))))
(defvar code-c-d-keywords nil)
(setq code-c-d-keywords
'((:info . ee-code-c-d-:info)
(:anchor . ee-code-c-d-:anchor)))
(defun ee-code-c-d-:info (info &rest rest)
(cons (format "
(defun find-%snode (page &rest pos-spec-list)
(interactive (list \"\"))
(apply 'find-node (format \"(%s)%%s\" page) pos-spec-list))
" c info) (ee-code-c-d-rest rest)))
(defun ee-code-c-d-:anchor (&rest rest)
(cons (format "
(defun find-%s (str &rest pos-spec-list)
(apply 'find-anchor (ee-%sfile str) pos-spec-list))
" c c) (ee-code-c-d-rest rest)))
(add-to-alist 'code-c-d-keywords '(:linfo . ee-code-c-d-:linfo))
(defun ee-code-c-d-:linfo (linfo &rest rest)
(cons (format "
(defun find-%snode (page &rest pos-spec-list)
(interactive (list \"\"))
(apply 'find-node (format \"(%%s)%%s\" page)
(ee-expand (ee-%sfile %S))
pos-spec-list))
" c c linfo) (ee-code-c-d-rest rest)))
(defun find-eoutput-rerun (buffer-name code &rest pos-spec-list)
(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)
(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)
(apply 'find-eoutput-rerun "*string*" `(insert ,string) pos-spec-list))
(defun find-estring-elisp (string &rest pos-spec-list)
(apply 'find-eoutput-rerun "*string*"
`(progn (insert ,string) (emacs-lisp-mode)) pos-spec-list))
(defun find-sh (command &rest pos-spec-list)
(apply 'find-eoutput-reuse
(ee-no-trailing-nl command)
`(insert (shell-command-to-string ,command))
pos-spec-list))
(defun find-sh00 (command) (shell-command-to-string command))
(defun find-sh0 (command) (ee-no-trailing-nl (find-sh00 command)))
(defun find-man (manpage &rest pos-spec-list)
(apply 'find-sh (format "PAGER=cat man %s | col -bx" manpage)
pos-spec-list))
(defun ee-split (str) (if (stringp str) (split-string str "[ \t]+") 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 find-callprocess-ne (program-and-args &rest pos-spec-list)
(apply 'find-eoutput-reuse (ee-unsplit program-and-args)
`(insert (find-callprocess00-ne ',program-and-args))
pos-spec-list))
(defun find-callprocess (program-and-args &rest pos-spec-list)
(apply 'find-eoutput-reuse (ee-unsplit program-and-args)
`(insert (find-callprocess00 ',program-and-args))
pos-spec-list))
(defun ee-eval-last-sexp ()
"Like C-x C-e, but does not start the debugger on errors."
(interactive)
(let ((debug-on-error nil))
(eval-last-sexp nil)))
(defun ee-eval-sexp-eol ()
"Like C-e C-x C-e, but does not start the debugger on errors."
(interactive)
(end-of-line)
(let ((debug-on-error nil))
(eval-last-sexp nil)))
(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 eelatex-eevscript "cd $EEVTMPDIR/; latex tmp.tex && xdvi tmp.dvi &"
"See `eelatex'.")
(defun ee-se-to-string (s e)
"Convert the pair (S E) to a string - see `write-region' for the rules."
(cond ((numberp s) (buffer-substring-no-properties s e))
((stringp s) s)))
(defun ee-write-string (str &optional altfile)
"Write STR to ALTFILE, or to `ee-file' if ALTFILE is nil."
(write-region str nil (ee-expand (or altfile ee-file)))
(format "Wrote %s" (or altfile ee-file)))
(defun ee-write (s e pre post &optional altfile)
"Write PRE+(ee-se-to-string S E)+POST to ALTFILE, or to `ee-file'.
PRE and POST must be strings. See `ee-se-to-string' and `ee-write-string'."
(ee-write-string (concat pre (ee-se-to-string s e) post)
altfile))
(defun eev (s &optional e altfile)
"Save the region to `ee-file'"
(interactive "r")
(ee-write-string (ee-se-to-string s e) altfile))
(defun eelatex (s &optional e)
"Save the region to `ee-file-tex', then save `eelatex-eevscript' to `ee-file'."
(interactive "r")
(ee-write s e "" "" ee-file-tex)
(eev eelatex-eevscript nil)
(format "eelatex: wrote %s and %s" ee-file-tex ee-file))
(defface eev-glyph-face-red '((t (:foreground "red")))
"Face used for the red star glyph (char 15).")
(defun ee-glyph (char &optional face)
(logior char (ash (if face (face-id face) 0) 19)))
(defun eev-set-glyph (pos &optional char face)
(aset standard-display-table pos
(if char (vector (ee-glyph char face)))))
(eev-set-glyph ?\^O ?* 'eev-glyph-face-red)
(defvar ee-flash-spec '(highlight 0.75))
(defun eeflash (s e)
"Highlight temporarily the region between S and E. See `ee-flash-spec'."
(interactive "r")
(if (numberp s)
(let ((ovl (make-overlay s e))
(face (car ee-flash-spec))
(duration (cadr ee-flash-spec)))
(overlay-put ovl 'face face)
(run-at-time duration nil 'delete-overlay ovl)))
(ee-se-to-string s e))
(defvar eeb-defaults '(eev "\n#*\n"))
(defun eeb-default ()
"Run the default action on a delimited region around point.
The default action is determined by the entries in `eeb-defaults'.
See `eeb-define'."
(interactive)
(let* ((fun (nth 0 eeb-defaults))
(delim (nth 1 eeb-defaults))
(s (ee-search-backward edelim))
(e (ee-search-forward edelim)))
(eeflash s e)
(funcall fun s e)))
(defun ee-eeb-define (eeb-fun fun delim)
"Returns code (as as string) to define EEB-FUN as a wrapper around FUN."
(read (format "
(defun %S ()
(interactive)
(setq eeb-defaults '(%S %S))
(eeb-default))" eeb-fun fun delim))))
(defun eeb-define (eeb-fun fun delim)
"Define EEB-FUN as a wrapper around FUN."
(eval (read (ee-eeb-define eeb-fun fun delim))))
(defun find-eeb-define (eeb-fun fun delim)
"Show the code that an `eeb-define' with the same args would run."
(find-estring-elisp (ee-eeb-define eeb-fun fun delim)))
(eeb-define 'eev-bounded 'eev "\n#*\n")
(eeb-define 'eegdb-bounded 'eegdb "\n#*\n")
(eeb-define 'eelatex-bounded 'eelatex "\n%*\n")
(eeb-define 'eeeval-bounded 'eeeval "\n;;*\n")
(eeb-define 'eeb-eval 'eeeval "\n;;*\n")
(setq pop-up-windows nil))
(defvar eev-mode-map nil)
(if eev-mode-map
()
(setq eev-mode-map (make-sparse-keymap))
(define-key eev-mode-map "\M-E" 'ee-eval-last-sexp) (define-key eev-mode-map "\M-e" 'ee-eval-sexp-eol) (define-key eev-mode-map "\M-k" 'kill-this-buffer) (define-key eev-mode-map "\M-K" 'bury-buffer) (define-key eev-mode-map [f3] 'eeb-default)
(define-key eev-mode-map [f8] 'eepitch-this-line)
(define-key eev-mode-map [f9] 'eechannel-this-line)
(define-key eev-mode-map [f12] 'eesteps-do-step)
(define-key eev-mode-map "\M-h\M-f" 'find-efunction-links) )