Warning: this is an htmlized version!
The original is across this link,
and the conversion rules are here.
;;; eev-extras.el --- experimental extra features for eev.el.

;; Note, 2004mar25: this file is not loaded anymore.
;; But I still have some old files in cp850 here and there and
;; I may need some of functions here in the future.

;; The Elisp material here can be roughly divided into eight parts:

;;  1) enhanced or experimental versions for functions in eev.el.
;;     Contains the bloated ee-goto-position, the bloated find-w3,
;;     and more flexible definitions for eelatex and eelatex-file.
;;     «.find-w3»		(to "find-w3")
;;     «.new_goto-position»	(to "new_goto-position")
;;     «.eelatex»		(to "eelatex")
;;     «.eelatex-file»		(to "eelatex-file")
;;
;;  2) Extra hyperlink functions, not too weird: `to' and `back'.
;;     «.to_and_back»		(to "to_and_back")
;;
;;  3) gdbk-mode and the gdbk-xxxdb family of functions, for
;;     hyperlinks that activate debuggers.
;;     (oops, these functions have moved to:) (find-angg "eegdb.el")
;;     «.gdbk-mode»		(to "gdbk-mode")
;;     «.gdbk-hyperlinks»	(to "gdbk-hyperlinks")
;;     «.eeg_in_emacs»		(to "eeg_in_emacs")
;;
;;  4) Functions to insert hyperlinks into the current buffer.
;;     «.macros»		(to "macros")
;;     «.mkto»			(to "mkto")
;;
;;  5) Support for entering codepage 850 characters (for when you
;;     can't use a hacked console keytable ;-).
;;     «.tr»			(to "tr")
;;
;;  6) Leftovers from my glyph stuff (that went to another file). 
;;     «.leftovers_glyphs»	(to "leftovers_glyphs")
;;
;;  7) Support for using both the 850math and latinmath charsets.

;;  8) Misc:
;;     «.ee-load-back»		(to "ee-load-back")





