No subject



;;; -*- Mode: emacs-lisp ;Minor-mode: auto-fill -*-


;;; Denne fila lager en spesialisert emacs-omgivelse for arbeid med
;;; Common-Music.  =


(setq load-path (cons "/local/gnu/lib/emacs/site-lisp/w3" load-path))
(setq load-path
      (cons (expand-file-name "~andersvi/usr/gnu/emacs/lisp")
		  load-path))

(setq load-path (append load-path (list "~andersvi/usr/gnu/calc-2.02c")))=



(require 'cl)
;;(require 'title)
(require 'easymenu)
(require 'disp-table)
(require 'advice)
;;(require 'mouse-extras)                                           =

;;(require 'tinyxreg)


(load-library "loaddefs")		;innlasting av mye defaults
(require 'inf-lisp)
(load-library "ansi-doc")
;;(load-library "netscape")             ; lagt inn i denne fila.
(load-library "xf-load")

(if (not transient-mark-mode) (transient-mark-mode 1))

;;; litt spesialisering av taster, lisp-prompt osv.:

;;(setq initial-frame-alist
;;      '((top . -1) (left . -1) (width . 85)
;;	(height . 50) (background-color . "grey89")
;;	(font . "-sgi-screen-medium-r-normal--15-150-72-72-m-80-iso8859-1")
;;	(icon-type . t)))

(setq display-time-day-and-date t)
(display-time)
(setq line-number-mode t)
(put 'eval-expression 'disabled nil)
(setq lpr-command "/local/bin/ppr")

;; 8-bits tegn.
(require 'iso-insert)
(set-input-mode t nil '8bit)
(require 'iso-syntax)
(standard-display-european 1)

;;(global-set-key (quote [C-M-mouse-2]) (quote mouse-menu-choose-yank))
(global-set-key "=18=02" 'electric-buffer-list)

(require 'dired-x)
;; Set dired-x variabler her.  For eksempel:

(setq dired-guess-shell-alist-user
      (list (list "\\.aif[cf]$" "playaiff" "sfplay" "soundeditor" "sfinfo=
" "sfconvert")
	    (list "\\.snd$" "playaiff" "sfplay" "sfinfo" "soundeditor" "sfconver=
t")
	    (list "\\.e*ps" "ghostview" "sonataview" "ppr" "xv")))

(setq dired-listing-switches "-lo")
(setq dired-guess-shell-gnutar nil)
(setq dired-omit-files-p nil)
(setq dired-omit-files
    (concat dired-omit-files "\\|^\\..+$"))
(setq dired-x-hands-off-my-keys nil)
(dired-x-bind-find-file)

;;; Denne muliggj=F8r bakgrunnsjobber i dired f.eks.

(load-library "background")
(define-key dired-mode-map "&" 'dsg-dired-do-shell-command-bg)

(defun dsg-dired-do-shell-command-bg ()
  "Background shell commands for dired"
  (interactive)
  (unwind-protect
      (progn
	(fset 'dsg-real-shell-command (symbol-function 'shell-command))
	(fset 'shell-command (symbol-function 'background))
	(call-interactively 'dired-do-shell-command))
    (progn
      (fset 'shell-command (symbol-function 'dsg-real-shell-command))
      (fmakunbound 'dsg-real-shell-command)))
  nil) ; return nil to be consistent - not sure if really necessary

(global-set-key "=A6" (quote dsg-do-shell-command-bg))

(defun dsg-do-shell-command-bg ()
  "Background shell commands for dired"
  (interactive)
  (unwind-protect
      (progn
	(fset 'dsg-real-shell-command (symbol-function 'shell-command))
	(fset 'shell-command (symbol-function 'background))
	(call-interactively 'shell-command))
    (progn
      (fset 'shell-command (symbol-function 'dsg-real-shell-command))
      (fmakunbound 'dsg-real-shell-command)))
  nil) ; return nil to be consistent - not sure if really necessary


(defun my-dired-f-key (arg)
  "Kills previous dir buffer if dired-find-file entered new directory.
Else works like normal 'f'
"
  (interactive "P")
  (let ((ob (current-buffer)))		;original buffer
    (if (not arg)
	(dired-advertised-find-file)
      (save-excursion
	(dired-advertised-find-file)	;move to dir or load a file ?
	;;  What happened
	;;  a) where are we now, still in dired ?
	;;  b) user requested same dir, "."
	(if (or (null (string-match "dired" mode-name))
		(equal ob (current-buffer)))	=

	    nil
	  (set-buffer ob)
	  (kill-buffer ob))
	))))

(add-hook 'dired-mode-hook
     '(lambda ()
	(local-set-key "f" 'my-dired-f-key)))

(setq background-show nil)

(defun insert-anfoersels-tegn (arg)
  "Setter inn doble anfoersels-tegn paa samme maate som paranteser etc."
  (interactive "P")
  (if arg (setq arg (prefix-numeric-value arg))
    (setq arg 0))
  (or (eq arg 0) (skip-chars-forward " \t"))
  (insert ?\")
  (save-excursion
    (or (eq arg 0) (forward-sexp arg))
    (insert ?\"))
  (forward-sexp arg))

(define-key esc-map "\"" 'insert-anfoersels-tegn)

(global-set-key "=03=13" (quote shell))

;; Mere fleksible s=F8keoperasjoner.  Ned i underkataloger osv.

(autoload (function igrep) "igrep"                   =

   "*Run `grep' to match EXPRESSION in FILES..." t)  =

(autoload (function egrep) "igrep"                   =

   "*Run `egrep'..." t)                              =

(autoload (function fgrep) "igrep"                   =

   "*Run `fgrep'..." t)                              =

(autoload (function igrep-recursively) "igrep"       =

   "*Run `grep' recursively..." t)                   =

(autoload (function egrep-recursively) "igrep"       =

   "*Run `egrep' recursively..." t)                  =

(autoload (function fgrep-recursively) "igrep"       =

   "*Run `fgrep' recursively..." t)                  =



(autoload 'alarm	   "alarm" "pop-opp alarm til spesifisert tid" t)


;;;Calc autoloads

;;; Commands added by calc-private-autoloads on Mon Nov 28 12:03:09 1994.=

(autoload 'calc-dispatch	   "calc" "Calculator Options" t)
(autoload 'full-calc		   "calc" "Full-screen Calculator" t)
(autoload 'full-calc-keypad	   "calc" "Full-screen X Calculator" t)
(autoload 'calc-eval		   "calc" "Use Calculator from Lisp")
(autoload 'defmath		   "calc" nil t t)
(autoload 'calc			   "calc" "Calculator Mode" t)
(autoload 'quick-calc		   "calc" "Quick Calculator" t)
(autoload 'calc-keypad		   "calc" "X windows Calculator" t)
(autoload 'calc-embedded	   "calc" "Use Calc inside any buffer" t)
(autoload 'calc-embedded-activate  "calc" "Activate =3D>'s in buffer" t)
(autoload 'calc-grab-region	   "calc" "Grab region of Calc data" t)	=

(autoload 'calc-grab-rectangle	   "calc" "Grab rectangle of data" t)
(autoload 'edit-kbd-macro	   "macedit" "Edit Keyboard Macro" t)
(autoload 'edit-last-kbd-macro	   "macedit" "Edit Keyboard Macro" t)
(autoload 'read-kbd-macro	   "macedit" "Read Keyboard Macro" t)
(global-set-key "\e#" 'calc-dispatch)
;;; End of Calc autoloads.

(setq calc-info-filename "~andersvi/usr/gnu/calc-2.02c/calc.info")
(setq Info-directory-list (cons "~andersvi/usr/gnu/calc-2.02c/"
				Info-default-directory-list))


;;; HILIT kode:

(cond (nil;;(window-system
       (setq hilit-mode-enable-list  '();;'(lisp-mode inferior-lisp-mode)=

	     hilit-background-mode   'light
	     hilit-inhibit-hooks     nil
	     hilit-inhibit-rebinding nil)
	(hilit-set-mode-patterns
	 'browser-file-mode
	 '(("\\w*/" nil dired-directory)
	   ("\\w*\\\*" nil ForestGreen)
	   ("\\w*\\\@" nil dired-link)
	   ("\\w*\\\.gz\\>" nil VioletRed)
	   ("\\w*\\\.\\(lisp\\|c\\|el\\|tex\\)\\>" nil FireBrick)
	   ("\\w*\\\.\\(fasl\\|o\\|elc\\|dvi\\)\\>" nil SlateGray)
	   ("\\w*\\\.h\\>" nil Purple)))
	(add-hook 'browser-file-display-hook
	  (function (lambda ()
		      (hilit-highlight-region (point) (point-max) nil t))))
	(require 'hilit19)))



(defun find-ansi-doc ()
  "Find the documentation in the ansi draft on a particular function
or topic.   If there are several pieces of documentation then go through
them successively."
  (interactive)
  (let (x tem name lis first chap tmp-chap ans next)
    (or ansi-doc-alist
	(progn
	  (create-index-el-from-index-idx )
	  (load (concat ansi-doc-dir "/index.el"))))
    (setq name (completing-read "Dokumentasjon om: " ansi-doc-alist nil t=
))
    (progn  (setq ans nil)   (setq lis ansi-doc-alist)
	    (while lis
	      (cond ((equal (car  (car lis)) name)
		     (setq ans (append ans (cdr  (cdr (car lis)))))))
	      (setq lis (cdr lis))))
    (setq tem ans)
    (if (cdr tem) (setq first "First") (setq first ""))
    (print (car (car x)))
    (while tem
      (setq x (car tem))
      (setq chap (concat ansi-doc-dir
		  (downcase (format "/chap-%s.dvi"  (car x)))))
      (setq chap (maybe-gzip-to-tmp chap))
      (message "%s Doc in Chapter %s page %s)  .." first (car x) (cdr x))=

      (if (cdr tem) (setq first "Next") (setq next "Final"))
      (shell-command (concat "xdvi  -expert -xoffset .2 -yoffset -.2 "
			     " -paper 7.2x8.5 "
			     " -display "
			     (or x-display-name ":0")
			     "  -geometry -2-2 +" (+ (cdr x) 2)" "
			     chap
			     ;;" &"
			     ))
      (setq tem (cdr tem))))
  (message nil))


;;;;;;;;;;  Hjelpe tekster fra emacs: ;;;;;;;;;;;;;;

(defun cm-manual ()
  (interactive)
  (setq background-show nil)
  (unwind-protect
      (browse-url-netscape "http://www.notam.uio.no/internt/cm-sys/cm/doc=
/dict/Intro.html"))) =


(defun stella-manual ()
  (interactive)
  (setq background-show nil)
  (unwind-protect
      (browse-url-netscape "http://www.notam.uio.no/internt/cm-sys/cm/doc=
/tutorials/stella/toc.html")))

(defun clm-manual ()
  (interactive)
  (setq background-show nil)
  (unwind-protect
      (browse-url-netscape "http://www.notam.uio.no/internt/cm-sys/clm/cl=
m.html")))

(defun cmn-manual ()
  (interactive)
  (setq background-show nil)
  (unwind-protect
      (browse-url-netscape "http://www.notam.uio.no/internt/cm-sys/cmn/cm=
n.html")))

;;; sett inn div dokumentasjon i help-menyen

(define-key-after menu-bar-help-menu [Stella-dictionary]
  '("Stella innf=F8ring" . stella-manual) [Show Version])

(define-key-after menu-bar-help-menu [CM-dictionary]
  '("CM dokumentasjon" . cm-manual) [Stella-dictionary])

(define-key-after menu-bar-help-menu [CLM-dictionary]
  '("CLM dokumentasjon" . clm-manual) [CM-dictionary])

(define-key-after menu-bar-help-menu [CMN-dictionary]
  '("CMN dokumentasjon" . cmn-manual) [CLM-dictionary])

(define-key-after menu-bar-help-menu [CL-ANSI-dokumentasjon]
  '("Common Lisp dokumentasjon" . find-ansi-doc) [CMN-dictionary])

(define-key-after menu-bar-edit-menu [marker-alt]
  '("Marker hele bufferet" . mark-whole-buffer) 'clear)

(define-key-after menu-bar-edit-menu [finn-definisjon]
  '("Liste over definisjoner..." . imenu) 'search-fwd)

(defvar cm-help-file-dir "/hf/notam/u1/andersvi/cm-sys/nycm/acl/cm/stella=
/help/")

(load "/local/notam/kurs/lisp/sys/stella-help")
(pushnew "*Stella hjelp*" special-display-buffer-names)


;;; IMENU:

;;;; Load imenu index funksjon.  Man=F8vrer i et buffer ved hjelp av
;;;; menyer:

(load-library "imenu")

;;(autoload 'imenu "imenu" nil t)

;;(autoload 'imenu-add-to-menubar "imenu" nil t)

(global-set-key [M-S-down-mouse-3] (function imenu))


;;; tilpasset CM-arbeid

(defun imenu-cm--lisp-extract-index-name ()
  ;; Example of a candidate for `imenu-extract-index-name-function'.
  ;; This will generate a flat index of definitions in a lisp file.
  (save-match-data
    (and (looking-at
	  "(algo\\|(thre\\|(gene\\|(merg\\|(mute\\|(def")
	 (condition-case nil
	     (progn
	       (down-list 1)
	       (forward-sexp 2)
	       (let ((beg (point))
		     (end (progn (forward-sexp -1) (point))))
		 (buffer-substring beg end)))
	   (error nil)))))

(setf imenu-extract-index-name-function 'imenu-cm--lisp-extract-index-ind=
ex)

(defun imenu-cm--create-lisp-index ()
  ;; Example of a candidate for `imenu-create-index-function'.
  ;; It will generate a nested index of definitions.
  (let ((index-alist '())
	(index-funk-alist '())
	(index-var-alist '())
	(index-type-alist '())
	(index-unknown-alist '())
	(index-algo-alist '())
	(index-gen-alist '())
	(index-thread-alist '())
	(index-merge-alist '())
	(index-mute-alist '())
	(index-inst-alist '())
	prev-pos)
    (goto-char (point-max))
    (imenu-progress-message prev-pos 0)
    ;; Search for the function
    (while (beginning-of-defun)
      (imenu-progress-message prev-pos nil t)
      (save-match-data
	(and (looking-at
	      "(algo\\|(thre\\|(definst\\|(gene\\|(merg\\|(mute\\|(def\\|(set")
	     (save-excursion
	       (down-list 1)
	       (cond
		((looking-at "def\\(var\\|const\\)")
		 (forward-sexp 2)
		 (push (imenu-example--name-and-position)
		       index-var-alist))
		((looking-at "setf")
		 (forward-sexp 2)
		 (push (imenu-example--name-and-position)
		       index-var-alist))
		((looking-at "def\\(un\\|subst\\|macro\\|advice\\)")
		 (forward-sexp 2)
		 (push (imenu-example--name-and-position)
		       index-funk-alist))
		((looking-at "def\\(type\\|struct\\|class\\|ine-condition\\)")
 		 (forward-sexp 2)
 		 (if (=3D (char-after (1- (point))) ?\))
 		     (progn
 		       (forward-sexp -1)
 		       (down-list 1)
 		       (forward-sexp 1)))
 		 (push (imenu-example--name-and-position)
 		       index-type-alist))
		((looking-at "algorithm")
		 (forward-sexp 2)
		 (push (imenu-example--name-and-position)
		       index-algo-alist))
		((looking-at "generator")
		 (forward-sexp 2)
		 (push (imenu-example--name-and-position)
		       index-gen-alist))
		((looking-at "thread")
		 (forward-sexp 2)
		 (push (imenu-example--name-and-position)
		       index-thread-alist))
		((looking-at "merge")
		 (forward-sexp 2)
		 (push (imenu-example--name-and-position)
		       index-merge-alist))
		((looking-at "mute")
		 (forward-sexp 2)
		 (push (imenu-example--name-and-position)
		       index-mute-alist))
		((looking-at "definstrument")
		 (forward-sexp 2)
		 (push (imenu-example--name-and-position)
		       index-inst-alist))
		((looking-at "with-sound")
		 (forward-sexp 2)
		 (push (imenu-example--name-and-position)
		       index-unknown-alist))
		(t
		 (forward-sexp 2)
		 (push (imenu-example--name-and-position)
		       index-unknown-alist)))))))
    (imenu-progress-message prev-pos 100)
    (and index-unknown-alist
	 (push (cons (imenu-create-submenu-name "Div...") index-unknown-alist)
	       index-alist))
    (and index-funk-alist
	 (push (cons (imenu-create-submenu-name "Funksjoner") index-funk-alist)
	       index-alist))
    (and index-var-alist
	 (push (cons (imenu-create-submenu-name "Variabler") index-var-alist)
	       index-alist))
    (and index-type-alist
 	 (push (cons (imenu-create-submenu-name "Typer") index-type-alist)
  	       index-alist))
    (and index-algo-alist
	 (push (cons (imenu-create-submenu-name "Algorithm") index-algo-alist)
	       index-alist))
    (and index-gen-alist
	 (push (cons (imenu-create-submenu-name "Generator") index-gen-alist)
	       index-alist))
    (and index-thread-alist
	 (push (cons (imenu-create-submenu-name "Thread") index-thread-alist)
	       index-alist))
    (and index-merge-alist
	 (push (cons (imenu-create-submenu-name "Merge") index-merge-alist)
	       index-alist))
    (and index-mute-alist
	 (push (cons (imenu-create-submenu-name "Mute") index-mute-alist)
	       index-alist))
    (and index-inst-alist
	 (push (cons (imenu-create-submenu-name "Instrumenter") index-inst-alist=
)
	       index-alist))
    index-alist))


(add-hook 'lisp-mode-hook
	  (function
	   (lambda ()
	     (setq imenu-create-index-function
		   'imenu-cm--create-lisp-index)
	     (setq imenu-extract-index-name-function
		   'imenu-cm--lisp-extract-index-name))))

(autoload 'follow-mode "follow"
  "Synchronize windows showing the same buffer, minor mode." t)

(autoload 'browse "filebrowser" "File and directory tree browser" t)
(global-set-key "=18=04" 'browse)
(define-key-after menu-bar-file-menu [browse-directory]
  '("Browse Directory..." . browse) 'dired)

(add-hook 'browser-file-display-hook
	  '(lambda ()
	     (set-background-color "brown")
	     (set-foreground-color "yellow2")))

(eval-after-load                                                         =
          =

 "filebrowser"
 '(browser-add-menu
   '(("[mM]akefile"                                                      =
            =

      ["Make"                    compile t])
     ("News"
      ["GNUS"                    gnus t])
     ("\\.tar$"
      ["Untar Archive"           (browser-shell "tar -xf %s") t]
      ["List Archive"            (browser-shell "tar -tvf %s") t])
     ("\\.\\(tar\\.gz\\|tar\\.[zZ]\\|tgz\\|taz\\)$"
      ["Untar Compressed Archive" (browser-shell "tar -zxf %s") t]
      ["List Compressed Archive" (browser-shell "tar -ztvf %s") t])
     ("Xdefaults\\|Xresources"
      ["Load X Resources"        (browser-shell "xrdb -merge %s") t])
     ("\\.\\(gif\\|jpg\\|xwd\\|xpm\\)$"
      ["View Image"              (browser-shell "xv %s &") t])
     ("\\.html$"
      ["Netscape"                (browser-shell "netscape -remote openURL=
(%s) &") t]))))


;;; OPPVRENGING AV URLER FOR CLMDOK OSV.

(defun browse-url-netscape (url &optional new-window)
  "Ask the Netscape WWW browser to load URL."
  (or (and
       (zerop
	(apply 'call-process "netscape" nil nil nil
	       (append;;browse-url-netscape-arguments
		(if new-window '("-noraise"))
		(list "-remote" =

		      (concat "openURL(" url =

			      (if new-window ",new-window")
			      ")")))))
       (message (concat "Sl=E5r opp URL " url)))
      (progn				; Netscape not running - start it
	(message "Starting Netscape...")
	(apply 'start-process "netscape" nil "netscape"
	       (append ;;browse-url-netscape-arguments
		(list url)))
	(message (concat "Sl=E5r opp URL " url)))))

(defun netscape-follow-url (event)
  (interactive "e")
  (let ((curwin (current-window-configuration)) url)
    (save-excursion
      (mouse-set-point event)
      ;; find url-at-point
      (require 'url)			;from w3
      (setq url (url-get-url-at-point)))
    (set-window-configuration curwin)
    (if url
        (progn
          (prin1 (concat "Open URL " url))
	  (browse-url-netscape url)
	  (call-process "netscape" nil 0 nil "-remote"
			(concat "openURL(" url ")"))
	  )
      (prin1 "No URL found at point"))))

(global-set-key [S-mouse-3] 'netscape-follow-url)



(cond (window-system (require 'framepop)))
(define-key global-map [f2] framepop-map)
(setq framepop-frame-parameters
   '((name . nil)
     (unsplittable . t)
     (menu-bar-lines . 0)
     (minibuffer . nil)
     (icon-type . t)
     (left . 1)
     (top . 0)
     (width . 77)
     (font . "-misc-fixed-medium-r-normal--14-130-75-75-c-70-iso8859-1")
     ;;(font . "9x15bold")
     (background-color . "antiquewhite3")
     (foreground-color . "black")))

(setq special-display-function 'framepop-special-display)
(pushnew "*Shell Command Output*" special-display-buffer-names)


(autoload 'mouse-drag-scroll-bar "my-mouse"
    "Change the width of a window by dragging on the scroll bar.")
(global-set-key [vertical-scroll-bar S-down-mouse-1]      =

                 'mouse-drag-scroll-bar)                   =

(global-set-key [vertical-line down-mouse-1]              =

                 'mouse-drag-scroll-bar)

(global-set-key [M-down-mouse-1] 'pasting-mouse-drag-secondary)   =

(global-set-key [M-S-down-mouse-1] 'moving-mouse-drag-secondary)  =

(global-set-key [down-mouse-2] 'mouse-drag-throw)                 =


(global-set-key "\C-x/"  'my-point-to-register)             =

(global-set-key "\C-x\\" 'my-point-remove-register)
(global-set-key "\C-cj";; like C-xj
		'(lambda () (interactive)                      =

		   (let ((event (list                          =

				 'mouse-1                      =

				 (list                         =

				  (selected-window)            =

				  1714                         =

				  (cons 200 30)                =

				  25033746                     =

				  ))))                         =

		     (setq EE event)                           =

		     ;;  Use fake event                        =

		     (my-point-mouse-jump-to-register event))))


;;; LISP ARBEID


(setq inferior-lisp-prompt
      "^[*[1-9]*[a-z]*]* *[A-Z]+([0-9]+): *\\|Stella \\[[-a-zA-Z0-9]+\\]:=
 \\|Edit: \\|new value: (<cr>=3DUnchanged)  \\|Lisp> ")

(global-set-key "=03=1A" (quote cm))

(setq inferior-lisp-program "/hf/notam/u1/andersvi/usr/bin/CM")

(add-hook 'inferior-lisp-mode-hook
	  '(lambda ()
	     (local-set-key (quote [up]) 'comint-previous-input)
	     (local-set-key (quote [down]) 'comint-next-input)
	     (local-set-key "\t" 'comint-dynamic-complete-filename)
	     (local-set-key "=01" 'comint-bol)
	     (setq comint-input-ring-size 300)
	     (auto-fill-mode 0)))

;;;;;;; INDENTERINGS-KODE:

(put 'algorithm 'lisp-indent-hook 3)
(put 'generator 'lisp-indent-hook 3)
(put 'mute 'lisp-indent-hook 'defun)
(put 'thread 'lisp-indent-hook 'defun)
(put 'merge 'lisp-indent-hook 'defun)
;(put 'object 'lisp-indent-hook '(like make-instance))
(put 'defobject 'lisp-indent-hook 'defun)
;(put 'make-object 'lisp-indent-hook '(like make-instance))
(put 'unless-chording 'lisp-indent-hook 0)
(put 'doitems 'lisp-indent-hook 1)
(put 'defscale 'lisp-indent-hook 'defun)
(put 'defmultiple-item 'lisp-indent-hook 'defun)
(put 'multiple-item-bind 'lisp-indent-hook 2)
(put 'formatting-slots 'lisp-indent-hook 1)
(put 'printing-random-thing 'lisp-indent-hook 1)
(put 'with-sound 'lisp-indent-hook 'defun)


(setq default-major-mode 'lisp-mode)

(add-hook 'lisp-mode-hook
	  (function
	   (lambda ()
	     (turn-on-auto-fill)
	     (local-set-key "=0D" (quote newline-and-indent))
	     (local-set-key "=03=1A" 'cm))))

(defun lisp-eval-buffer (&optional til-lisp)
  "Evaluer hele bufferet. Prefix-argument betyr g=E5 til lisp etterp=E5"
  (interactive "P")
  (unless (get-buffer "*inferior-lisp*") (cm))
  (comint-send-region (inferior-lisp-proc) (point-min) (point-max))
  (comint-send-string (inferior-lisp-proc) "\n")
  (if til-lisp (cm 1)))

(defun lisp-eval-buffer-til-lisp ()
  (interactive)
  (unless (get-buffer "*inferior-lisp*") (cm))
  (lisp-eval-buffer 1))

(defun til-lisp ()
  (interactive)
  (cm 1))


;;; s=F8rg for at en del hjelpe-funksjoner finner riktig 'package:

(setq lisp-arglist-command
      "(let ((fn '%s))
         (format t \"Arglist for ~a: ~a\" fn (excl::arglist fn))
         (values)) ") =


(setq lisp-describe-sym-command "(excl::describe '%s)")


;;; SETT I GANG LISP I EGET DEDIKERT VINDU:

(defvar cm-frame nil)

(defvar cm-framepars
  '((name . "Common Music")
    (unsplittable . t)
    (width . 80)
    (height . 30)
    (top . -1)
    (left . 1)
    (icon-type . t)
    (font . "-sgi-screen-medium-r-normal--15-150-72-72-m-80-iso8859-1")
    (border-color . "Black")
    (border-width . 20)
    (minibuffer . nil)
    (background-color . "DeepSkyBlue4")
    (foreground-color . "LightCyan1")
    (cursor-color . "yellow3")
    (mouse-color . "yellow1")
    (auto-raise . nil)
    ))

(defun cm (&optional til-lisp)
  (interactive "P")
  (unless (frame-live-p cm-frame)
    (setq cm-frame (make-frame cm-framepars))
    (set-face-foreground 'region "black" cm-frame)
    (set-face-background 'region "LightCyan3" cm-frame)
    (set-face-background 'modeline "black" cm-frame)
    (set-face-foreground 'modeline "yellow3" cm-frame)
    (set-window-buffer
     (frame-selected-window cm-frame) (start-lisp))
    (set-window-dedicated-p (frame-selected-window cm-frame) t)
    (progn (set-buffer inferior-lisp-buffer)
	   ;;(setq title-customized t)
	   (setq mode-line-format
		 '("   " "Common Music"
		   "   " global-mode-string "   %[("
		   mode-name mode-line-process minor-mode-alist
		   "%n" ")%]--"
		   (line-number-mode "L%l--") (-3 . "%p") "-%-"))))
  =

  (if (gaar-lisp)
      (when til-lisp =

	(progn (raise-frame cm-frame)
	       (set-mouse-position cm-frame 0 0)))
    (set-window-buffer
     (frame-selected-window cm-frame) (start-lisp))))

(defun gaar-lisp ()
  (get-buffer-process (if (eq major-mode 'inferior-lisp-mode)
				      (current-buffer)
				    inferior-lisp-buffer)))

(defun start-lisp ()
  (interactive)
  (if (not (comint-check-proc "*inferior-lisp*"))
      (progn (set-buffer (apply (function make-comint)
				"inferior-lisp" inferior-lisp-program nil))
	     (inferior-lisp-mode)))
  (setq inferior-lisp-buffer "*inferior-lisp*")
  (set-buffer inferior-lisp-buffer)
  (current-buffer))

(defun lisp-exit ()
  "Avslutt lisp.  Dette er ekstremt viktig p=E5 NoTAM forel=F8pig"
  (interactive)
  (when (get-buffer-process inferior-lisp-buffer)
    (comint-send-string (inferior-lisp-proc) "(excl::exit)\n"))
  (when (get-buffer "*inferior-lisp*")
    (kill-buffer "*inferior-lisp*")))


;;(defun lisp-reset ()
;;  "Reset lispen fra en hvilken som helst buffer i lisp-mode"
;;  (interactive)
;;  (when (get-buffer-process inferior-lisp-buffer)
;;    (comint-send-string (inferior-lisp-proc) "(excl::exit)\n"))
;;  (when (get-buffer "*inferior-lisp*")
;;    (kill-buffer "*inferior-lisp*")))


;;; lager rutine for =E5 sjekke om lisp er skrudd av f=F8r emacs avslutte=
s
(defun min-exit-emacs ()
  "Avslutt emacs, men sjekk for l=F8pende lisp-prosesser f=F8rst"
  (interactive)
  (if (not (get-buffer-process inferior-lisp-buffer))
      (save-buffers-kill-emacs)
    (lisp-exit)
    (save-buffers-kill-emacs)))

(define-key global-map [menu-bar file exit-emacs] 'undefined)
(define-key-after menu-bar-file-menu [avslutt-emacs]
  '("Quit" . min-exit-emacs) 'epatch)
(global-set-key "=18=03" (quote min-exit-emacs))

;;; diverse snarveier

(defun mixview (lydfil)
  (interactive "fmxv (filnavn) : ")
  "Sett i gang en mxv-jobb"
  (background (concat "mxv " lydfil)))

(defun rt ()
  (interactive)
  "f=E5 igang RT"
  (background "rt"))

(defun bredit ()
  (interactive)
  "f=E5 igang bredit"
  (background "bredit"))

(defun spill ()
  (interactive)
  "spill siste lyd med (dac)"
  (when (get-buffer-process inferior-lisp-buffer)
    (comint-send-string (inferior-lisp-proc) "(dac)\n")))




(add-hook 'inferior-lisp-mode-hook
	  (function
	   (lambda ()
	     (local-set-key "=03p" 'spill)
	     (local-set-key "=03m" 'mixview)
	     (local-set-key "=03r" 'rt)
	     (local-set-key "=03b" 'bredit))))

(add-hook 'lisp-mode-hook
	  (function
	   (lambda ()
	     (local-set-key "=03p" 'spill)
	     (local-set-key "=03m" 'mixview)
	     (local-set-key "=03r" 'rt)
	     (local-set-key "=03b" 'bredit))))


(add-hook 'dired-mode-hook
	  (function
	   (lambda ()
	     (local-set-key "=03p" 'spill)
	     (local-set-key "=03m" 'mixview)
	     (local-set-key "=03r" 'rt)
	     (local-set-key "=03b" 'bredit))))


;;; lag Lisp-meny i alle buffere:


(defconst tools-map-lisp-menu
  '("Lisp-Tools"
    ["CM"	        	cm t]
    ["Avslutt CM!"		lisp-exit t]
    ["MiXViews"                 mixview t]
    ["RT"                       rt t]
    ["bredit"                   bredit t]
    ["Spill siste lyd"          spill t]
    ["Quit"			min-exit-emacs t]))

(defconst lisp-mode-lisp-menu
  '("Common-Music"
    ["Start CM"	        	cm t]
    ["Avslutt CM!"		lisp-exit t]
    ["Evaluer uttrykk"	lisp-eval-defun t]
    ["Evaluer region"		lisp-eval-region t]
    ["Evaluer buffer"		lisp-eval-buffer t]
    ["Evaluer buffer - g=E5 lisp"	lisp-eval-buffer-til-lisp t]
    ["Load lisp-file"		lisp-load-file t]
    ["MiXViews"                 mixview t]
    ["RT"                       rt t]
    ["bredit"                   bredit t]
    ["Spill siste lyd"          spill t]
    ["Quit"			min-exit-emacs t]))


(easy-menu-define lisp-mode-lisp-menu lisp-mode-map
		  "Lisp mode operasjoner" lisp-mode-lisp-menu)

;(easy-menu-define lisp-mode-lisp-menu inferior-lisp-mode-map
;		  "Lisp mode operasjoner" lisp-mode-lisp-menu)


;;(defconst lisp-mode-complete-menu
;;  '("Filnavn"
;;    ["Fullf=F8r filnavn"		comint-dynamic-complete-filename t]
;;    ["Filnavn-listing" comint-dynamic-list-filename-completions t]
;;    ["Ekspander filnavn"	comint-replace-by-expanded-filename t]))

;;(easy-menu-define lisp-mode-complete lisp-mode-map
;;		  "Filnavn operasjoner" lisp-mode-complete-menu)

;;(easy-menu-define lisp-mode-complete inferior-lisp-mode-map
;;		  "Filnavn operasjoner" lisp-mode-complete-menu)
 =

;;(define-key inferior-lisp-mode-map [menu-bar completion] 'undefined)
;;(define-key inferior-lisp-mode-map [menu-bar signals] 'undefined)


(global-set-key (quote [f5]) (quote other-frame))


(global-set-key '[print] 'ps-spool-buffer-with-faces)
(global-set-key '[S-execute] 'ps-spool-region-with-faces)
(global-set-key '[C-print] 'ps-despool)

--Multipart_Thu_Oct__2_11:26:09_1997-1--