home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume31 / bam / part06 < prev    next >
Encoding:
Text File  |  1992-07-30  |  27.5 KB  |  698 lines

  1. Newsgroups: comp.sources.misc
  2. From: sbo@vlsi.polymtl.ca (Stephane Boucher)
  3. Subject:  v31i062:  bam - [OpenLook|Athena] menu system for [GNU|Epoch|Lucid] Emacs, Part06/07
  4. Message-ID: <1992Jul31.042613.23933@sparky.imd.sterling.com>
  5. X-Md4-Signature: bc9f911afe699f13f9213f09b8f788c1
  6. Date: Fri, 31 Jul 1992 04:26:13 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: sbo@vlsi.polymtl.ca (Stephane Boucher)
  10. Posting-number: Volume 31, Issue 62
  11. Archive-name: bam/part06
  12. Environment: Lex, Yacc, SunOS 4.x with XView or BSD Unix with Athena Widget
  13. Supersedes: bam: Volume 27, Issue 68-69
  14.  
  15. #! /bin/sh
  16. # This is a shell archive.  Remove anything before this line, then unpack
  17. # it by saving it into a file and typing "sh file".  To overwrite existing
  18. # files, type "sh file -c".  You can also feed this as standard input via
  19. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  20. # will see the following message at the end:
  21. #        "End of archive 6 (of 7)."
  22. # Contents:  bam-2.0/COPYING bam-2.0/bam.el
  23. # Wrapped by sbo@froh on Mon Jul 27 20:11:50 1992
  24. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  25. if test -f 'bam-2.0/COPYING' -a "${1}" != "-c" ; then 
  26.   echo shar: Will not clobber existing file \"'bam-2.0/COPYING'\"
  27. else
  28. echo shar: Extracting \"'bam-2.0/COPYING'\" \(12473 characters\)
  29. sed "s/^X//" >'bam-2.0/COPYING' <<'END_OF_FILE'
  30. X
  31. X            GNU GENERAL PUBLIC LICENSE
  32. X             Version 1, February 1989
  33. X
  34. X Copyright (C) 1989 Free Software Foundation, Inc.
  35. X            675 Mass Ave, Cambridge, MA 02139, USA
  36. X Everyone is permitted to copy and distribute verbatim copies
  37. X of this license document, but changing it is not allowed.
  38. X
  39. X                Preamble
  40. X
  41. X  The license agreements of most software companies try to keep users
  42. Xat the mercy of those companies.  By contrast, our General Public
  43. XLicense is intended to guarantee your freedom to share and change free
  44. Xsoftware--to make sure the software is free for all its users.  The
  45. XGeneral Public License applies to the Free Software Foundation's
  46. Xsoftware and to any other program whose authors commit to using it.
  47. XYou can use it for your programs, too.
  48. X
  49. X  When we speak of free software, we are referring to freedom, not
  50. Xprice.  Specifically, the General Public License is designed to make
  51. Xsure that you have the freedom to give away or sell copies of free
  52. Xsoftware, that you receive source code or can get it if you want it,
  53. Xthat you can change the software or use pieces of it in new free
  54. Xprograms; and that you know you can do these things.
  55. X
  56. X  To protect your rights, we need to make restrictions that forbid
  57. Xanyone to deny you these rights or to ask you to surrender the rights.
  58. XThese restrictions translate to certain responsibilities for you if you
  59. Xdistribute copies of the software, or if you modify it.
  60. X
  61. X  For example, if you distribute copies of a such a program, whether
  62. Xgratis or for a fee, you must give the recipients all the rights that
  63. Xyou have.  You must make sure that they, too, receive or can get the
  64. Xsource code.  And you must tell them their rights.
  65. X
  66. X  We protect your rights with two steps: (1) copyright the software, and
  67. X(2) offer you this license which gives you legal permission to copy,
  68. Xdistribute and/or modify the software.
  69. X
  70. X  Also, for each author's protection and ours, we want to make certain
  71. Xthat everyone understands that there is no warranty for this free
  72. Xsoftware.  If the software is modified by someone else and passed on, we
  73. Xwant its recipients to know that what they have is not the original, so
  74. Xthat any problems introduced by others will not reflect on the original
  75. Xauthors' reputations.
  76. X
  77. X  The precise terms and conditions for copying, distribution and
  78. Xmodification follow.
  79. X
  80. X            GNU GENERAL PUBLIC LICENSE
  81. X   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
  82. X
  83. X  0. This License Agreement applies to any program or other work which
  84. Xcontains a notice placed by the copyright holder saying it may be
  85. Xdistributed under the terms of this General Public License.  The
  86. X"Program", below, refers to any such program or work, and a "work based
  87. Xon the Program" means either the Program or any work containing the
  88. XProgram or a portion of it, either verbatim or with modifications.  Each
  89. Xlicensee is addressed as "you".
  90. X
  91. X  1. You may copy and distribute verbatim copies of the Program's source
  92. Xcode as you receive it, in any medium, provided that you conspicuously and
  93. Xappropriately publish on each copy an appropriate copyright notice and
  94. Xdisclaimer of warranty; keep intact all the notices that refer to this
  95. XGeneral Public License and to the absence of any warranty; and give any
  96. Xother recipients of the Program a copy of this General Public License
  97. Xalong with the Program.  You may charge a fee for the physical act of
  98. Xtransferring a copy.
  99. X
  100. X  2. You may modify your copy or copies of the Program or any portion of
  101. Xit, and copy and distribute such modifications under the terms of Paragraph
  102. X1 above, provided that you also do the following:
  103. X
  104. X    a) cause the modified files to carry prominent notices stating that
  105. X    you changed the files and the date of any change; and
  106. X
  107. X    b) cause the whole of any work that you distribute or publish, that
  108. X    in whole or in part contains the Program or any part thereof, either
  109. X    with or without modifications, to be licensed at no charge to all
  110. X    third parties under the terms of this General Public License (except
  111. X    that you may choose to grant warranty protection to some or all
  112. X    third parties, at your option).
  113. X
  114. X    c) If the modified program normally reads commands interactively when
  115. X    run, you must cause it, when started running for such interactive use
  116. X    in the simplest and most usual way, to print or display an
  117. X    announcement including an appropriate copyright notice and a notice
  118. X    that there is no warranty (or else, saying that you provide a
  119. X    warranty) and that users may redistribute the program under these
  120. X    conditions, and telling the user how to view a copy of this General
  121. X    Public License.
  122. X
  123. X    d) You may charge a fee for the physical act of transferring a
  124. X    copy, and you may at your option offer warranty protection in
  125. X    exchange for a fee.
  126. X
  127. XMere aggregation of another independent work with the Program (or its
  128. Xderivative) on a volume of a storage or distribution medium does not bring
  129. Xthe other work under the scope of these terms.
  130. X
  131. X  3. You may copy and distribute the Program (or a portion or derivative of
  132. Xit, under Paragraph 2) in object code or executable form under the terms of
  133. XParagraphs 1 and 2 above provided that you also do one of the following:
  134. X
  135. X    a) accompany it with the complete corresponding machine-readable
  136. X    source code, which must be distributed under the terms of
  137. X    Paragraphs 1 and 2 above; or,
  138. X
  139. X    b) accompany it with a written offer, valid for at least three
  140. X    years, to give any third party free (except for a nominal charge
  141. X    for the cost of distribution) a complete machine-readable copy of the
  142. X    corresponding source code, to be distributed under the terms of
  143. X    Paragraphs 1 and 2 above; or,
  144. X
  145. X    c) accompany it with the information you received as to where the
  146. X    corresponding source code may be obtained.  (This alternative is
  147. X    allowed only for noncommercial distribution and only if you
  148. X    received the program in object code or executable form alone.)
  149. X
  150. XSource code for a work means the preferred form of the work for making
  151. Xmodifications to it.  For an executable file, complete source code means
  152. Xall the source code for all modules it contains; but, as a special
  153. Xexception, it need not include source code for modules which are standard
  154. Xlibraries that accompany the operating system on which the executable
  155. Xfile runs, or for standard header files or definitions files that
  156. Xaccompany that operating system.
  157. X
  158. X  4. You may not copy, modify, sublicense, distribute or transfer the
  159. XProgram except as expressly provided under this General Public License.
  160. XAny attempt otherwise to copy, modify, sublicense, distribute or transfer
  161. Xthe Program is void, and will automatically terminate your rights to use
  162. Xthe Program under this License.  However, parties who have received
  163. Xcopies, or rights to use copies, from you under this General Public
  164. XLicense will not have their licenses terminated so long as such parties
  165. Xremain in full compliance.
  166. X
  167. X  5. By copying, distributing or modifying the Program (or any work based
  168. Xon the Program) you indicate your acceptance of this license to do so,
  169. Xand all its terms and conditions.
  170. X
  171. X  6. Each time you redistribute the Program (or any work based on the
  172. XProgram), the recipient automatically receives a license from the original
  173. Xlicensor to copy, distribute or modify the Program subject to these
  174. Xterms and conditions.  You may not impose any further restrictions on the
  175. Xrecipients' exercise of the rights granted herein.
  176. X
  177. X  7. The Free Software Foundation may publish revised and/or new versions
  178. Xof the General Public License from time to time.  Such new versions will
  179. Xbe similar in spirit to the present version, but may differ in detail to
  180. Xaddress new problems or concerns.
  181. X
  182. XEach version is given a distinguishing version number.  If the Program
  183. Xspecifies a version number of the license which applies to it and "any
  184. Xlater version", you have the option of following the terms and conditions
  185. Xeither of that version or of any later version published by the Free
  186. XSoftware Foundation.  If the Program does not specify a version number of
  187. Xthe license, you may choose any version ever published by the Free Software
  188. XFoundation.
  189. X
  190. X  8. If you wish to incorporate parts of the Program into other free
  191. Xprograms whose distribution conditions are different, write to the author
  192. Xto ask for permission.  For software which is copyrighted by the Free
  193. XSoftware Foundation, write to the Free Software Foundation; we sometimes
  194. Xmake exceptions for this.  Our decision will be guided by the two goals
  195. Xof preserving the free status of all derivatives of our free software and
  196. Xof promoting the sharing and reuse of software generally.
  197. X
  198. X                NO WARRANTY
  199. X
  200. X  9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
  201. XFOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
  202. XOTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
  203. XPROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
  204. XOR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  205. XMERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
  206. XTO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
  207. XPROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
  208. XREPAIR OR CORRECTION.
  209. X
  210. X  10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
  211. XWILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
  212. XREDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
  213. XINCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
  214. XOUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
  215. XTO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
  216. XYOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
  217. XPROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
  218. XPOSSIBILITY OF SUCH DAMAGES.
  219. X
  220. X             END OF TERMS AND CONDITIONS
  221. X
  222. X    Appendix: How to Apply These Terms to Your New Programs
  223. X
  224. X  If you develop a new program, and you want it to be of the greatest
  225. Xpossible use to humanity, the best way to achieve this is to make it
  226. Xfree software which everyone can redistribute and change under these
  227. Xterms.
  228. X
  229. X  To do so, attach the following notices to the program.  It is safest to
  230. Xattach them to the start of each source file to most effectively convey
  231. Xthe exclusion of warranty; and each file should have at least the
  232. X"copyright" line and a pointer to where the full notice is found.
  233. X
  234. X    <one line to give the program's name and a brief idea of what it does.>
  235. X    Copyright (C) 19yy    <name of author>
  236. X
  237. X    This program is free software; you can redistribute it and/or modify
  238. X    it under the terms of the GNU General Public License as published by
  239. X    the Free Software Foundation; either version 1, or (at your option)
  240. X    any later version.
  241. X
  242. X    This program is distributed in the hope that it will be useful,
  243. X    but WITHOUT ANY WARRANTY; without even the implied warranty of
  244. X    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  245. X    GNU General Public License for more details.
  246. X
  247. X    You should have received a copy of the GNU General Public License
  248. X    along with this program; if not, write to the Free Software
  249. X    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  250. X
  251. XAlso add information on how to contact you by electronic and paper mail.
  252. X
  253. XIf the program is interactive, make it output a short notice like this
  254. Xwhen it starts in an interactive mode:
  255. X
  256. X    Gnomovision version 69, Copyright (C) 19xx name of author
  257. X    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
  258. X    This is free software, and you are welcome to redistribute it
  259. X    under certain conditions; type `show c' for details.
  260. X
  261. XThe hypothetical commands `show w' and `show c' should show the
  262. Xappropriate parts of the General Public License.  Of course, the
  263. Xcommands you use may be called something other than `show w' and `show
  264. Xc'; they could even be mouse-clicks or menu items--whatever suits your
  265. Xprogram.
  266. X
  267. XYou should also get your employer (if you work as a programmer) or your
  268. Xschool, if any, to sign a "copyright disclaimer" for the program, if
  269. Xnecessary.  Here a sample; alter the names:
  270. X
  271. X  Yoyodyne, Inc., hereby disclaims all copyright interest in the
  272. X  program `Gnomovision' (a program to direct compilers to make passes
  273. X  at assemblers) written by James Hacker.
  274. X
  275. X  <signature of Ty Coon>, 1 April 1989
  276. X  Ty Coon, President of Vice
  277. X
  278. XThat's all there is to it!
  279. END_OF_FILE
  280. if test 12473 -ne `wc -c <'bam-2.0/COPYING'`; then
  281.     echo shar: \"'bam-2.0/COPYING'\" unpacked with wrong size!
  282. fi
  283. # end of 'bam-2.0/COPYING'
  284. fi
  285. if test -f 'bam-2.0/bam.el' -a "${1}" != "-c" ; then 
  286.   echo shar: Will not clobber existing file \"'bam-2.0/bam.el'\"
  287. else
  288. echo shar: Extracting \"'bam-2.0/bam.el'\" \(12774 characters\)
  289. sed "s/^X//" >'bam-2.0/bam.el' <<'END_OF_FILE'
  290. X;   bam - the Born Again Menus for GNU Emacs.
  291. X;   Copyright (C) 1992 Stephane Boucher, Hans Olsson.
  292. X;
  293. X;    This program is free software; you can redistribute it and/or modify
  294. X;    it under the terms of the GNU General Public License as published by
  295. X;    the Free Software Foundation; either version 1, or (at your option)
  296. X;    any later version.
  297. X;
  298. X;    This program is distributed in the hope that it will be useful,
  299. X;    but WITHOUT ANY WARRANTY; without even the implied warranty of
  300. X;    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  301. X;    GNU General Public License for more details.
  302. X;
  303. X;    You should have received a copy of the GNU General Public License
  304. X;    along with this program; if not, write to the Free Software
  305. X;    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  306. X;
  307. X;  In other words, you are welcome to use, share and improve this program.
  308. X;  You are forbidden to forbid anyone else to use, share and improve
  309. X;  what you give them.   Help stamp out software-hoarding!
  310. X
  311. X;;; $Id: bam.el,v 1.11 1992/07/27 23:06:26 sbo Exp $
  312. X
  313. X(require 'command-process)
  314. X
  315. X(load-library "bytecomp")
  316. X(require 'bam-defaults)
  317. X
  318. X(defun y-or-n-p (str)
  319. X  "A better y-or-n-p (oh well the other crashed...)"
  320. X; To test if you need this:
  321. X; 0: Comment out this function
  322. X; 1: save a file
  323. X; 2: change it(do not save it)
  324. X; 3: choose Quit in the menu
  325. X; 4: Press control-g as answer.
  326. X; 5: If emacs beeps unstoppably you'll need this.
  327. X;
  328. X  (interactive)
  329. X  (message str)
  330. X  (defun again ()
  331. X    (let ((the-character-in-my-y-or-n-p (read-char)))
  332. X      (cond ((or
  333. X              (= the-character-in-my-y-or-n-p ?\ )
  334. X              (= the-character-in-my-y-or-n-p ?y )) t)
  335. X            ((or
  336. X              (= the-character-in-my-y-or-n-p ?n)
  337. X              (= the-character-in-my-y-or-n-p ?\C-g )
  338. X              (= the-character-in-my-y-or-n-p ?\^? )) '())
  339. X            (t (again)))))
  340. X  (again))
  341. X
  342. X;;;
  343. X;;; Manipulations of command line args
  344. X;;;
  345. X(setq command-switch-alist
  346. X      (append
  347. X       '(("-bam" . bam-menu-mode))
  348. X       command-switch-alist))
  349. X
  350. X(defun bam-menu-mode (arg)
  351. X  "Loads the next argument with menus"
  352. X  (interactive)
  353. X  (if (not (null command-line-args-left))
  354. X      (progn
  355. X    (bam-load-menu (car command-line-args-left))
  356. X    (bam-open-menu (car command-line-args-left))
  357. X    (setq command-line-args-left (cdr command-line-args-left)))))
  358. X;;;-------------------------------------
  359. X
  360. X(defun bam-font-option (font)
  361. X  "Returns options suitable for setting a font"
  362. X  (cond
  363. X   ((string= bam-widget "ATHENA")
  364. X    (list "-font" font))
  365. X   ((string= bam-widget "XVIEW")
  366. X    (list "-Wt" font))
  367. X   (t 
  368. X    (error "Unknown widget toolkit %s" bam-widget))))
  369. X
  370. X(defun bam-geometry-option (x y w h &optional grab)
  371. X  "Returns options suitable for the specified geometry.
  372. XIf the optional argument grab is true, the options
  373. Xwill make bam grab the emacs window."
  374. X  (cond
  375. X  ((string= bam-widget "XVIEW")
  376. X   (list "-Wp" (int-to-string x) (int-to-string y) "-Ws"
  377. X     (int-to-string w) (int-to-string h)))
  378. X  ((string= bam-widget "ATHENA")
  379. X   (if (and (not (null grab)) (not (null bam-window-name)))
  380. X       (list "-geometry" "482x314+1000+1000" "-w" bam-window-name)
  381. X     (list "-geometry" 
  382. X       (concat (int-to-string w) "x" (int-to-string h) "+"
  383. X           (int-to-string x) "+" (int-to-string y)))))
  384. X  (t
  385. X   (error "Unknown widget toolkit %s" bam-widget))))
  386. X
  387. X(defun bam-grab-option ()
  388. X  "Returns options that makes bam grab the emacs"
  389. X  (if (and (string= bam-widget "ATHENA")
  390. X       (not (null bam-window-name)))
  391. X      (list "-w" bam-window-name)
  392. X    (list )))
  393. X
  394. X(defun bam-after (opt li)
  395. X  "Returns the argument after opt in li"
  396. X  (cond
  397. X   ((null li) nil)
  398. X   ((equal opt (car li)) (car (cdr li)))
  399. X   ('t (bam-after opt (cdr li)))))
  400. X
  401. X(setq bam-window-name (bam-after "-wn" command-line-args))
  402. X
  403. X(defvar bam-menus-list '()
  404. X  "List of menus and their respective properties.
  405. XThe structure for each menu is:
  406. X     (menu-name menu-dir menu-args menu-process)
  407. XWhere menu-name and menu-dir are strings, and menu-args is a list of
  408. Xarguments to pass to bam. menu-process indicate the current process
  409. Xfor this menu.")
  410. X
  411. X(defun bam-set-menu-dir (menu-name menu-dir)
  412. X  "Sets the menu directory where the files menu-name.el and menu-name are
  413. Xlocated. Returns t if the menu exists and nil if it does not exist."
  414. X  (interactive "sBam menu name: \nDBam menu directory: ")
  415. X  (let ((menu (assoc menu-name bam-menus-list)))
  416. X    (if menu
  417. X    (prog1 t
  418. X      (setcar (nthcdr 1 menu)
  419. X          ;; Remove the traling '/', if any.
  420. X          (if (string= (substring menu-dir -1) "/")
  421. X              (substring menu-dir 0 -1)
  422. X            (concat menu-dir))))
  423. X      nil)))
  424. X
  425. X
  426. X(defun bam-get-menu-dir (menu-name)
  427. X  "Gets the menu directory corresponding to the menu named menu-name.
  428. XReturn nil if the menu does not exist."
  429. X  (interactive "sBam menu name: ")
  430. X  (let ((menu (assoc menu-name bam-menus-list)))
  431. X    (if menu
  432. X    (progn
  433. X      (if (interactive-p)
  434. X          (message (car (nthcdr 1 menu))))
  435. X      (concat (car (nthcdr 1 menu))))
  436. X      (prog1 nil
  437. X    (if (interactive-p)
  438. X        (message (concat "Bam menu \"" menu-name "\" was not found.")))))))
  439. X
  440. X
  441. X(defun bam-set-menu-args (menu-name &optional args)
  442. X  "Sets the arguments to be passed to Bam for the given menu.
  443. Xmenu-name. Return t if the menu exists, nil otherwise."
  444. X  (interactive "sBam menu name: \nLBam menu args list: ")
  445. X  (let ((menu (assoc menu-name bam-menus-list)))
  446. X    (if menu
  447. X    ;; Menu was found.
  448. X    (prog1 t
  449. X      (setcar 
  450. X       (nthcdr 2 menu)
  451. X       (if (and (not (null args)) (listp args))
  452. X           (copy-sequence args)
  453. X         (append
  454. X          (bam-font-option "7x14") ; font
  455. X          (bam-geometry-option 0 0 1000 300)) ; Position, size
  456. X         )))
  457. X      (prog1 nil
  458. X    (if (interactive-p)
  459. X        (message "Bam menu \"" menu-name "\" was not found"))))))
  460. X
  461. X(defun bam-set-menu-process (menu-name &optional menu-process)
  462. X  "Store the process handle for menu-name in the menu's structure."
  463. X  (let ((menu (assoc menu-name bam-menus-list)))
  464. X    (if menu
  465. X    ;; Menu was found.
  466. X    (prog1 t
  467. X      (setcar 
  468. X       (nthcdr 3 menu)
  469. X       (if (and menu-process 
  470. X            (processp menu-process)
  471. X            (eq (process-status menu-process) 'run))
  472. X           menu-process
  473. X         nil)))
  474. X      nil)))
  475. X
  476. X
  477. X(defun bam-set-mode-hook (menu-name mode-hook-variable)
  478. X  "Sets a mode hook that will cause the given menu to be openned.
  479. XThe hook will cause the specified menu (menu-name) to be openned
  480. Xwhen a given emacs mode is activated."
  481. X  (if (not (boundp mode-hook-variable))
  482. X      (set-variable mode-hook-variable nil))
  483. X  (cond
  484. X   ;; No hook functions
  485. X   ((equal (eval mode-hook-variable) nil)
  486. X    (set-variable mode-hook-variable
  487. X          (` (lambda () (bam-open-menu (, menu-name))))))
  488. X   ;; List of hook functions
  489. X   ((and (listp (eval mode-hook-variable))
  490. X     (listp (car (eval mode-hook-variable))))
  491. X    (set-variable mode-hook-variable 
  492. X          (cons (` (lambda () (bam-open-menu (, menu-name))))
  493. X            (eval mode-hook-variable))))
  494. X   ;; one hook function
  495. X   ((listp (eval mode-hook-variable))
  496. X    (set-variable mode-hook-variable 
  497. X          (cons (` (lambda () (bam-open-menu (, menu-name))))
  498. X            (list (eval mode-hook-variable)))))
  499. X   (t
  500. X    (message (concat "Can't hook menu \"" menu-name "\" to "
  501. X             (symbol-name mode-hook-variable)))
  502. X    nil)))
  503. X
  504. X
  505. X(defun bam-get-menu-args (menu-name)
  506. X  "Gets the args for the menu named menu-name. Return the list of args.
  507. XReturns nil if the menu was not found."
  508. X  (interactive "sBam menu name: ")
  509. X  (let ((menu (assoc menu-name bam-menus-list)))
  510. X    (if menu
  511. X    ;; Menu was found.
  512. X    (copy-sequence (car (nthcdr 2 menu)))
  513. X      (prog1 nil
  514. X    (if (interactive-p)
  515. X        (message "Bam menu \"" menu-name "\" was not found"))))))
  516. X
  517. X
  518. X(defun bam-get-menu-process (menu-name)
  519. X  "Gets the process-handle for the menu named menu-name. 
  520. XReturn the found handle."
  521. X  (let ((menu (assoc menu-name bam-menus-list)))
  522. X    (if menu
  523. X    ;; Menu was found.
  524. X    (car (nthcdr 3 menu))
  525. X      nil)))
  526. X
  527. X;; Add the bam-exec-dir to the beginning of the list
  528. X;; exec-path, only if bam-exec-dir is not already in
  529. X;; exec-path.
  530. X;(let ((path exec-path)
  531. X;      (path-found nil))
  532. X;  (while (and (not path-found) path)
  533. X;    (if (string= (car path) bam-exec-dir)
  534. X;    (setq path-found t)
  535. X;      (setq path (cdr path))))
  536. X;  (if (not path-found)
  537. X;      (setq exec-path (cons bam-exec-dir exec-path))))
  538. X
  539. X
  540. X(defun bam-load-menu (menu-name)
  541. X  "Load the bam menu menu-name. This does not open the menu.
  542. XThe directory where the menu-name is located is determined,
  543. Xand then this menu is registered as being ready to be opened."
  544. X  (interactive "sBam menu name: ")
  545. X  (let ((path bam-menus-path))
  546. X    (while path
  547. X      (let ((menu-file-name (concat (car path) "/" menu-name)))
  548. X        (if (and (file-exists-p menu-file-name) 
  549. X             (file-readable-p menu-file-name))
  550. X            (prog1 t
  551. X              (bam-add-menu-to-menu-list menu-name (car path))
  552. X              (let ((elisp-menu-file-name 
  553. X                 (concat menu-file-name ".el")))
  554. X            (if (and (file-exists-p elisp-menu-file-name)
  555. X                 (file-readable-p elisp-menu-file-name))
  556. X                (load-file elisp-menu-file-name)))
  557. X              (message (concat "Bam menu \"" 
  558. X                       menu-name "\" successfully loaded.")))
  559. X          (message (concat "Cannot locate the \"" 
  560. X                   menu-name "\" menu"))))
  561. X      (setq path (cdr path)))))
  562. X
  563. X        
  564. X(defun bam-elisp-to-unix-path (path-list)
  565. X  "Convert a path in the form of a list to a path in the form of a unix path
  566. Xe.g. (\"path1\" \"path2\" \"path3\") to \"path1:path2:path3\"."
  567. X  (let ((path path-list) (full-path ""))
  568. X    (while path
  569. X      (if (string= full-path "")
  570. X      (setq full-path (car path))
  571. X    (setq full-path (concat full-path ":" (car path))))
  572. X      (setq path (cdr path)))
  573. X    full-path))
  574. X
  575. X
  576. X(defun bam-add-menu-to-menu-list (menu-name menu-dir)
  577. X  "Register the bam menu and save useful information about the menu.  The
  578. Xlist as currently the format ((menu-name menu-dir) ...) where menu-dir
  579. Xis the directory where the files menu-name.el and menu-name are
  580. Xstored. menu-name and menu-dir are both string."
  581. X  (let ((menu (assoc menu-name bam-menus-list)))
  582. X    (if menu
  583. X        ;; The menu was found in the list. Modify the stored information.
  584. X        (progn
  585. X          (bam-set-menu-dir menu-name menu-dir)
  586. X      (bam-set-menu-args menu-name)
  587. X          (message (concat "Bam menu \"" menu-name "\" replaced")))
  588. X
  589. X      ;; The menu was not found in the list. Add it to the list.
  590. X      (progn
  591. X        (setq bam-menus-list
  592. X              (cons (` ((, menu-name) nil nil nil))
  593. X                    bam-menus-list))
  594. X    (bam-set-menu-dir menu-name menu-dir)
  595. X    (bam-set-menu-args menu-name)
  596. X;    (bam-set-menu-process nil)
  597. X        (message (concat "Bam menu \"" menu-name "\" added"))))))
  598. X   
  599. X(defun bam-expand-lists-to-strings (args)
  600. X  "Recursively parse args to generate a list of strings."
  601. X  (if (listp args) 
  602. X      (let ((sub-args args)
  603. X        (new-list '())
  604. X        (car-arg nil))
  605. X    (while sub-args
  606. X      (setq car-arg (car sub-args))
  607. X      (cond ((stringp car-arg) 
  608. X         (setq new-list (append new-list (list car-arg))))
  609. X        ((integerp car-arg) 
  610. X         (setq new-list
  611. X               (append new-list (list (int-to-string car-arg)))))
  612. X        ((symbolp car-arg)
  613. X         (setq new-list 
  614. X               (append new-list (list (symbol-name car-arg)))))
  615. X        ((listp car-arg)
  616. X         (setq new-list 
  617. X               (append new-list 
  618. X                   (bam-expand-lists-to-strings car-arg))))
  619. X        ((null car-arg) )
  620. X        (t
  621. X         (progn
  622. X           (error "Wrong type argument type " (car-arg))
  623. X           (setq sub-args nil))))
  624. X      (setq sub-args (cdr sub-args)))
  625. X    new-list)
  626. X    (error "args must be a list")))
  627. X
  628. X
  629. X(defun bam-open-menu (menu-name &rest bam-args)
  630. X  "Open the menu specified by menu-name, passing bam-args to the bam menu.
  631. XIf the menu is already opened, no additional menu of the same name is
  632. Xopened. bam-args is not allowed in interactive mode."
  633. X;;;  (interactive "sBam Menu Name: \nxBam Arguments (surrounded by paran): ")
  634. X  (interactive "sBam Menu Name: ")
  635. X  (let ((menu (assoc menu-name bam-menus-list)))
  636. X    ;; The menu exist. Try to start it.
  637. X    (if menu
  638. X    ;; If the menu process is not already running, start a process
  639. X    (let ((p (bam-get-menu-process menu-name)))
  640. X      (if (or (not (processp p))
  641. X          (not (eq (process-status (process-name p)) 'run)))
  642. X          (progn
  643. X        (bam-set-menu-process 
  644. X         menu-name 
  645. X         (apply 'command-process 
  646. X            (concat bam-exec-dir "/bam")
  647. X            (bam-expand-lists-to-strings
  648. X             (append
  649. X              (list '-B (bam-elisp-to-unix-path bam-bitmaps-path))
  650. X              (bam-get-menu-args menu-name)
  651. X              bam-args
  652. X              (list
  653. X               (concat (bam-get-menu-dir menu-name) 
  654. X                   "/" menu-name))))))
  655. X        (process-kill-without-query (bam-get-menu-process menu-name)))))
  656. X
  657. X      ;; The menu does not exist.
  658. X      (message
  659. X       (concat "The bam menu \"" menu-name "\" is not in the menu list")))))
  660. X
  661. X(defun strings-to-buffer (string1 string2)
  662. X  "*Inserts STRING1 and STRING2 in current buffer, puts point after STRING1."
  663. X  (insert string1)
  664. X  (let ((newpoint (point)))
  665. X    (insert string2)
  666. X    (goto-char newpoint)))
  667. X
  668. X(byte-compile (function strings-to-buffer))
  669. X
  670. X(provide 'bam)
  671. X
  672. X
  673. END_OF_FILE
  674. if test 12774 -ne `wc -c <'bam-2.0/bam.el'`; then
  675.     echo shar: \"'bam-2.0/bam.el'\" unpacked with wrong size!
  676. fi
  677. # end of 'bam-2.0/bam.el'
  678. fi
  679. echo shar: End of archive 6 \(of 7\).
  680. cp /dev/null ark6isdone
  681. MISSING=""
  682. for I in 1 2 3 4 5 6 7 ; do
  683.     if test ! -f ark${I}isdone ; then
  684.     MISSING="${MISSING} ${I}"
  685.     fi
  686. done
  687. if test "${MISSING}" = "" ; then
  688.     echo You have unpacked all 7 archives.
  689.     rm -f ark[1-9]isdone
  690. else
  691.     echo You still need to unpack the following archives:
  692.     echo "        " ${MISSING}
  693. fi
  694. ##  End of shell archive.
  695. exit 0
  696.  
  697. exit 0 # Just in case...
  698.