(defmacro if-gnu-emacs (&rest body)
  (if (string-match "GNU Emacs" (emacs-version)) (cons 'progn body)))


;; «find-w3»  (to ".find-w3")
;; Redefined with support for netscape:
;;
(defun find-w3 (localurl &rest pos-spec-list)
  "Like `find-fline', but will open LOCALURL using W3 or other browser.
If the value of `ee-arg' is 1 then use Lynx (via `eev') instead of W3.
The standard way to set `ee-arg' is to execute this function with
`\\[end-of-line-then-eval-last-sexp]' instead of with `\\[eval-last-sexp]'.\n
It is easy to add support for more browsers to this function by
redefining it at your .emacs with a richer `cond'. :-)"
  (cond ((eq ee-arg 1)
	 (ees (format "lynx %s\n" localurl) nil))
	((eq ee-arg 2)
	 (eev (format "edrxnetscape %s &\n" localurl) nil))
	(t (w3-open-local localurl)
	   (apply 'ee-goto-position pos-spec-list))))

;;;;
;;;; «new_goto-position»  (to ".new_goto-position")
;;;; 
;;
;; This is the bloated & ugly version of ee-goto-position that was
;; as mentioned in eev.el at:
;;   (find-angg "eev.el" "find-")
;;
;; With this version you can run, for example,
;;
;;   (find-drfcfile "rfc1812.txt.gz"  "[page 47]"  '* 2 "host"  3)
;;
;; which means: open the file rfc1812.txt.gz from the directory
;; /usr/doc/doc-rfc/all-included-rfcs/, then search for the first
;; occurrence of "[page 47]", then search two times for "host", then
;; go down 3 lines.
;;
;; A number ("n", say) in the pos-spec-list is always interpreted as
;; "descend n lines", except if it is the first element of the
;; pos-spec-list, a case in which we want to interpret is as meaning
;; "go to the line n" -- that is, "descend n-1 lines from the top".
;; That's part of the reason why the new definition of
;; ee-goto-position is so ugly; the rest is due to my incompetence.
;;
;; We need to load eev.el before these defuns, or else they'll be
;; overwritten...

;; Recursive version:
;;
(defun process-pos-spec-list (pos-spec-list)
  (let ((pos-spec1 (car pos-spec-list)))
    (cond ((null pos-spec-list))	; end of list: do nothing
	  ((numberp pos-spec1)		; n: descend n lines
	   (forward-line pos-spec1)
	   (process-pos-spec-list (cdr pos-spec-list)))
	  ((stringp pos-spec1)		; str: search for str
	   (search-forward pos-spec1)
	   (process-pos-spec-list (cdr pos-spec-list)))
	  ((eq '* pos-spec1)		; '* n str: search n times for str
	   (let ((n (nth 1 pos-spec-list))
		 (s (nth 2 pos-spec-list))
		 (rest (nthcdr 3 pos-spec-list)))
	     (process-pos-spec-list (append (make-list n s) rest))))
	  (t (error
	      "%S: Only numbers, strings and \"'* n s\" are supported now"
	      pos-spec-list)))))

;; Disabled!!!
'(defun ee-goto-position (&rest pos-spec-list)
   (if pos-spec-list
       (progn (goto-char (point-min))
	      (if (numberp (car pos-spec-list))
		  (process-pos-spec-list (cons (1- (car pos-spec-list))
					       (cdr pos-spec-list)))
		(process-pos-spec-list pos-spec-list)))))



; «eelatex»  (to ".eelatex")
; «eelatex-file»  (to ".eelatex-file")
; 2000oct30: experimental version, mainly for Kalyan, using rexdvi.
; (find-angg "eev.el" "eelatex")
; (find-angg ".zshrc" "rexdvi")

;(setq eelatex-pre "\\input tese2.sty\n\\begin{document}\n")
(setq eelatex-pre "\\input edrx.sty\n\\begin{document}\n")
(setq eelatex-post "\n\\end{document}\n")
(setq eelatex-file "~/LATEX/tmp.tex")
(setq eelatex-eevscript "cd ~/LATEX/; rm tmp.dvi; make tmp.dvi\nrexdvi tmp.dvi\nsavetmptex")

; (find-etag "save-buffer")
; (find-elnode "Buffer Modification" "set-buffer-modified-p")
; We save the file again because sometimes the TeXing command
; is invoked by make, and then we need the file to be touched.
;
(defun eelatex-file ()
  "Like `eelatex-bounded', but on the whole file."
  (set-buffer-modified-p t) (save-buffer)
  (eev eelatex-eevscript nil)
  (message "eelatex-file: wrote %s and %s" (buffer-file-name) ee-file))





;;;;;
;;;;; «macros»  (to ".macros")
;;;;; (find-es "emacs" "saving_emacs_macros")
;;;;; Being superseded by: (find-eevfile "eev-links.el")
;;;;;
;
(defun eemacro-manline () (interactive)
  (setq last-kbd-macro
	(read-kbd-macro
	 "C-a # SPC (eeman SPC \" 18*<deletechar> <right>
	  <deletechar> SPC C-e 5*DEL \") C-a <down>")))
;
(defun eemacro-fline () (interactive)
  (setq last-kbd-macro
	(read-kbd-macro
	 "# SPC (find-fline SPC \" C-e \") C-a <down>")))

; «mkto»  (to ".mkto")
; (find-es "emacs" "mkto")
; I still have some LaTeX texts in 850math; this functions supports them too.
(defun mkto () (interactive)
  (let (beg end) (end-of-line) (setq end (point))
       (beginning-of-line) (setq beg (point))
       (save-restriction
	 (narrow-to-region beg end)
	 (if (equal ee-charset-indicator indicator-850math)
	     (replace-regexp "^\\(.+ \\)\\([!-~]+\\)$"
			     "% .\\2\t(to \"\\2\")\n\\\&  (to \".\\2\")")
	   (replace-regexp "^\\(.+ \\)«\\([!-~]+\\)»$"
			   "# «.\\2»\t(to \"\\2\")\n\\\&  (to \".\\2\")"))
       (beginning-of-line))))






;;;;;
;;;;; iso-accents changes to supports math fonts. Old comments:
;;;;
;;;; This block is made of new stuff written around 2000oct22.
;;;;
;;;; I have managed to port my math font to X, and then the main
;;;; problem became how to enter all my nice characters in an Emacs
;;;; running on X.
;;;;
;;;; This is work in progress and I think it won't work (at least for
;;;; now) outside of Emacs' unibyte mode. Also it is only being tested
;;;; on an Emacs 20.7.2 running on Debian Potato.
;;;;

;; First some conversion functions to let me use the same accent table
;; in both latinmath and 850math.  Note: they are new and aren't being
;; used by any other function yet.
;; «tr»  (to ".tr")

;; (find-es "emacs" "iso-accents")
;; (find-angg "compose.el")

(setq array-latinmath-to-850
  [213 159 242 254 196 179 218 191 192 217 195 180 194 193 197 205
   186 201 187 200 188 204 185 203 202 206 223 220 219 176 177 178
   255 173 189 156 207 190 221 245 249 184 166 174 170 240 169 238
   248 241 253 252 239 230 244 250 247 251 167 175 172 171 243 168
   183 181 182 199 142 143 146 128 212 144 210 211 222 214 215 216
   209 165 227 224 226 229 153 158 157 235 233 234 154 237 232 225
   133 160 131 198 132 134 145 135 138 130 136 137 141 161 140 139
   208 164 149 162 147 228 148 246 155 151 163 150 129 236 231 152])

(setq array-850-to-latinmath
  [199 252 233 226 228 224 229 231 234 235 232 239 238 236 196 197
   201 230 198 244 246 242 251 249 255 214 220 248 163 216 215 129
   225 237 243 250 241 209 170 186 191 174 172 189 188 161 171 187
   157 158 159 133 139 193 194 192 169 150 144 146 148 162 165 135
   136 141 140 138 132 142 227 195 147 145 152 151 149 143 153 164
   240 208 202 203 200 128 205 206 207 137 134 156 155 166 204 154
   211 223 212 210 245 213 181 254 222 218 219 217 253 221 175 180
   173 177 130 190 182 167 247 184 176 168 183 185 179 178 131 160])

(defun tr (arr obj)
  (cond ((numberp obj) (if (< obj 128) obj (aref arr (- obj 128))))
        ((stringp obj)
	 (mapconcat (function (lambda (c) (format "%c" (tr arr c)))) obj ""))
	((t (error "tr what?")))))
(defun tr-850-to-latinmath (obj) (tr array-850-to-latinmath obj))
(defun tr-latinmath-to-850 (obj) (tr array-latinmath-to-850 obj))

(setq do-tr nil)

(defun tr-850-to (obj &optional when)
  (cond ((eq when t) (tr-850-to-latinmath obj))
        ((eq when nil) obj)
        (t (if do-tr (tr-850-to-latinmath obj) obj))))
(defun tr-to-850 (obj &optional when)
  (cond ((eq when t) (tr-latinmath-to-850 obj))
        ((eq when nil) obj)
        (t (if do-tr (tr-latinmath-to-850 obj) obj))))






;;;;;
;;;;; Leftovers from my glyph stuff (old comments, etc.)
;;;;; «leftovers_glyphs»  (to ".leftovers_glyphs")
;;;;;

;; Note that the current glyph functions went to:
;; (find-angg "glyphs.el")


;; Functions to detect and avoid an Emacs bug.
;; Glyphs in GNU Emacs always ranged between badly-documented and
;; not documented at all, and I've been told that support for them
;; will change a lot in Emacs21. But I use them because they're
;; funny and practical, not because they're standard... :-)
;;
;; Note: I use a hacked defkeymap file in which typing "C-," sends
;; a "C-q", and "C-." is the compose char; so, for example, typing
;; "C-, C-. ~ a" inserts a tilded "a", and (my defkeymap and my VT
;; font are REALLY hacked) typing "C-, C-. - o" inserts the sign
;; for linear implication in linear logic, that is like a "-o" and
;; is formally (!) called "lollipop".
;;

; *
; 
; aÆo
; ä

;; «xmath»  (to ".xmath")
;; (find-angg ".zshrc" "X")
;(defun xmath-disptable () (interactive)
;  (standard-display-8bit 128 254)
;  (standard-display-8bit 1 8)
;  (standard-display-8bit 11 31)
;  (setglyphs-X
;   15  'eev-red ?
;   174 'eev-green 174
;   175 'eev-green 175))

; (find-es "x" "X_with_mathfont")
;(defun xmath   () (interactive) (set-frame-font "mathvga")  (xmath-disptable))
;(defun xmathx2 () (interactive) (set-frame-font "mathvgax2") (xmath-disptable))

; (set-frame-font "mathvga")
; (set-frame-font "mathvgax2")

;; (find-es "emacs" "old_glyph_stuff")







;; (find-angg "glyphs.el")









;;;;;
;;;;; Support for switching between the 850/850math and
;;;;; latin1/latinmath charsets
;;;;;

;; The idea is to use a line like `ee-charset-indicator: "c"' in the
;; local variables section to indicate which charset to use for a
;; file; the char 165 (0245 octal) will mean 850/850math, and 209
;; (0321 octal) will mean latin1/latinmath.
;;
;; (format "850: %d=0%o (%c)  latin: %d=0%o (%c)" 165 165 165 209 209 209)
;; (find-es "charsets" "tcs_latin1-850")

(setq ee-charset-indicator nil)

(setq indicator-850math   "\245")
(setq indicator-latinmath "\321")

(code-c-d "vtutil" "$HOME/vtutil/")

(defun cs-set-font-psf (psffname &optional buffer)
  (call-process "consolechars" nil buffer nil "-H" "8" "-f" psffname))
(defun cs-loadkeys (keymapfname &optional buffer)
  (call-process "loadkeys" nil buffer nil keymapfname))

;; UGLY!!! We are setting standard-display-table instead of doing
;; something buffer-local...
;;
(defun cs-set-psf-keymap-disptable (psf keymap disptable &optional buffer)
  (cs-set-font-psf (ee-vtutilfile psf) buffer)
  (cs-loadkeys (ee-vtutilfile keymap) buffer)
  (setq standard-display-table disptable))

(defun cs-850 (&optional buffer)
  (cs-set-psf-keymap-disptable
   "math850.8.psf" "math850.map" disptable-850 buffer)
  (message "Using math850"))
(defun cs-latin (&optional buffer)
  (cs-set-psf-keymap-disptable
   "mathlatin.8.psf" "mathlatin.map" disptable-latin buffer)
  (message "Using latinmath"))

(defun set-charset (indicator)
  (cond ((equal indicator indicator-850math) (cs-850 "*Messages*"))
	((equal indicator indicator-latinmath) (cs-latin "*Messages*"))
	(t (error "Strange ee-charset-indicator: %S" ee-charset-indicator))))

(defun cs (&optional arg) (interactive "P")
  (cond ((eq arg 0) (set-charset indicator-850math))
        ((eq arg 1) (set-charset indicator-latinmath))
        ((eq arg nil) (set-charset ee-charset-indicator) (normal-mode))
	(t (error "Arg to `cs' must be 0, 1 or nil"))))




;; «ee-load-back»  (to ".ee-load-back")
;; (find-eev "eev-misc.el" "ee-load-back")

;; (find-eevfile "eev-all.el")
;; (find-eev "eev-all.el" "bounded_support")
;; (find-eev "eev-gud.el" "eeg_in_emacs")
;; (find-elnode "Text Comparison")
;; (find-elnode "Creating Strings")

;; (ee-load-back ee-delimiter-hash "$EE" "set -v\n" "\nset +v")






; (find-elnode "Backquote")
; (find-etag "what-line")
; (find-etag "describe-key")
; (describe-key "\M-B")
; (describe-key "\M-b")





;; Local Variables:
;; ee-anchor-format:     "«%s»"
;; ee-charset-indicator: "Ñ"
;; End:

;;; eev-extras.el ends here