menu-bar.el 93 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229
  1. ;;; menu-bar.el --- define a default menu bar
  2. ;; Copyright (C) 1993-1995, 2000-2012 Free Software Foundation, Inc.
  3. ;; Author: RMS
  4. ;; Maintainer: FSF
  5. ;; Keywords: internal, mouse
  6. ;; Package: emacs
  7. ;; This file is part of GNU Emacs.
  8. ;; GNU Emacs is free software: you can redistribute it and/or modify
  9. ;; it under the terms of the GNU General Public License as published by
  10. ;; the Free Software Foundation, either version 3 of the License, or
  11. ;; (at your option) any later version.
  12. ;; GNU Emacs is distributed in the hope that it will be useful,
  13. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. ;; GNU General Public License for more details.
  16. ;; You should have received a copy of the GNU General Public License
  17. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  18. ;; Avishai Yacobi suggested some menu rearrangements.
  19. ;;; Commentary:
  20. ;;; Code:
  21. ;; This is referenced by some code below; it is defined in uniquify.el
  22. (defvar uniquify-buffer-name-style)
  23. ;; From emulation/cua-base.el; used below
  24. (defvar cua-enable-cua-keys)
  25. ;; Don't clobber an existing menu-bar keymap, to preserve any menu-bar key
  26. ;; definitions made in loaddefs.el.
  27. (or (lookup-key global-map [menu-bar])
  28. (define-key global-map [menu-bar] (make-sparse-keymap "menu-bar")))
  29. (if (not (featurep 'ns))
  30. ;; Force Help item to come last, after the major mode's own items.
  31. ;; The symbol used to be called `help', but that gets confused with the
  32. ;; help key.
  33. (setq menu-bar-final-items '(help-menu))
  34. (if (eq system-type 'darwin)
  35. (setq menu-bar-final-items '(buffer services help-menu))
  36. (setq menu-bar-final-items '(buffer services hide-app quit))
  37. ;; Add standard top-level items to GNUstep menu.
  38. (define-key global-map [menu-bar quit]
  39. `(menu-item ,(purecopy "Quit") save-buffers-kill-emacs
  40. :help ,(purecopy "Save unsaved buffers, then exit")))
  41. (define-key global-map [menu-bar hide-app]
  42. `(menu-item ,(purecopy "Hide") ns-do-hide-emacs
  43. :help ,(purecopy "Hide Emacs"))))
  44. (define-key global-map [menu-bar services] ; set-up in ns-win
  45. (cons (purecopy "Services") (make-sparse-keymap "Services"))))
  46. ;; This definition is just to show what this looks like.
  47. ;; It gets modified in place when menu-bar-update-buffers is called.
  48. (defvar global-buffers-menu-map (make-sparse-keymap "Buffers"))
  49. ;; Only declared obsolete (and only made a proper alias) in 23.3.
  50. (define-obsolete-variable-alias
  51. 'menu-bar-files-menu 'menu-bar-file-menu "22.1")
  52. (defvar menu-bar-file-menu
  53. (let ((menu (make-sparse-keymap "File")))
  54. ;; The "File" menu items
  55. (define-key menu [exit-emacs]
  56. `(menu-item ,(purecopy "Quit") save-buffers-kill-terminal
  57. :help ,(purecopy "Save unsaved buffers, then exit")))
  58. (define-key menu [separator-exit]
  59. menu-bar-separator)
  60. ;; Don't use delete-frame as event name because that is a special
  61. ;; event.
  62. (define-key menu [delete-this-frame]
  63. `(menu-item ,(purecopy "Delete Frame") delete-frame
  64. :visible (fboundp 'delete-frame)
  65. :enable (delete-frame-enabled-p)
  66. :help ,(purecopy "Delete currently selected frame")))
  67. (define-key menu [make-frame-on-display]
  68. `(menu-item ,(purecopy "New Frame on Display...") make-frame-on-display
  69. :visible (fboundp 'make-frame-on-display)
  70. :help ,(purecopy "Open a new frame on another display")))
  71. (define-key menu [make-frame]
  72. `(menu-item ,(purecopy "New Frame") make-frame-command
  73. :visible (fboundp 'make-frame-command)
  74. :help ,(purecopy "Open a new frame")))
  75. (define-key menu [separator-frame]
  76. menu-bar-separator)
  77. (define-key menu [one-window]
  78. `(menu-item ,(purecopy "Remove Other Windows") delete-other-windows
  79. :enable (not (one-window-p t nil))
  80. :help ,(purecopy "Make selected window fill whole frame")))
  81. (define-key menu [new-window-on-right]
  82. `(menu-item ,(purecopy "New Window on Right") split-window-right
  83. :enable (and (menu-bar-menu-frame-live-and-visible-p)
  84. (menu-bar-non-minibuffer-window-p))
  85. :help ,(purecopy "Make new window on right of selected one")))
  86. (define-key menu [new-window-below]
  87. `(menu-item ,(purecopy "New Window Below") split-window-below
  88. :enable (and (menu-bar-menu-frame-live-and-visible-p)
  89. (menu-bar-non-minibuffer-window-p))
  90. :help ,(purecopy "Make new window below selected one")))
  91. (define-key menu [separator-window]
  92. menu-bar-separator)
  93. (define-key menu [ps-print-region]
  94. `(menu-item ,(purecopy "PostScript Print Region (B+W)") ps-print-region
  95. :enable mark-active
  96. :help ,(purecopy "Pretty-print marked region in black and white to PostScript printer")))
  97. (define-key menu [ps-print-buffer]
  98. `(menu-item ,(purecopy "PostScript Print Buffer (B+W)") ps-print-buffer
  99. :enable (menu-bar-menu-frame-live-and-visible-p)
  100. :help ,(purecopy "Pretty-print current buffer in black and white to PostScript printer")))
  101. (define-key menu [ps-print-region-faces]
  102. `(menu-item ,(purecopy "PostScript Print Region")
  103. ps-print-region-with-faces
  104. :enable mark-active
  105. :help ,(purecopy
  106. "Pretty-print marked region to PostScript printer")))
  107. (define-key menu [ps-print-buffer-faces]
  108. `(menu-item ,(purecopy "PostScript Print Buffer")
  109. ps-print-buffer-with-faces
  110. :enable (menu-bar-menu-frame-live-and-visible-p)
  111. :help ,(purecopy "Pretty-print current buffer to PostScript printer")))
  112. (define-key menu [print-region]
  113. `(menu-item ,(purecopy "Print Region") print-region
  114. :enable mark-active
  115. :help ,(purecopy "Print region between mark and current position")))
  116. (define-key menu [print-buffer]
  117. `(menu-item ,(purecopy "Print Buffer") print-buffer
  118. :enable (menu-bar-menu-frame-live-and-visible-p)
  119. :help ,(purecopy "Print current buffer with page headings")))
  120. (define-key menu [separator-print]
  121. menu-bar-separator)
  122. (define-key menu [recover-session]
  123. `(menu-item ,(purecopy "Recover Crashed Session") recover-session
  124. :enable
  125. (and auto-save-list-file-prefix
  126. (file-directory-p
  127. (file-name-directory auto-save-list-file-prefix))
  128. (directory-files
  129. (file-name-directory auto-save-list-file-prefix)
  130. nil
  131. (concat "\\`"
  132. (regexp-quote
  133. (file-name-nondirectory
  134. auto-save-list-file-prefix)))
  135. t))
  136. :help ,(purecopy "Recover edits from a crashed session")))
  137. (define-key menu [revert-buffer]
  138. `(menu-item ,(purecopy "Revert Buffer") revert-buffer
  139. :enable (or revert-buffer-function
  140. revert-buffer-insert-file-contents-function
  141. (and buffer-file-number
  142. (or (buffer-modified-p)
  143. (not (verify-visited-file-modtime
  144. (current-buffer))))))
  145. :help ,(purecopy "Re-read current buffer from its file")))
  146. (define-key menu [write-file]
  147. `(menu-item ,(purecopy "Save As...") write-file
  148. :enable (and (menu-bar-menu-frame-live-and-visible-p)
  149. (menu-bar-non-minibuffer-window-p))
  150. :help ,(purecopy "Write current buffer to another file")))
  151. (define-key menu [save-buffer]
  152. `(menu-item ,(purecopy "Save") save-buffer
  153. :enable (and (buffer-modified-p)
  154. (buffer-file-name)
  155. (menu-bar-non-minibuffer-window-p))
  156. :help ,(purecopy "Save current buffer to its file")))
  157. (define-key menu [separator-save]
  158. menu-bar-separator)
  159. (define-key menu [kill-buffer]
  160. `(menu-item ,(purecopy "Close") kill-this-buffer
  161. :enable (kill-this-buffer-enabled-p)
  162. :help ,(purecopy "Discard (kill) current buffer")))
  163. (define-key menu [insert-file]
  164. `(menu-item ,(purecopy "Insert File...") insert-file
  165. :enable (menu-bar-non-minibuffer-window-p)
  166. :help ,(purecopy "Insert another file into current buffer")))
  167. (define-key menu [dired]
  168. `(menu-item ,(purecopy "Open Directory...") dired
  169. :enable (menu-bar-non-minibuffer-window-p)
  170. :help ,(purecopy
  171. "Read a directory, to operate on its files")))
  172. (define-key menu [open-file]
  173. `(menu-item ,(purecopy "Open File...") menu-find-file-existing
  174. :enable (menu-bar-non-minibuffer-window-p)
  175. :help ,(purecopy
  176. "Read an existing file into an Emacs buffer")))
  177. (define-key menu [new-file]
  178. `(menu-item ,(purecopy "Visit New File...") find-file
  179. :enable (menu-bar-non-minibuffer-window-p)
  180. :help ,(purecopy
  181. "Specify a new file's name, to edit the file")))
  182. menu))
  183. (defun menu-find-file-existing ()
  184. "Edit the existing file FILENAME."
  185. (interactive)
  186. (let* ((mustmatch (not (and (fboundp 'x-uses-old-gtk-dialog)
  187. (x-uses-old-gtk-dialog))))
  188. (filename (car (find-file-read-args "Find file: " mustmatch))))
  189. (if mustmatch
  190. (find-file-existing filename)
  191. (find-file filename))))
  192. ;; The "Edit->Search" submenu
  193. (defvar menu-bar-last-search-type nil
  194. "Type of last non-incremental search command called from the menu.")
  195. (defun nonincremental-repeat-search-forward ()
  196. "Search forward for the previous search string or regexp."
  197. (interactive)
  198. (cond
  199. ((and (eq menu-bar-last-search-type 'string)
  200. search-ring)
  201. (search-forward (car search-ring)))
  202. ((and (eq menu-bar-last-search-type 'regexp)
  203. regexp-search-ring)
  204. (re-search-forward (car regexp-search-ring)))
  205. (t
  206. (error "No previous search"))))
  207. (defun nonincremental-repeat-search-backward ()
  208. "Search backward for the previous search string or regexp."
  209. (interactive)
  210. (cond
  211. ((and (eq menu-bar-last-search-type 'string)
  212. search-ring)
  213. (search-backward (car search-ring)))
  214. ((and (eq menu-bar-last-search-type 'regexp)
  215. regexp-search-ring)
  216. (re-search-backward (car regexp-search-ring)))
  217. (t
  218. (error "No previous search"))))
  219. (defun nonincremental-search-forward (string)
  220. "Read a string and search for it nonincrementally."
  221. (interactive "sSearch for string: ")
  222. (setq menu-bar-last-search-type 'string)
  223. (if (equal string "")
  224. (search-forward (car search-ring))
  225. (isearch-update-ring string nil)
  226. (search-forward string)))
  227. (defun nonincremental-search-backward (string)
  228. "Read a string and search backward for it nonincrementally."
  229. (interactive "sSearch for string: ")
  230. (setq menu-bar-last-search-type 'string)
  231. (if (equal string "")
  232. (search-backward (car search-ring))
  233. (isearch-update-ring string nil)
  234. (search-backward string)))
  235. (defun nonincremental-re-search-forward (string)
  236. "Read a regular expression and search for it nonincrementally."
  237. (interactive "sSearch for regexp: ")
  238. (setq menu-bar-last-search-type 'regexp)
  239. (if (equal string "")
  240. (re-search-forward (car regexp-search-ring))
  241. (isearch-update-ring string t)
  242. (re-search-forward string)))
  243. (defun nonincremental-re-search-backward (string)
  244. "Read a regular expression and search backward for it nonincrementally."
  245. (interactive "sSearch for regexp: ")
  246. (setq menu-bar-last-search-type 'regexp)
  247. (if (equal string "")
  248. (re-search-backward (car regexp-search-ring))
  249. (isearch-update-ring string t)
  250. (re-search-backward string)))
  251. ;; The Edit->Search->Incremental Search menu
  252. (defvar menu-bar-i-search-menu
  253. (let ((menu (make-sparse-keymap "Incremental Search")))
  254. (define-key menu [isearch-backward-regexp]
  255. `(menu-item ,(purecopy "Backward Regexp...") isearch-backward-regexp
  256. :help ,(purecopy
  257. "Search backwards for a regular expression as you type it")))
  258. (define-key menu [isearch-forward-regexp]
  259. `(menu-item ,(purecopy "Forward Regexp...") isearch-forward-regexp
  260. :help ,(purecopy
  261. "Search forward for a regular expression as you type it")))
  262. (define-key menu [isearch-backward]
  263. `(menu-item ,(purecopy "Backward String...") isearch-backward
  264. :help ,(purecopy "Search backwards for a string as you type it")))
  265. (define-key menu [isearch-forward]
  266. `(menu-item ,(purecopy "Forward String...") isearch-forward
  267. :help ,(purecopy "Search forward for a string as you type it")))
  268. menu))
  269. (defvar menu-bar-search-menu
  270. (let ((menu (make-sparse-keymap "Search")))
  271. (define-key menu [i-search]
  272. `(menu-item ,(purecopy "Incremental Search") ,menu-bar-i-search-menu))
  273. (define-key menu [separator-tag-isearch]
  274. menu-bar-separator)
  275. (define-key menu [tags-continue]
  276. `(menu-item ,(purecopy "Continue Tags Search") tags-loop-continue
  277. :help ,(purecopy "Continue last tags search operation")))
  278. (define-key menu [tags-srch]
  279. `(menu-item ,(purecopy "Search Tagged Files...") tags-search
  280. :help ,(purecopy "Search for a regexp in all tagged files")))
  281. (define-key menu [separator-tag-search] menu-bar-separator)
  282. (define-key menu [repeat-search-back]
  283. `(menu-item ,(purecopy "Repeat Backwards")
  284. nonincremental-repeat-search-backward
  285. :enable (or (and (eq menu-bar-last-search-type 'string)
  286. search-ring)
  287. (and (eq menu-bar-last-search-type 'regexp)
  288. regexp-search-ring))
  289. :help ,(purecopy "Repeat last search backwards")))
  290. (define-key menu [repeat-search-fwd]
  291. `(menu-item ,(purecopy "Repeat Forward")
  292. nonincremental-repeat-search-forward
  293. :enable (or (and (eq menu-bar-last-search-type 'string)
  294. search-ring)
  295. (and (eq menu-bar-last-search-type 'regexp)
  296. regexp-search-ring))
  297. :help ,(purecopy "Repeat last search forward")))
  298. (define-key menu [separator-repeat-search]
  299. menu-bar-separator)
  300. (define-key menu [re-search-backward]
  301. `(menu-item ,(purecopy "Regexp Backwards...")
  302. nonincremental-re-search-backward
  303. :help ,(purecopy
  304. "Search backwards for a regular expression")))
  305. (define-key menu [re-search-forward]
  306. `(menu-item ,(purecopy "Regexp Forward...")
  307. nonincremental-re-search-forward
  308. :help ,(purecopy "Search forward for a regular expression")))
  309. (define-key menu [search-backward]
  310. `(menu-item ,(purecopy "String Backwards...")
  311. nonincremental-search-backward
  312. :help ,(purecopy "Search backwards for a string")))
  313. (define-key menu [search-forward]
  314. `(menu-item ,(purecopy "String Forward...") nonincremental-search-forward
  315. :help ,(purecopy "Search forward for a string")))
  316. menu))
  317. ;; The Edit->Replace submenu
  318. (defvar menu-bar-replace-menu
  319. (let ((menu (make-sparse-keymap "Replace")))
  320. (define-key menu [tags-repl-continue]
  321. `(menu-item ,(purecopy "Continue Replace") tags-loop-continue
  322. :help ,(purecopy "Continue last tags replace operation")))
  323. (define-key menu [tags-repl]
  324. `(menu-item ,(purecopy "Replace in Tagged Files...") tags-query-replace
  325. :help ,(purecopy
  326. "Interactively replace a regexp in all tagged files")))
  327. (define-key menu [separator-replace-tags]
  328. menu-bar-separator)
  329. (define-key menu [query-replace-regexp]
  330. `(menu-item ,(purecopy "Replace Regexp...") query-replace-regexp
  331. :enable (not buffer-read-only)
  332. :help ,(purecopy "Replace regular expression interactively, ask about each occurrence")))
  333. (define-key menu [query-replace]
  334. `(menu-item ,(purecopy "Replace String...") query-replace
  335. :enable (not buffer-read-only)
  336. :help ,(purecopy
  337. "Replace string interactively, ask about each occurrence")))
  338. menu))
  339. ;;; Assemble the top-level Edit menu items.
  340. (defvar menu-bar-goto-menu
  341. (let ((menu (make-sparse-keymap "Go To")))
  342. (define-key menu [set-tags-name]
  343. `(menu-item ,(purecopy "Set Tags File Name...") visit-tags-table
  344. :help ,(purecopy "Tell Tags commands which tag table file to use")))
  345. (define-key menu [separator-tag-file]
  346. menu-bar-separator)
  347. (define-key menu [apropos-tags]
  348. `(menu-item ,(purecopy "Tags Apropos...") tags-apropos
  349. :help ,(purecopy "Find function/variables whose names match regexp")))
  350. (define-key menu [next-tag-otherw]
  351. `(menu-item ,(purecopy "Next Tag in Other Window")
  352. menu-bar-next-tag-other-window
  353. :enable (and (boundp 'tags-location-ring)
  354. (not (ring-empty-p tags-location-ring)))
  355. :help ,(purecopy "Find next function/variable matching last tag name in another window")))
  356. (define-key menu [next-tag]
  357. `(menu-item ,(purecopy "Find Next Tag")
  358. menu-bar-next-tag
  359. :enable (and (boundp 'tags-location-ring)
  360. (not (ring-empty-p tags-location-ring)))
  361. :help ,(purecopy "Find next function/variable matching last tag name")))
  362. (define-key menu [find-tag-otherw]
  363. `(menu-item ,(purecopy "Find Tag in Other Window...") find-tag-other-window
  364. :help ,(purecopy "Find function/variable definition in another window")))
  365. (define-key menu [find-tag]
  366. `(menu-item ,(purecopy "Find Tag...") find-tag
  367. :help ,(purecopy "Find definition of function or variable")))
  368. (define-key menu [separator-tags]
  369. menu-bar-separator)
  370. (define-key menu [end-of-buf]
  371. `(menu-item ,(purecopy "Goto End of Buffer") end-of-buffer))
  372. (define-key menu [beg-of-buf]
  373. `(menu-item ,(purecopy "Goto Beginning of Buffer") beginning-of-buffer))
  374. (define-key menu [go-to-pos]
  375. `(menu-item ,(purecopy "Goto Buffer Position...") goto-char
  376. :help ,(purecopy "Read a number N and go to buffer position N")))
  377. (define-key menu [go-to-line]
  378. `(menu-item ,(purecopy "Goto Line...") goto-line
  379. :help ,(purecopy "Read a line number and go to that line")))
  380. menu))
  381. (defvar yank-menu (cons (purecopy "Select Yank") nil))
  382. (fset 'yank-menu (cons 'keymap yank-menu))
  383. (defvar menu-bar-edit-menu
  384. (let ((menu (make-sparse-keymap "Edit")))
  385. (define-key menu [props]
  386. `(menu-item ,(purecopy "Text Properties") facemenu-menu))
  387. ;; ns-win.el said: Add spell for platform consistency.
  388. (if (featurep 'ns)
  389. (define-key menu [spell]
  390. `(menu-item ,(purecopy "Spell") ispell-menu-map)))
  391. (define-key menu [fill]
  392. `(menu-item ,(purecopy "Fill") fill-region
  393. :enable (and mark-active (not buffer-read-only))
  394. :help
  395. ,(purecopy "Fill text in region to fit between left and right margin")))
  396. (define-key menu [separator-bookmark]
  397. menu-bar-separator)
  398. (define-key menu [bookmark]
  399. `(menu-item ,(purecopy "Bookmarks") menu-bar-bookmark-map))
  400. (define-key menu [goto]
  401. `(menu-item ,(purecopy "Go To") ,menu-bar-goto-menu))
  402. (define-key menu [replace]
  403. `(menu-item ,(purecopy "Replace") ,menu-bar-replace-menu))
  404. (define-key menu [search]
  405. `(menu-item ,(purecopy "Search") ,menu-bar-search-menu))
  406. (define-key menu [separator-search]
  407. menu-bar-separator)
  408. (define-key menu [mark-whole-buffer]
  409. `(menu-item ,(purecopy "Select All") mark-whole-buffer
  410. :help ,(purecopy "Mark the whole buffer for a subsequent cut/copy")))
  411. (define-key menu [clear]
  412. `(menu-item ,(purecopy "Clear") delete-region
  413. :enable (and mark-active
  414. (not buffer-read-only))
  415. :help
  416. ,(purecopy "Delete the text in region between mark and current position")))
  417. (define-key menu (if (featurep 'ns) [select-paste]
  418. [paste-from-menu])
  419. ;; ns-win.el said: Change text to be more consistent with
  420. ;; surrounding menu items `paste', etc."
  421. `(menu-item ,(purecopy (if (featurep 'ns) "Select and Paste"
  422. "Paste from Kill Menu")) yank-menu
  423. :enable (and (cdr yank-menu) (not buffer-read-only))
  424. :help ,(purecopy "Choose a string from the kill ring and paste it")))
  425. (define-key menu [paste]
  426. `(menu-item ,(purecopy "Paste") yank
  427. :enable (and (or
  428. ;; Emacs compiled --without-x (or --with-ns)
  429. ;; doesn't have x-selection-exists-p.
  430. (and (fboundp 'x-selection-exists-p)
  431. (x-selection-exists-p 'CLIPBOARD))
  432. (if (featurep 'ns) ; like paste-from-menu
  433. (cdr yank-menu)
  434. kill-ring))
  435. (not buffer-read-only))
  436. :help ,(purecopy "Paste (yank) text most recently cut/copied")))
  437. (define-key menu [copy]
  438. ;; ns-win.el said: Substitute a Copy function that works better
  439. ;; under X (for GNUstep).
  440. `(menu-item ,(purecopy "Copy") ,(if (featurep 'ns)
  441. 'ns-copy-including-secondary
  442. 'kill-ring-save)
  443. :enable mark-active
  444. :help ,(purecopy "Copy text in region between mark and current position")
  445. :keys ,(purecopy (if (featurep 'ns)
  446. "\\[ns-copy-including-secondary]"
  447. "\\[kill-ring-save]"))))
  448. (define-key menu [cut]
  449. `(menu-item ,(purecopy "Cut") kill-region
  450. :enable (and mark-active (not buffer-read-only))
  451. :help
  452. ,(purecopy "Cut (kill) text in region between mark and current position")))
  453. ;; ns-win.el said: Separate undo from cut/paste section.
  454. (if (featurep 'ns)
  455. (define-key menu [separator-undo] menu-bar-separator))
  456. (define-key menu [undo]
  457. `(menu-item ,(purecopy "Undo") undo
  458. :enable (and (not buffer-read-only)
  459. (not (eq t buffer-undo-list))
  460. (if (eq last-command 'undo)
  461. (listp pending-undo-list)
  462. (consp buffer-undo-list)))
  463. :help ,(purecopy "Undo last operation")))
  464. menu))
  465. (defun menu-bar-next-tag-other-window ()
  466. "Find the next definition of the tag already specified."
  467. (interactive)
  468. (find-tag-other-window nil t))
  469. (defun menu-bar-next-tag ()
  470. "Find the next definition of the tag already specified."
  471. (interactive)
  472. (find-tag nil t))
  473. (define-obsolete-function-alias
  474. 'menu-bar-kill-ring-save 'kill-ring-save "24.1")
  475. ;; These are alternative definitions for the cut, paste and copy
  476. ;; menu items. Use them if your system expects these to use the clipboard.
  477. (put 'clipboard-kill-region 'menu-enable
  478. '(and mark-active (not buffer-read-only)))
  479. (put 'clipboard-kill-ring-save 'menu-enable 'mark-active)
  480. (put 'clipboard-yank 'menu-enable
  481. '(and (or (not (fboundp 'x-selection-exists-p))
  482. (x-selection-exists-p)
  483. (x-selection-exists-p 'CLIPBOARD))
  484. (not buffer-read-only)))
  485. (defun clipboard-yank ()
  486. "Insert the clipboard contents, or the last stretch of killed text."
  487. (interactive "*")
  488. (let ((x-select-enable-clipboard t))
  489. (yank)))
  490. (defun clipboard-kill-ring-save (beg end)
  491. "Copy region to kill ring, and save in the X clipboard."
  492. (interactive "r")
  493. (let ((x-select-enable-clipboard t))
  494. (kill-ring-save beg end)))
  495. (defun clipboard-kill-region (beg end)
  496. "Kill the region, and save it in the X clipboard."
  497. (interactive "r")
  498. (let ((x-select-enable-clipboard t))
  499. (kill-region beg end)))
  500. (defun menu-bar-enable-clipboard ()
  501. "Make CUT, PASTE and COPY (keys and menu bar items) use the clipboard.
  502. Do the same for the keys of the same name."
  503. (interactive)
  504. ;; These are Sun server keysyms for the Cut, Copy and Paste keys
  505. ;; (also for XFree86 on Sun keyboard):
  506. (define-key global-map [f20] 'clipboard-kill-region)
  507. (define-key global-map [f16] 'clipboard-kill-ring-save)
  508. (define-key global-map [f18] 'clipboard-yank)
  509. ;; X11R6 versions:
  510. (define-key global-map [cut] 'clipboard-kill-region)
  511. (define-key global-map [copy] 'clipboard-kill-ring-save)
  512. (define-key global-map [paste] 'clipboard-yank))
  513. ;; The "Options" menu items
  514. (defvar menu-bar-custom-menu
  515. (let ((menu (make-sparse-keymap "Customize")))
  516. (define-key menu [customize-apropos-faces]
  517. `(menu-item ,(purecopy "Faces Matching...") customize-apropos-faces
  518. :help ,(purecopy "Browse faces matching a regexp or word list")))
  519. (define-key menu [customize-apropos-options]
  520. `(menu-item ,(purecopy "Options Matching...") customize-apropos-options
  521. :help ,(purecopy "Browse options matching a regexp or word list")))
  522. (define-key menu [customize-apropos]
  523. `(menu-item ,(purecopy "All Settings Matching...") customize-apropos
  524. :help ,(purecopy "Browse customizable settings matching a regexp or word list")))
  525. (define-key menu [separator-1]
  526. menu-bar-separator)
  527. (define-key menu [customize-group]
  528. `(menu-item ,(purecopy "Specific Group...") customize-group
  529. :help ,(purecopy "Customize settings of specific group")))
  530. (define-key menu [customize-face]
  531. `(menu-item ,(purecopy "Specific Face...") customize-face
  532. :help ,(purecopy "Customize attributes of specific face")))
  533. (define-key menu [customize-option]
  534. `(menu-item ,(purecopy "Specific Option...") customize-option
  535. :help ,(purecopy "Customize value of specific option")))
  536. (define-key menu [separator-2]
  537. menu-bar-separator)
  538. (define-key menu [customize-changed-options]
  539. `(menu-item ,(purecopy "New Options...") customize-changed-options
  540. :help ,(purecopy "Options added or changed in recent Emacs versions")))
  541. (define-key menu [customize-saved]
  542. `(menu-item ,(purecopy "Saved Options") customize-saved
  543. :help ,(purecopy "Customize previously saved options")))
  544. (define-key menu [separator-3]
  545. menu-bar-separator)
  546. (define-key menu [customize-browse]
  547. `(menu-item ,(purecopy "Browse Customization Groups") customize-browse
  548. :help ,(purecopy "Browse all customization groups")))
  549. (define-key menu [customize]
  550. `(menu-item ,(purecopy "Top-level Customization Group") customize
  551. :help ,(purecopy "The master group called `Emacs'")))
  552. (define-key menu [customize-themes]
  553. `(menu-item ,(purecopy "Custom Themes") customize-themes
  554. :help ,(purecopy "Choose a pre-defined customization theme")))
  555. menu))
  556. ;(defvar menu-bar-preferences-menu (make-sparse-keymap "Preferences"))
  557. (defmacro menu-bar-make-mm-toggle (fname doc help &optional props)
  558. "Make a menu-item for a global minor mode toggle.
  559. FNAME is the minor mode's name (variable and function).
  560. DOC is the text to use for the menu entry.
  561. HELP is the text to use for the tooltip.
  562. PROPS are additional properties."
  563. `(list 'menu-item (purecopy ,doc) ',fname
  564. ,@(mapcar (lambda (p) (list 'quote p)) props)
  565. :help (purecopy ,help)
  566. :button '(:toggle . (and (default-boundp ',fname)
  567. (default-value ',fname)))))
  568. (defmacro menu-bar-make-toggle (name variable doc message help &rest body)
  569. `(progn
  570. (defun ,name (&optional interactively)
  571. ,(concat "Toggle whether to " (downcase (substring help 0 1))
  572. (substring help 1) ".
  573. In an interactive call, record this option as a candidate for saving
  574. by \"Save Options\" in Custom buffers.")
  575. (interactive "p")
  576. (if ,(if body `(progn . ,body)
  577. `(progn
  578. (custom-load-symbol ',variable)
  579. (let ((set (or (get ',variable 'custom-set) 'set-default))
  580. (get (or (get ',variable 'custom-get) 'default-value)))
  581. (funcall set ',variable (not (funcall get ',variable))))))
  582. (message ,message "enabled globally")
  583. (message ,message "disabled globally"))
  584. ;; The function `customize-mark-as-set' must only be called when
  585. ;; a variable is set interactively, as the purpose is to mark it as
  586. ;; a candidate for "Save Options", and we do not want to save options
  587. ;; the user have already set explicitly in his init file.
  588. (if interactively (customize-mark-as-set ',variable)))
  589. (list 'menu-item (purecopy ,doc) ',name
  590. :help (purecopy ,help)
  591. :button '(:toggle . (and (default-boundp ',variable)
  592. (default-value ',variable))))))
  593. ;; Function for setting/saving default font.
  594. (defun menu-set-font ()
  595. "Interactively select a font and make it the default."
  596. (interactive)
  597. (set-frame-font (if (fboundp 'x-select-font)
  598. (x-select-font)
  599. (mouse-select-font))
  600. nil t))
  601. (defun menu-bar-options-save ()
  602. "Save current values of Options menu items using Custom."
  603. (interactive)
  604. (let ((need-save nil))
  605. ;; These are set with menu-bar-make-mm-toggle, which does not
  606. ;; put on a customized-value property.
  607. (dolist (elt '(line-number-mode column-number-mode size-indication-mode
  608. cua-mode show-paren-mode transient-mark-mode
  609. blink-cursor-mode display-time-mode display-battery-mode
  610. ;; These are set by other functions that don't set
  611. ;; the customized state. Having them here has the
  612. ;; side-effect that turning them off via X
  613. ;; resources acts like having customized them, but
  614. ;; that seems harmless.
  615. menu-bar-mode tool-bar-mode))
  616. ;; FIXME ? It's a little annoying that running this command
  617. ;; always loads cua-base, paren, time, and battery, even if they
  618. ;; have not been customized in any way. (Due to custom-load-symbol.)
  619. (and (customize-mark-to-save elt)
  620. (setq need-save t)))
  621. ;; These are set with `customize-set-variable'.
  622. (dolist (elt '(scroll-bar-mode
  623. debug-on-quit debug-on-error
  624. ;; Somehow this works, when tool-bar and menu-bar don't.
  625. tooltip-mode
  626. save-place uniquify-buffer-name-style fringe-mode
  627. indicate-empty-lines indicate-buffer-boundaries
  628. case-fold-search font-use-system-font
  629. current-language-environment default-input-method
  630. ;; Saving `text-mode-hook' is somewhat questionable,
  631. ;; as we might get more than we bargain for, if
  632. ;; other code may has added hooks as well.
  633. ;; Nonetheless, not saving it would like be confuse
  634. ;; more often.
  635. ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2002-02-11.
  636. text-mode-hook tool-bar-position))
  637. (and (get elt 'customized-value)
  638. (customize-mark-to-save elt)
  639. (setq need-save t)))
  640. (when (get 'default 'customized-face)
  641. (put 'default 'saved-face (get 'default 'customized-face))
  642. (put 'default 'customized-face nil)
  643. (setq need-save t))
  644. ;; Save if we changed anything.
  645. (when need-save
  646. (custom-save-all))))
  647. ;;; Assemble all the top-level items of the "Options" menu
  648. ;; The "Show/Hide" submenu of menu "Options"
  649. (defun menu-bar-showhide-fringe-ind-customize ()
  650. "Show customization buffer for `indicate-buffer-boundaries'."
  651. (interactive)
  652. (customize-variable 'indicate-buffer-boundaries))
  653. (defun menu-bar-showhide-fringe-ind-mixed ()
  654. "Display top and bottom indicators in opposite fringes, arrows in right."
  655. (interactive)
  656. (customize-set-variable 'indicate-buffer-boundaries
  657. '((t . right) (top . left))))
  658. (defun menu-bar-showhide-fringe-ind-box ()
  659. "Display top and bottom indicators in opposite fringes."
  660. (interactive)
  661. (customize-set-variable 'indicate-buffer-boundaries
  662. '((top . left) (bottom . right))))
  663. (defun menu-bar-showhide-fringe-ind-right ()
  664. "Display buffer boundaries and arrows in the right fringe."
  665. (interactive)
  666. (customize-set-variable 'indicate-buffer-boundaries 'right))
  667. (defun menu-bar-showhide-fringe-ind-left ()
  668. "Display buffer boundaries and arrows in the left fringe."
  669. (interactive)
  670. (customize-set-variable 'indicate-buffer-boundaries 'left))
  671. (defun menu-bar-showhide-fringe-ind-none ()
  672. "Do not display any buffer boundary indicators."
  673. (interactive)
  674. (customize-set-variable 'indicate-buffer-boundaries nil))
  675. (defvar menu-bar-showhide-fringe-ind-menu
  676. (let ((menu (make-sparse-keymap "Buffer boundaries")))
  677. (define-key menu [customize]
  678. `(menu-item ,(purecopy "Other (Customize)")
  679. menu-bar-showhide-fringe-ind-customize
  680. :help ,(purecopy "Additional choices available through Custom buffer")
  681. :visible (display-graphic-p)
  682. :button (:radio . (not (member indicate-buffer-boundaries
  683. '(nil left right
  684. ((top . left) (bottom . right))
  685. ((t . right) (top . left))))))))
  686. (define-key menu [mixed]
  687. `(menu-item ,(purecopy "Opposite, Arrows Right") menu-bar-showhide-fringe-ind-mixed
  688. :help
  689. ,(purecopy "Show top/bottom indicators in opposite fringes, arrows in right")
  690. :visible (display-graphic-p)
  691. :button (:radio . (equal indicate-buffer-boundaries
  692. '((t . right) (top . left))))))
  693. (define-key menu [box]
  694. `(menu-item ,(purecopy "Opposite, No Arrows") menu-bar-showhide-fringe-ind-box
  695. :help ,(purecopy "Show top/bottom indicators in opposite fringes, no arrows")
  696. :visible (display-graphic-p)
  697. :button (:radio . (equal indicate-buffer-boundaries
  698. '((top . left) (bottom . right))))))
  699. (define-key menu [right]
  700. `(menu-item ,(purecopy "In Right Fringe") menu-bar-showhide-fringe-ind-right
  701. :help ,(purecopy "Show buffer boundaries and arrows in right fringe")
  702. :visible (display-graphic-p)
  703. :button (:radio . (eq indicate-buffer-boundaries 'right))))
  704. (define-key menu [left]
  705. `(menu-item ,(purecopy "In Left Fringe") menu-bar-showhide-fringe-ind-left
  706. :help ,(purecopy "Show buffer boundaries and arrows in left fringe")
  707. :visible (display-graphic-p)
  708. :button (:radio . (eq indicate-buffer-boundaries 'left))))
  709. (define-key menu [none]
  710. `(menu-item ,(purecopy "No Indicators") menu-bar-showhide-fringe-ind-none
  711. :help ,(purecopy "Hide all buffer boundary indicators and arrows")
  712. :visible (display-graphic-p)
  713. :button (:radio . (eq indicate-buffer-boundaries nil))))
  714. menu))
  715. (defun menu-bar-showhide-fringe-menu-customize ()
  716. "Show customization buffer for `fringe-mode'."
  717. (interactive)
  718. (customize-variable 'fringe-mode))
  719. (defun menu-bar-showhide-fringe-menu-customize-reset ()
  720. "Reset the fringe mode: display fringes on both sides of a window."
  721. (interactive)
  722. (customize-set-variable 'fringe-mode nil))
  723. (defun menu-bar-showhide-fringe-menu-customize-right ()
  724. "Display fringes only on the right of each window."
  725. (interactive)
  726. (require 'fringe)
  727. (customize-set-variable 'fringe-mode '(0 . nil)))
  728. (defun menu-bar-showhide-fringe-menu-customize-left ()
  729. "Display fringes only on the left of each window."
  730. (interactive)
  731. (require 'fringe)
  732. (customize-set-variable 'fringe-mode '(nil . 0)))
  733. (defun menu-bar-showhide-fringe-menu-customize-disable ()
  734. "Do not display window fringes."
  735. (interactive)
  736. (require 'fringe)
  737. (customize-set-variable 'fringe-mode 0))
  738. (defvar menu-bar-showhide-fringe-menu
  739. (let ((menu (make-sparse-keymap "Fringe")))
  740. (define-key menu [showhide-fringe-ind]
  741. `(menu-item ,(purecopy "Buffer Boundaries") ,menu-bar-showhide-fringe-ind-menu
  742. :visible (display-graphic-p)
  743. :help ,(purecopy "Indicate buffer boundaries in fringe")))
  744. (define-key menu [indicate-empty-lines]
  745. (menu-bar-make-toggle toggle-indicate-empty-lines indicate-empty-lines
  746. "Empty Line Indicators"
  747. "Indicating of empty lines %s"
  748. "Indicate trailing empty lines in fringe, globally"))
  749. (define-key menu [customize]
  750. `(menu-item ,(purecopy "Customize Fringe") menu-bar-showhide-fringe-menu-customize
  751. :help ,(purecopy "Detailed customization of fringe")
  752. :visible (display-graphic-p)))
  753. (define-key menu [default]
  754. `(menu-item ,(purecopy "Default") menu-bar-showhide-fringe-menu-customize-reset
  755. :help ,(purecopy "Default width fringe on both left and right side")
  756. :visible (display-graphic-p)
  757. :button (:radio . (eq fringe-mode nil))))
  758. (define-key menu [right]
  759. `(menu-item ,(purecopy "On the Right") menu-bar-showhide-fringe-menu-customize-right
  760. :help ,(purecopy "Fringe only on the right side")
  761. :visible (display-graphic-p)
  762. :button (:radio . (equal fringe-mode '(0 . nil)))))
  763. (define-key menu [left]
  764. `(menu-item ,(purecopy "On the Left") menu-bar-showhide-fringe-menu-customize-left
  765. :help ,(purecopy "Fringe only on the left side")
  766. :visible (display-graphic-p)
  767. :button (:radio . (equal fringe-mode '(nil . 0)))))
  768. (define-key menu [none]
  769. `(menu-item ,(purecopy "None") menu-bar-showhide-fringe-menu-customize-disable
  770. :help ,(purecopy "Turn off fringe")
  771. :visible (display-graphic-p)
  772. :button (:radio . (eq fringe-mode 0))))
  773. menu))
  774. (defun menu-bar-right-scroll-bar ()
  775. "Display scroll bars on the right of each window."
  776. (interactive)
  777. (customize-set-variable 'scroll-bar-mode 'right))
  778. (defun menu-bar-left-scroll-bar ()
  779. "Display scroll bars on the left of each window."
  780. (interactive)
  781. (customize-set-variable 'scroll-bar-mode 'left))
  782. (defun menu-bar-no-scroll-bar ()
  783. "Turn off scroll bars."
  784. (interactive)
  785. (customize-set-variable 'scroll-bar-mode nil))
  786. (defvar menu-bar-showhide-scroll-bar-menu
  787. (let ((menu (make-sparse-keymap "Scroll-bar")))
  788. (define-key menu [right]
  789. `(menu-item ,(purecopy "On the Right")
  790. menu-bar-right-scroll-bar
  791. :help ,(purecopy "Scroll-bar on the right side")
  792. :visible (display-graphic-p)
  793. :button (:radio . (eq (cdr (assq 'vertical-scroll-bars
  794. (frame-parameters))) 'right))))
  795. (define-key menu [left]
  796. `(menu-item ,(purecopy "On the Left")
  797. menu-bar-left-scroll-bar
  798. :help ,(purecopy "Scroll-bar on the left side")
  799. :visible (display-graphic-p)
  800. :button (:radio . (eq (cdr (assq 'vertical-scroll-bars
  801. (frame-parameters))) 'left))))
  802. (define-key menu [none]
  803. `(menu-item ,(purecopy "None")
  804. menu-bar-no-scroll-bar
  805. :help ,(purecopy "Turn off scroll-bar")
  806. :visible (display-graphic-p)
  807. :button (:radio . (eq (cdr (assq 'vertical-scroll-bars
  808. (frame-parameters))) nil))))
  809. menu))
  810. (defun menu-bar-frame-for-menubar ()
  811. "Return the frame suitable for updating the menu bar."
  812. (or (and (framep menu-updating-frame)
  813. menu-updating-frame)
  814. (selected-frame)))
  815. (defun menu-bar-positive-p (val)
  816. "Return non-nil iff VAL is a positive number."
  817. (and (numberp val)
  818. (> val 0)))
  819. (defun menu-bar-set-tool-bar-position (position)
  820. (customize-set-variable 'tool-bar-mode t)
  821. (customize-set-variable 'tool-bar-position position))
  822. (defun menu-bar-showhide-tool-bar-menu-customize-disable ()
  823. "Do not display tool bars."
  824. (interactive)
  825. (customize-set-variable 'tool-bar-mode nil))
  826. (defun menu-bar-showhide-tool-bar-menu-customize-enable-left ()
  827. "Display tool bars on the left side."
  828. (interactive)
  829. (menu-bar-set-tool-bar-position 'left))
  830. (defun menu-bar-showhide-tool-bar-menu-customize-enable-right ()
  831. "Display tool bars on the right side."
  832. (interactive)
  833. (menu-bar-set-tool-bar-position 'right))
  834. (defun menu-bar-showhide-tool-bar-menu-customize-enable-top ()
  835. "Display tool bars on the top side."
  836. (interactive)
  837. (menu-bar-set-tool-bar-position 'top))
  838. (defun menu-bar-showhide-tool-bar-menu-customize-enable-bottom ()
  839. "Display tool bars on the bottom side."
  840. (interactive)
  841. (menu-bar-set-tool-bar-position 'bottom))
  842. (when (featurep 'move-toolbar)
  843. (defvar menu-bar-showhide-tool-bar-menu
  844. (let ((menu (make-sparse-keymap "Tool-bar")))
  845. (define-key menu [showhide-tool-bar-left]
  846. `(menu-item ,(purecopy "On the Left")
  847. menu-bar-showhide-tool-bar-menu-customize-enable-left
  848. :help ,(purecopy "Tool-bar at the left side")
  849. :visible (display-graphic-p)
  850. :button
  851. (:radio . (and tool-bar-mode
  852. (eq (frame-parameter
  853. (menu-bar-frame-for-menubar)
  854. 'tool-bar-position)
  855. 'left)))))
  856. (define-key menu [showhide-tool-bar-right]
  857. `(menu-item ,(purecopy "On the Right")
  858. menu-bar-showhide-tool-bar-menu-customize-enable-right
  859. :help ,(purecopy "Tool-bar at the right side")
  860. :visible (display-graphic-p)
  861. :button
  862. (:radio . (and tool-bar-mode
  863. (eq (frame-parameter
  864. (menu-bar-frame-for-menubar)
  865. 'tool-bar-position)
  866. 'right)))))
  867. (define-key menu [showhide-tool-bar-bottom]
  868. `(menu-item ,(purecopy "On the Bottom")
  869. menu-bar-showhide-tool-bar-menu-customize-enable-bottom
  870. :help ,(purecopy "Tool-bar at the bottom")
  871. :visible (display-graphic-p)
  872. :button
  873. (:radio . (and tool-bar-mode
  874. (eq (frame-parameter
  875. (menu-bar-frame-for-menubar)
  876. 'tool-bar-position)
  877. 'bottom)))))
  878. (define-key menu [showhide-tool-bar-top]
  879. `(menu-item ,(purecopy "On the Top")
  880. menu-bar-showhide-tool-bar-menu-customize-enable-top
  881. :help ,(purecopy "Tool-bar at the top")
  882. :visible (display-graphic-p)
  883. :button
  884. (:radio . (and tool-bar-mode
  885. (eq (frame-parameter
  886. (menu-bar-frame-for-menubar)
  887. 'tool-bar-position)
  888. 'top)))))
  889. (define-key menu [showhide-tool-bar-none]
  890. `(menu-item ,(purecopy "None")
  891. menu-bar-showhide-tool-bar-menu-customize-disable
  892. :help ,(purecopy "Turn tool-bar off")
  893. :visible (display-graphic-p)
  894. :button (:radio . (eq tool-bar-mode nil))))
  895. menu)))
  896. (defvar menu-bar-showhide-menu
  897. (let ((menu (make-sparse-keymap "Show/Hide")))
  898. (define-key menu [column-number-mode]
  899. (menu-bar-make-mm-toggle column-number-mode
  900. "Column Numbers"
  901. "Show the current column number in the mode line"))
  902. (define-key menu [line-number-mode]
  903. (menu-bar-make-mm-toggle line-number-mode
  904. "Line Numbers"
  905. "Show the current line number in the mode line"))
  906. (define-key menu [size-indication-mode]
  907. (menu-bar-make-mm-toggle size-indication-mode
  908. "Size Indication"
  909. "Show the size of the buffer in the mode line"))
  910. (define-key menu [linecolumn-separator]
  911. menu-bar-separator)
  912. (define-key menu [showhide-battery]
  913. (menu-bar-make-mm-toggle display-battery-mode
  914. "Battery Status"
  915. "Display battery status information in mode line"))
  916. (define-key menu [showhide-date-time]
  917. (menu-bar-make-mm-toggle display-time-mode
  918. "Time, Load and Mail"
  919. "Display time, system load averages and \
  920. mail status in mode line"))
  921. (define-key menu [datetime-separator]
  922. menu-bar-separator)
  923. (define-key menu [showhide-speedbar]
  924. `(menu-item ,(purecopy "Speedbar") speedbar-frame-mode
  925. :help ,(purecopy "Display a Speedbar quick-navigation frame")
  926. :button (:toggle
  927. . (and (boundp 'speedbar-frame)
  928. (frame-live-p (symbol-value 'speedbar-frame))
  929. (frame-visible-p
  930. (symbol-value 'speedbar-frame))))))
  931. (define-key menu [showhide-fringe]
  932. `(menu-item ,(purecopy "Fringe") ,menu-bar-showhide-fringe-menu
  933. :visible (display-graphic-p)))
  934. (define-key menu [showhide-scroll-bar]
  935. `(menu-item ,(purecopy "Scroll-bar") ,menu-bar-showhide-scroll-bar-menu
  936. :visible (display-graphic-p)))
  937. (define-key menu [showhide-tooltip-mode]
  938. `(menu-item ,(purecopy "Tooltips") tooltip-mode
  939. :help ,(purecopy "Turn tooltips on/off")
  940. :visible (and (display-graphic-p) (fboundp 'x-show-tip))
  941. :button (:toggle . tooltip-mode)))
  942. (define-key menu [menu-bar-mode]
  943. `(menu-item ,(purecopy "Menu-bar") toggle-menu-bar-mode-from-frame
  944. :help ,(purecopy "Turn menu-bar on/off")
  945. :button
  946. (:toggle . (menu-bar-positive-p
  947. (frame-parameter (menu-bar-frame-for-menubar)
  948. 'menu-bar-lines)))))
  949. (if (and (boundp 'menu-bar-showhide-tool-bar-menu)
  950. (keymapp menu-bar-showhide-tool-bar-menu))
  951. (define-key menu [showhide-tool-bar]
  952. `(menu-item ,(purecopy "Tool-bar") ,menu-bar-showhide-tool-bar-menu
  953. :visible (display-graphic-p)))
  954. ;; else not tool bar that can move.
  955. (define-key menu [showhide-tool-bar]
  956. `(menu-item ,(purecopy "Tool-bar") toggle-tool-bar-mode-from-frame
  957. :help ,(purecopy "Turn tool-bar on/off")
  958. :visible (display-graphic-p)
  959. :button
  960. (:toggle . (menu-bar-positive-p
  961. (frame-parameter (menu-bar-frame-for-menubar)
  962. 'tool-bar-lines))))))
  963. menu))
  964. (defun menu-bar-text-mode-auto-fill ()
  965. (interactive)
  966. (toggle-text-mode-auto-fill)
  967. ;; This is somewhat questionable, as `text-mode-hook'
  968. ;; might have changed outside customize.
  969. ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2002-02-11.
  970. (customize-mark-as-set 'text-mode-hook))
  971. (defvar menu-bar-line-wrapping-menu
  972. (let ((menu (make-sparse-keymap "Line Wrapping")))
  973. (define-key menu [word-wrap]
  974. `(menu-item
  975. ,(purecopy "Word Wrap (Visual Line mode)")
  976. (lambda ()
  977. (interactive)
  978. (unless visual-line-mode
  979. (visual-line-mode 1))
  980. (message ,(purecopy "Visual-Line mode enabled")))
  981. :help ,(purecopy "Wrap long lines at word boundaries")
  982. :button (:radio . (and (null truncate-lines)
  983. (not (truncated-partial-width-window-p))
  984. word-wrap))
  985. :visible (menu-bar-menu-frame-live-and-visible-p)))
  986. (define-key menu [truncate]
  987. `(menu-item ,(purecopy "Truncate Long Lines")
  988. (lambda ()
  989. (interactive)
  990. (if visual-line-mode (visual-line-mode 0))
  991. (setq word-wrap nil)
  992. (toggle-truncate-lines 1))
  993. :help ,(purecopy "Truncate long lines at window edge")
  994. :button (:radio . (or truncate-lines
  995. (truncated-partial-width-window-p)))
  996. :visible (menu-bar-menu-frame-live-and-visible-p)
  997. :enable (not (truncated-partial-width-window-p))))
  998. (define-key menu [window-wrap]
  999. `(menu-item ,(purecopy "Wrap at Window Edge")
  1000. (lambda () (interactive)
  1001. (if visual-line-mode (visual-line-mode 0))
  1002. (setq word-wrap nil)
  1003. (if truncate-lines (toggle-truncate-lines -1)))
  1004. :help ,(purecopy "Wrap long lines at window edge")
  1005. :button (:radio . (and (null truncate-lines)
  1006. (not (truncated-partial-width-window-p))
  1007. (not word-wrap)))
  1008. :visible (menu-bar-menu-frame-live-and-visible-p)
  1009. :enable (not (truncated-partial-width-window-p))))
  1010. menu))
  1011. (defvar menu-bar-options-menu
  1012. (let ((menu (make-sparse-keymap "Options")))
  1013. (define-key menu [customize]
  1014. `(menu-item ,(purecopy "Customize Emacs") ,menu-bar-custom-menu))
  1015. (define-key menu [package]
  1016. '(menu-item "Manage Emacs Packages" package-list-packages
  1017. :help "Install or uninstall additional Emacs packages"))
  1018. (define-key menu [save]
  1019. `(menu-item ,(purecopy "Save Options") menu-bar-options-save
  1020. :help ,(purecopy "Save options set from the menu above")))
  1021. (define-key menu [custom-separator]
  1022. menu-bar-separator)
  1023. (define-key menu [menu-set-font]
  1024. `(menu-item ,(purecopy "Set Default Font...") menu-set-font
  1025. :visible (display-multi-font-p)
  1026. :help ,(purecopy "Select a default font")))
  1027. (if (featurep 'system-font-setting)
  1028. (define-key menu [menu-system-font]
  1029. (menu-bar-make-toggle
  1030. toggle-use-system-font font-use-system-font
  1031. "Use System Font"
  1032. "Use system font: %s"
  1033. "Use the monospaced font defined by the system")))
  1034. (define-key menu [showhide]
  1035. `(menu-item ,(purecopy "Show/Hide") ,menu-bar-showhide-menu))
  1036. (define-key menu [showhide-separator]
  1037. menu-bar-separator)
  1038. (define-key menu [mule]
  1039. ;; It is better not to use backquote here,
  1040. ;; because that makes a bootstrapping problem
  1041. ;; if you need to recompile all the Lisp files using interpreted code.
  1042. `(menu-item ,(purecopy "Multilingual Environment") ,mule-menu-keymap
  1043. ;; Most of the MULE menu actually does make sense in
  1044. ;; unibyte mode, e.g. language selection.
  1045. ;; :visible '(default-value 'enable-multibyte-characters)
  1046. ))
  1047. ;;(setq menu-bar-final-items (cons 'mule menu-bar-final-items))
  1048. ;;(define-key menu [preferences]
  1049. ;; `(menu-item ,(purecopy "Preferences") ,menu-bar-preferences-menu
  1050. ;; :help ,(purecopy "Toggle important global options")))
  1051. (define-key menu [mule-separator]
  1052. menu-bar-separator)
  1053. (define-key menu [debug-on-quit]
  1054. (menu-bar-make-toggle toggle-debug-on-quit debug-on-quit
  1055. "Enter Debugger on Quit/C-g" "Debug on Quit %s"
  1056. "Enter Lisp debugger when C-g is pressed"))
  1057. (define-key menu [debug-on-error]
  1058. (menu-bar-make-toggle toggle-debug-on-error debug-on-error
  1059. "Enter Debugger on Error" "Debug on Error %s"
  1060. "Enter Lisp debugger when an error is signaled"))
  1061. (define-key menu [debugger-separator]
  1062. menu-bar-separator)
  1063. (define-key menu [blink-cursor-mode]
  1064. (menu-bar-make-mm-toggle
  1065. blink-cursor-mode
  1066. "Blink Cursor"
  1067. "Whether the cursor blinks (Blink Cursor mode)"))
  1068. (define-key menu [cursor-separator]
  1069. menu-bar-separator)
  1070. (define-key menu [save-place]
  1071. (menu-bar-make-toggle
  1072. toggle-save-place-globally save-place
  1073. "Save Place in Files between Sessions"
  1074. "Saving place in files %s"
  1075. "Visit files of previous session when restarting Emacs"
  1076. (require 'saveplace)
  1077. ;; Do it by name, to avoid a free-variable
  1078. ;; warning during byte compilation.
  1079. (set-default
  1080. 'save-place (not (symbol-value 'save-place)))))
  1081. (define-key menu [uniquify]
  1082. (menu-bar-make-toggle
  1083. toggle-uniquify-buffer-names uniquify-buffer-name-style
  1084. "Use Directory Names in Buffer Names"
  1085. "Directory name in buffer names (uniquify) %s"
  1086. "Uniquify buffer names by adding parent directory names"
  1087. (require 'uniquify)
  1088. (setq uniquify-buffer-name-style
  1089. (if (not uniquify-buffer-name-style)
  1090. 'forward))))
  1091. (define-key menu [edit-options-separator]
  1092. menu-bar-separator)
  1093. (define-key menu [cua-mode]
  1094. (menu-bar-make-mm-toggle
  1095. cua-mode
  1096. "Use CUA Keys (Cut/Paste with C-x/C-c/C-v)"
  1097. "Use C-z/C-x/C-c/C-v keys for undo/cut/copy/paste"
  1098. (:visible (or (not (boundp 'cua-enable-cua-keys))
  1099. cua-enable-cua-keys))))
  1100. (define-key menu [cua-emulation-mode]
  1101. (menu-bar-make-mm-toggle
  1102. cua-mode
  1103. "Shift movement mark region (CUA)"
  1104. "Use shifted movement keys to set and extend the region"
  1105. (:visible (and (boundp 'cua-enable-cua-keys)
  1106. (not cua-enable-cua-keys)))))
  1107. (define-key menu [case-fold-search]
  1108. (menu-bar-make-toggle
  1109. toggle-case-fold-search case-fold-search
  1110. "Ignore Case for Search"
  1111. "Case-Insensitive Search %s"
  1112. "Ignore letter-case in search commands"))
  1113. (define-key menu [auto-fill-mode]
  1114. `(menu-item
  1115. ,(purecopy "Auto Fill in Text Modes")
  1116. menu-bar-text-mode-auto-fill
  1117. :help ,(purecopy "Automatically fill text while typing (Auto Fill mode)")
  1118. :button (:toggle . (if (listp text-mode-hook)
  1119. (member 'turn-on-auto-fill text-mode-hook)
  1120. (eq 'turn-on-auto-fill text-mode-hook)))))
  1121. (define-key menu [line-wrapping]
  1122. `(menu-item ,(purecopy "Line Wrapping in This Buffer")
  1123. ,menu-bar-line-wrapping-menu))
  1124. (define-key menu [highlight-separator]
  1125. menu-bar-separator)
  1126. (define-key menu [highlight-paren-mode]
  1127. (menu-bar-make-mm-toggle
  1128. show-paren-mode
  1129. "Highlight Matching Parentheses"
  1130. "Highlight matching/mismatched parentheses at cursor (Show Paren mode)"))
  1131. (define-key menu [transient-mark-mode]
  1132. (menu-bar-make-mm-toggle
  1133. transient-mark-mode
  1134. "Highlight Active Region"
  1135. "Make text in active region stand out in color (Transient Mark mode)"
  1136. (:enable (not cua-mode))))
  1137. menu))
  1138. ;; The "Tools" menu items
  1139. (defun send-mail-item-name ()
  1140. (let* ((known-send-mail-commands '((sendmail-user-agent . "sendmail")
  1141. (mh-e-user-agent . "MH")
  1142. (message-user-agent . "Gnus Message")
  1143. (gnus-user-agent . "Gnus")))
  1144. (name (assq mail-user-agent known-send-mail-commands)))
  1145. (if name
  1146. (setq name (cdr name))
  1147. (setq name (symbol-name mail-user-agent))
  1148. (if (string-match "\\(.+\\)-user-agent" name)
  1149. (setq name (match-string 1 name))))
  1150. name))
  1151. (defun read-mail-item-name ()
  1152. (let* ((known-rmail-commands '((rmail . "RMAIL")
  1153. (mh-rmail . "MH")
  1154. (gnus . "Gnus")))
  1155. (known (assq read-mail-command known-rmail-commands)))
  1156. (if known (cdr known) (symbol-name read-mail-command))))
  1157. (defvar menu-bar-games-menu
  1158. (let ((menu (make-sparse-keymap "Games")))
  1159. (define-key menu [zone]
  1160. `(menu-item ,(purecopy "Zone Out") zone
  1161. :help ,(purecopy "Play tricks with Emacs display when Emacs is idle")))
  1162. (define-key menu [tetris]
  1163. `(menu-item ,(purecopy "Tetris") tetris
  1164. :help ,(purecopy "Falling blocks game")))
  1165. (define-key menu [solitaire]
  1166. `(menu-item ,(purecopy "Solitaire") solitaire
  1167. :help ,(purecopy "Get rid of all the stones")))
  1168. (define-key menu [snake]
  1169. `(menu-item ,(purecopy "Snake") snake
  1170. :help ,(purecopy "Move snake around avoiding collisions")))
  1171. (define-key menu [pong]
  1172. `(menu-item ,(purecopy "Pong") pong
  1173. :help ,(purecopy "Bounce the ball to your opponent")))
  1174. (define-key menu [mult]
  1175. `(menu-item ,(purecopy "Multiplication Puzzle") mpuz
  1176. :help ,(purecopy "Exercise brain with multiplication")))
  1177. (define-key menu [life]
  1178. `(menu-item ,(purecopy "Life") life
  1179. :help ,(purecopy "Watch how John Conway's cellular automaton evolves")))
  1180. (define-key menu [land]
  1181. `(menu-item ,(purecopy "Landmark") landmark
  1182. :help ,(purecopy "Watch a neural-network robot learn landmarks")))
  1183. (define-key menu [hanoi]
  1184. `(menu-item ,(purecopy "Towers of Hanoi") hanoi
  1185. :help ,(purecopy "Watch Towers-of-Hanoi puzzle solved by Emacs")))
  1186. (define-key menu [gomoku]
  1187. `(menu-item ,(purecopy "Gomoku") gomoku
  1188. :help ,(purecopy "Mark 5 contiguous squares (like tic-tac-toe)")))
  1189. (define-key menu [bubbles]
  1190. `(menu-item ,(purecopy "Bubbles") bubbles
  1191. :help ,(purecopy "Remove all bubbles using the fewest moves")))
  1192. (define-key menu [black-box]
  1193. `(menu-item ,(purecopy "Blackbox") blackbox
  1194. :help ,(purecopy "Find balls in a black box by shooting rays")))
  1195. (define-key menu [adventure]
  1196. `(menu-item ,(purecopy "Adventure") dunnet
  1197. :help ,(purecopy "Dunnet, a text Adventure game for Emacs")))
  1198. (define-key menu [5x5]
  1199. `(menu-item ,(purecopy "5x5") 5x5
  1200. :help ,(purecopy "Fill in all the squares on a 5x5 board")))
  1201. menu))
  1202. (defvar menu-bar-encryption-decryption-menu
  1203. (let ((menu (make-sparse-keymap "Encryption/Decryption")))
  1204. (define-key menu [insert-keys]
  1205. `(menu-item ,(purecopy "Insert Keys") epa-insert-keys
  1206. :help ,(purecopy "Insert public keys after the current point")))
  1207. (define-key menu [export-keys]
  1208. `(menu-item ,(purecopy "Export Keys") epa-export-keys
  1209. :help ,(purecopy "Export public keys to a file")))
  1210. (define-key menu [import-keys-region]
  1211. `(menu-item ,(purecopy "Import Keys from Region") epa-import-keys-region
  1212. :help ,(purecopy "Import public keys from the current region")))
  1213. (define-key menu [import-keys]
  1214. `(menu-item ,(purecopy "Import Keys from File...") epa-import-keys
  1215. :help ,(purecopy "Import public keys from a file")))
  1216. (define-key menu [list-keys]
  1217. `(menu-item ,(purecopy "List Keys") epa-list-keys
  1218. :help ,(purecopy "Browse your public keyring")))
  1219. (define-key menu [separator-keys]
  1220. menu-bar-separator)
  1221. (define-key menu [sign-region]
  1222. `(menu-item ,(purecopy "Sign Region") epa-sign-region
  1223. :help ,(purecopy "Create digital signature of the current region")))
  1224. (define-key menu [verify-region]
  1225. `(menu-item ,(purecopy "Verify Region") epa-verify-region
  1226. :help ,(purecopy "Verify digital signature of the current region")))
  1227. (define-key menu [encrypt-region]
  1228. `(menu-item ,(purecopy "Encrypt Region") epa-encrypt-region
  1229. :help ,(purecopy "Encrypt the current region")))
  1230. (define-key menu [decrypt-region]
  1231. `(menu-item ,(purecopy "Decrypt Region") epa-decrypt-region
  1232. :help ,(purecopy "Decrypt the current region")))
  1233. (define-key menu [separator-file]
  1234. menu-bar-separator)
  1235. (define-key menu [sign-file]
  1236. `(menu-item ,(purecopy "Sign File...") epa-sign-file
  1237. :help ,(purecopy "Create digital signature of a file")))
  1238. (define-key menu [verify-file]
  1239. `(menu-item ,(purecopy "Verify File...") epa-verify-file
  1240. :help ,(purecopy "Verify digital signature of a file")))
  1241. (define-key menu [encrypt-file]
  1242. `(menu-item ,(purecopy "Encrypt File...") epa-encrypt-file
  1243. :help ,(purecopy "Encrypt a file")))
  1244. (define-key menu [decrypt-file]
  1245. `(menu-item ,(purecopy "Decrypt File...") epa-decrypt-file
  1246. :help ,(purecopy "Decrypt a file")))
  1247. menu))
  1248. (defun menu-bar-read-mail ()
  1249. "Read mail using `read-mail-command'."
  1250. (interactive)
  1251. (call-interactively read-mail-command))
  1252. (defvar menu-bar-tools-menu
  1253. (let ((menu (make-sparse-keymap "Tools")))
  1254. (define-key menu [games]
  1255. `(menu-item ,(purecopy "Games") ,menu-bar-games-menu))
  1256. (define-key menu [separator-games]
  1257. menu-bar-separator)
  1258. (define-key menu [encryption-decryption]
  1259. `(menu-item ,(purecopy "Encryption/Decryption") ,menu-bar-encryption-decryption-menu))
  1260. (define-key menu [separator-encryption-decryption]
  1261. menu-bar-separator)
  1262. (define-key menu [simple-calculator]
  1263. `(menu-item ,(purecopy "Simple Calculator") calculator
  1264. :help ,(purecopy "Invoke the Emacs built-in quick calculator")))
  1265. (define-key menu [calc]
  1266. `(menu-item ,(purecopy "Programmable Calculator") calc
  1267. :help ,(purecopy "Invoke the Emacs built-in full scientific calculator")))
  1268. (define-key menu [calendar]
  1269. `(menu-item ,(purecopy "Calendar") calendar
  1270. :help ,(purecopy "Invoke the Emacs built-in calendar")))
  1271. (define-key menu [separator-net]
  1272. menu-bar-separator)
  1273. (define-key menu [directory-search]
  1274. `(menu-item ,(purecopy "Directory Search") eudc-tools-menu))
  1275. (define-key menu [compose-mail]
  1276. `(menu-item (format "Send Mail (with %s)" (send-mail-item-name)) compose-mail
  1277. :visible (and mail-user-agent (not (eq mail-user-agent 'ignore)))
  1278. :help ,(purecopy "Send a mail message")))
  1279. (define-key menu [rmail]
  1280. `(menu-item (format "Read Mail (with %s)" (read-mail-item-name))
  1281. menu-bar-read-mail
  1282. :visible (and read-mail-command
  1283. (not (eq read-mail-command 'ignore)))
  1284. :help ,(purecopy "Read your mail and reply to it")))
  1285. (define-key menu [gnus]
  1286. `(menu-item ,(purecopy "Read Net News (Gnus)") gnus
  1287. :help ,(purecopy "Read network news groups")))
  1288. (define-key menu [separator-vc]
  1289. menu-bar-separator)
  1290. (define-key menu [pcl-cvs]
  1291. `(menu-item ,(purecopy "PCL-CVS") cvs-global-menu))
  1292. (define-key menu [vc] nil) ;Create the place for the VC menu.
  1293. (define-key menu [separator-compare]
  1294. menu-bar-separator)
  1295. (define-key menu [epatch]
  1296. `(menu-item ,(purecopy "Apply Patch") menu-bar-epatch-menu))
  1297. (define-key menu [ediff-merge]
  1298. `(menu-item ,(purecopy "Merge") menu-bar-ediff-merge-menu))
  1299. (define-key menu [compare]
  1300. `(menu-item ,(purecopy "Compare (Ediff)") menu-bar-ediff-menu))
  1301. (define-key menu [separator-spell]
  1302. menu-bar-separator)
  1303. (define-key menu [spell]
  1304. `(menu-item ,(purecopy "Spell Checking") ispell-menu-map))
  1305. (define-key menu [separator-prog]
  1306. menu-bar-separator)
  1307. (define-key menu [semantic]
  1308. `(menu-item ,(purecopy "Source Code Parsers (Semantic)")
  1309. semantic-mode
  1310. :help ,(purecopy "Toggle automatic parsing in source code buffers (Semantic mode)")
  1311. :button (:toggle . (bound-and-true-p semantic-mode))))
  1312. (define-key menu [ede]
  1313. `(menu-item ,(purecopy "Project support (EDE)")
  1314. global-ede-mode
  1315. :help ,(purecopy "Toggle the Emacs Development Environment (Global EDE mode)")
  1316. :button (:toggle . (bound-and-true-p global-ede-mode))))
  1317. (define-key menu [gdb]
  1318. `(menu-item ,(purecopy "Debugger (GDB)...") gdb
  1319. :help ,(purecopy "Debug a program from within Emacs with GDB")))
  1320. (define-key menu [shell-on-region]
  1321. `(menu-item ,(purecopy "Shell Command on Region...") shell-command-on-region
  1322. :enable mark-active
  1323. :help ,(purecopy "Pass marked region to a shell command")))
  1324. (define-key menu [shell]
  1325. `(menu-item ,(purecopy "Shell Command...") shell-command
  1326. :help ,(purecopy "Invoke a shell command and catch its output")))
  1327. (define-key menu [compile]
  1328. `(menu-item ,(purecopy "Compile...") compile
  1329. :help ,(purecopy "Invoke compiler or Make, view compilation errors")))
  1330. (define-key menu [grep]
  1331. `(menu-item ,(purecopy "Search Files (Grep)...") grep
  1332. :help ,(purecopy "Search files for strings or regexps (with Grep)")))
  1333. menu))
  1334. ;; The "Help" menu items
  1335. (defvar menu-bar-describe-menu
  1336. (let ((menu (make-sparse-keymap "Describe")))
  1337. (define-key menu [mule-diag]
  1338. `(menu-item ,(purecopy "Show All of Mule Status") mule-diag
  1339. :visible (default-value 'enable-multibyte-characters)
  1340. :help ,(purecopy "Display multilingual environment settings")))
  1341. (define-key menu [describe-coding-system-briefly]
  1342. `(menu-item ,(purecopy "Describe Coding System (Briefly)")
  1343. describe-current-coding-system-briefly
  1344. :visible (default-value 'enable-multibyte-characters)))
  1345. (define-key menu [describe-coding-system]
  1346. `(menu-item ,(purecopy "Describe Coding System...") describe-coding-system
  1347. :visible (default-value 'enable-multibyte-characters)))
  1348. (define-key menu [describe-input-method]
  1349. `(menu-item ,(purecopy "Describe Input Method...") describe-input-method
  1350. :visible (default-value 'enable-multibyte-characters)
  1351. :help ,(purecopy "Keyboard layout for specific input method")))
  1352. (define-key menu [describe-language-environment]
  1353. `(menu-item ,(purecopy "Describe Language Environment")
  1354. ,describe-language-environment-map))
  1355. (define-key menu [separator-desc-mule]
  1356. menu-bar-separator)
  1357. (define-key menu [list-keybindings]
  1358. `(menu-item ,(purecopy "List Key Bindings") describe-bindings
  1359. :help ,(purecopy "Display all current key bindings (keyboard shortcuts)")))
  1360. (define-key menu [describe-current-display-table]
  1361. `(menu-item ,(purecopy "Describe Display Table") describe-current-display-table
  1362. :help ,(purecopy "Describe the current display table")))
  1363. (define-key menu [describe-package]
  1364. `(menu-item ,(purecopy "Describe Package...") describe-package
  1365. :help ,(purecopy "Display documentation of a Lisp package")))
  1366. (define-key menu [describe-face]
  1367. `(menu-item ,(purecopy "Describe Face...") describe-face
  1368. :help ,(purecopy "Display the properties of a face")))
  1369. (define-key menu [describe-variable]
  1370. `(menu-item ,(purecopy "Describe Variable...") describe-variable
  1371. :help ,(purecopy "Display documentation of variable/option")))
  1372. (define-key menu [describe-function]
  1373. `(menu-item ,(purecopy "Describe Function...") describe-function
  1374. :help ,(purecopy "Display documentation of function/command")))
  1375. (define-key menu [describe-key-1]
  1376. `(menu-item ,(purecopy "Describe Key or Mouse Operation...") describe-key
  1377. ;; Users typically don't identify keys and menu items...
  1378. :help ,(purecopy "Display documentation of command bound to a \
  1379. key, a click, or a menu-item")))
  1380. (define-key menu [describe-mode]
  1381. `(menu-item ,(purecopy "Describe Buffer Modes") describe-mode
  1382. :help ,(purecopy "Describe this buffer's major and minor mode")))
  1383. menu))
  1384. (defun menu-bar-read-lispref ()
  1385. "Display the Emacs Lisp Reference manual in Info mode."
  1386. (interactive)
  1387. (info "elisp"))
  1388. (defun menu-bar-read-lispintro ()
  1389. "Display the Introduction to Emacs Lisp Programming in Info mode."
  1390. (interactive)
  1391. (info "eintr"))
  1392. (defun search-emacs-glossary ()
  1393. "Display the Glossary node of the Emacs manual in Info mode."
  1394. (interactive)
  1395. (info "(emacs)Glossary"))
  1396. (defun emacs-index-search (topic)
  1397. "Look up TOPIC in the indices of the Emacs User Manual."
  1398. (interactive "sSubject to look up: ")
  1399. (info "emacs")
  1400. (Info-index topic))
  1401. (defun elisp-index-search (topic)
  1402. "Look up TOPIC in the indices of the Emacs Lisp Reference Manual."
  1403. (interactive "sSubject to look up: ")
  1404. (info "elisp")
  1405. (Info-index topic))
  1406. (defvar menu-bar-search-documentation-menu
  1407. (let ((menu (make-sparse-keymap "Search Documentation")))
  1408. (define-key menu [search-documentation-strings]
  1409. `(menu-item ,(purecopy "Search Documentation Strings...") apropos-documentation
  1410. :help
  1411. ,(purecopy "Find functions and variables whose doc strings match a regexp")))
  1412. (define-key menu [find-any-object-by-name]
  1413. `(menu-item ,(purecopy "Find Any Object by Name...") apropos
  1414. :help ,(purecopy "Find symbols of any kind whose names match a regexp")))
  1415. (define-key menu [find-option-by-value]
  1416. `(menu-item ,(purecopy "Find Options by Value...") apropos-value
  1417. :help ,(purecopy "Find variables whose values match a regexp")))
  1418. (define-key menu [find-options-by-name]
  1419. `(menu-item ,(purecopy "Find Options by Name...") apropos-variable
  1420. :help ,(purecopy "Find variables whose names match a regexp")))
  1421. (define-key menu [find-commands-by-name]
  1422. `(menu-item ,(purecopy "Find Commands by Name...") apropos-command
  1423. :help ,(purecopy "Find commands whose names match a regexp")))
  1424. (define-key menu [sep1]
  1425. menu-bar-separator)
  1426. (define-key menu [lookup-command-in-manual]
  1427. `(menu-item ,(purecopy "Look Up Command in User Manual...") Info-goto-emacs-command-node
  1428. :help ,(purecopy "Display manual section that describes a command")))
  1429. (define-key menu [lookup-key-in-manual]
  1430. `(menu-item ,(purecopy "Look Up Key in User Manual...") Info-goto-emacs-key-command-node
  1431. :help ,(purecopy "Display manual section that describes a key")))
  1432. (define-key menu [lookup-subject-in-elisp-manual]
  1433. `(menu-item ,(purecopy "Look Up Subject in ELisp Manual...") elisp-index-search
  1434. :help ,(purecopy "Find description of a subject in Emacs Lisp manual")))
  1435. (define-key menu [lookup-subject-in-emacs-manual]
  1436. `(menu-item ,(purecopy "Look Up Subject in User Manual...") emacs-index-search
  1437. :help ,(purecopy "Find description of a subject in Emacs User manual")))
  1438. (define-key menu [emacs-terminology]
  1439. `(menu-item ,(purecopy "Emacs Terminology") search-emacs-glossary
  1440. :help ,(purecopy "Display the Glossary section of the Emacs manual")))
  1441. menu))
  1442. (defvar menu-bar-manuals-menu
  1443. (let ((menu (make-sparse-keymap "More Manuals")))
  1444. (define-key menu [man]
  1445. `(menu-item ,(purecopy "Read Man Page...") manual-entry
  1446. :help ,(purecopy "Man-page docs for external commands and libraries")))
  1447. (define-key menu [sep2]
  1448. menu-bar-separator)
  1449. (define-key menu [order-emacs-manuals]
  1450. `(menu-item ,(purecopy "Ordering Manuals") view-order-manuals
  1451. :help ,(purecopy "How to order manuals from the Free Software Foundation")))
  1452. (define-key menu [lookup-subject-in-all-manuals]
  1453. `(menu-item ,(purecopy "Lookup Subject in all Manuals...") info-apropos
  1454. :help ,(purecopy "Find description of a subject in all installed manuals")))
  1455. (define-key menu [other-manuals]
  1456. `(menu-item ,(purecopy "All Other Manuals (Info)") Info-directory
  1457. :help ,(purecopy "Read any of the installed manuals")))
  1458. (define-key menu [emacs-lisp-reference]
  1459. `(menu-item ,(purecopy "Emacs Lisp Reference") menu-bar-read-lispref
  1460. :help ,(purecopy "Read the Emacs Lisp Reference manual")))
  1461. (define-key menu [emacs-lisp-intro]
  1462. `(menu-item ,(purecopy "Introduction to Emacs Lisp") menu-bar-read-lispintro
  1463. :help ,(purecopy "Read the Introduction to Emacs Lisp Programming")))
  1464. menu))
  1465. (defun menu-bar-help-extra-packages ()
  1466. "Display help about some additional packages available for Emacs."
  1467. (interactive)
  1468. (let (enable-local-variables)
  1469. (view-file (expand-file-name "MORE.STUFF"
  1470. data-directory))
  1471. (goto-address-mode 1)))
  1472. (defun help-with-tutorial-spec-language ()
  1473. "Use the Emacs tutorial, specifying which language you want."
  1474. (interactive)
  1475. (help-with-tutorial t))
  1476. (defvar menu-bar-help-menu
  1477. (let ((menu (make-sparse-keymap "Help")))
  1478. (define-key menu [about-gnu-project]
  1479. `(menu-item ,(purecopy "About GNU") describe-gnu-project
  1480. :help ,(purecopy "About the GNU System, GNU Project, and GNU/Linux")))
  1481. (define-key menu [about-emacs]
  1482. `(menu-item ,(purecopy "About Emacs") about-emacs
  1483. :help ,(purecopy "Display version number, copyright info, and basic help")))
  1484. (define-key menu [sep4]
  1485. menu-bar-separator)
  1486. (define-key menu [describe-no-warranty]
  1487. `(menu-item ,(purecopy "(Non)Warranty") describe-no-warranty
  1488. :help ,(purecopy "Explain that Emacs has NO WARRANTY")))
  1489. (define-key menu [describe-copying]
  1490. `(menu-item ,(purecopy "Copying Conditions") describe-copying
  1491. :help ,(purecopy "Show the Emacs license (GPL)")))
  1492. (define-key menu [getting-new-versions]
  1493. `(menu-item ,(purecopy "Getting New Versions") describe-distribution
  1494. :help ,(purecopy "How to get the latest version of Emacs")))
  1495. (define-key menu [sep2]
  1496. menu-bar-separator)
  1497. (define-key menu [external-packages]
  1498. `(menu-item ,(purecopy "Finding Extra Packages") menu-bar-help-extra-packages
  1499. :help ,(purecopy "Lisp packages distributed separately for use in Emacs")))
  1500. (define-key menu [find-emacs-packages]
  1501. `(menu-item ,(purecopy "Search Built-in Packages") finder-by-keyword
  1502. :help ,(purecopy "Find built-in packages and features by keyword")))
  1503. (define-key menu [more-manuals]
  1504. `(menu-item ,(purecopy "More Manuals") ,menu-bar-manuals-menu))
  1505. (define-key menu [emacs-manual]
  1506. `(menu-item ,(purecopy "Read the Emacs Manual") info-emacs-manual
  1507. :help ,(purecopy "Full documentation of Emacs features")))
  1508. (define-key menu [describe]
  1509. `(menu-item ,(purecopy "Describe") ,menu-bar-describe-menu))
  1510. (define-key menu [search-documentation]
  1511. `(menu-item ,(purecopy "Search Documentation") ,menu-bar-search-documentation-menu))
  1512. (define-key menu [sep1]
  1513. menu-bar-separator)
  1514. (define-key menu [emacs-psychotherapist]
  1515. `(menu-item ,(purecopy "Emacs Psychotherapist") doctor
  1516. :help ,(purecopy "Our doctor will help you feel better")))
  1517. (define-key menu [send-emacs-bug-report]
  1518. `(menu-item ,(purecopy "Send Bug Report...") report-emacs-bug
  1519. :help ,(purecopy "Send e-mail to Emacs maintainers")))
  1520. (define-key menu [emacs-known-problems]
  1521. `(menu-item ,(purecopy "Emacs Known Problems") view-emacs-problems
  1522. :help ,(purecopy "Read about known problems with Emacs")))
  1523. (define-key menu [emacs-news]
  1524. `(menu-item ,(purecopy "Emacs News") view-emacs-news
  1525. :help ,(purecopy "New features of this version")))
  1526. (define-key menu [emacs-faq]
  1527. `(menu-item ,(purecopy "Emacs FAQ") view-emacs-FAQ
  1528. :help ,(purecopy "Frequently asked (and answered) questions about Emacs")))
  1529. (define-key menu [emacs-tutorial-language-specific]
  1530. `(menu-item ,(purecopy "Emacs Tutorial (choose language)...")
  1531. help-with-tutorial-spec-language
  1532. :help ,(purecopy "Learn how to use Emacs (choose a language)")))
  1533. (define-key menu [emacs-tutorial]
  1534. `(menu-item ,(purecopy "Emacs Tutorial") help-with-tutorial
  1535. :help ,(purecopy "Learn how to use Emacs")))
  1536. ;; In OS X it's in the app menu already.
  1537. ;; FIXME? There already is an "About Emacs" (sans ...) entry in the Help menu.
  1538. (and (featurep 'ns)
  1539. (not (eq system-type 'darwin))
  1540. (define-key menu [info-panel]
  1541. `(menu-item ,(purecopy "About Emacs...") ns-do-emacs-info-panel)))
  1542. menu))
  1543. (define-key global-map [menu-bar tools]
  1544. (cons (purecopy "Tools") menu-bar-tools-menu))
  1545. (define-key global-map [menu-bar buffer]
  1546. (cons (purecopy "Buffers") global-buffers-menu-map))
  1547. (define-key global-map [menu-bar options]
  1548. (cons (purecopy "Options") menu-bar-options-menu))
  1549. (define-key global-map [menu-bar edit]
  1550. (cons (purecopy "Edit") menu-bar-edit-menu))
  1551. (define-key global-map [menu-bar file]
  1552. (cons (purecopy "File") menu-bar-file-menu))
  1553. ;; Put "Help" menu at the end, or Info at the front.
  1554. ;; If running under GNUstep, "Help" is moved and renamed "Info" (see below).
  1555. (if (and (featurep 'ns)
  1556. (not (eq system-type 'darwin)))
  1557. (define-key global-map [menu-bar help-menu]
  1558. (cons (purecopy "Info") menu-bar-help-menu))
  1559. (define-key-after global-map [menu-bar help-menu]
  1560. (cons (purecopy "Help") menu-bar-help-menu)))
  1561. (defun menu-bar-menu-frame-live-and-visible-p ()
  1562. "Return non-nil if the menu frame is alive and visible.
  1563. The menu frame is the frame for which we are updating the menu."
  1564. (let ((menu-frame (or menu-updating-frame (selected-frame))))
  1565. (and (frame-live-p menu-frame)
  1566. (frame-visible-p menu-frame))))
  1567. (defun menu-bar-non-minibuffer-window-p ()
  1568. "Return non-nil if selected window of the menu frame is not a minibuf window.
  1569. See the documentation of `menu-bar-menu-frame-live-and-visible-p'
  1570. for the definition of the menu frame."
  1571. (let ((menu-frame (or menu-updating-frame (selected-frame))))
  1572. (not (window-minibuffer-p (frame-selected-window menu-frame)))))
  1573. (defun kill-this-buffer () ; for the menu bar
  1574. "Kill the current buffer.
  1575. When called in the minibuffer, get out of the minibuffer
  1576. using `abort-recursive-edit'."
  1577. (interactive)
  1578. (if (menu-bar-non-minibuffer-window-p)
  1579. (kill-buffer (current-buffer))
  1580. (abort-recursive-edit)))
  1581. (defun kill-this-buffer-enabled-p ()
  1582. "Return non-nil if the `kill-this-buffer' menu item should be enabled."
  1583. (or (not (menu-bar-non-minibuffer-window-p))
  1584. (let (found-1)
  1585. ;; Instead of looping over entire buffer list, stop once we've
  1586. ;; found two "killable" buffers (Bug#8184).
  1587. (catch 'found-2
  1588. (dolist (buffer (buffer-list))
  1589. (unless (string-match-p "^ " (buffer-name buffer))
  1590. (if (not found-1)
  1591. (setq found-1 t)
  1592. (throw 'found-2 t))))))))
  1593. (put 'dired 'menu-enable '(menu-bar-non-minibuffer-window-p))
  1594. ;; Permit deleting frame if it would leave a visible or iconified frame.
  1595. (defun delete-frame-enabled-p ()
  1596. "Return non-nil if `delete-frame' should be enabled in the menu bar."
  1597. (let ((frames (frame-list))
  1598. (count 0))
  1599. (while frames
  1600. (if (frame-visible-p (car frames))
  1601. (setq count (1+ count)))
  1602. (setq frames (cdr frames)))
  1603. (> count 1)))
  1604. (defcustom yank-menu-length 20
  1605. "Maximum length to display in the yank-menu."
  1606. :type 'integer
  1607. :group 'menu)
  1608. (defun menu-bar-update-yank-menu (string old)
  1609. (let ((front (car (cdr yank-menu)))
  1610. (menu-string (if (<= (length string) yank-menu-length)
  1611. string
  1612. (concat
  1613. (substring string 0 (/ yank-menu-length 2))
  1614. "..."
  1615. (substring string (- (/ yank-menu-length 2)))))))
  1616. ;; Don't let the menu string be all dashes
  1617. ;; because that has a special meaning in a menu.
  1618. (if (string-match "\\`-+\\'" menu-string)
  1619. (setq menu-string (concat menu-string " ")))
  1620. ;; If we're supposed to be extending an existing string, and that
  1621. ;; string really is at the front of the menu, then update it in place.
  1622. (if (and old (or (eq old (car front))
  1623. (string= old (car front))))
  1624. (progn
  1625. (setcar front string)
  1626. (setcar (cdr front) menu-string))
  1627. (setcdr yank-menu
  1628. (cons
  1629. (cons string (cons menu-string 'menu-bar-select-yank))
  1630. (cdr yank-menu)))))
  1631. (if (> (length (cdr yank-menu)) kill-ring-max)
  1632. (setcdr (nthcdr kill-ring-max yank-menu) nil)))
  1633. (put 'menu-bar-select-yank 'apropos-inhibit t)
  1634. (defun menu-bar-select-yank ()
  1635. "Insert the stretch of previously-killed text selected from menu.
  1636. The menu shows all the killed text sequences stored in `kill-ring'."
  1637. (interactive "*")
  1638. (push-mark (point))
  1639. (insert last-command-event))
  1640. ;;; Buffers Menu
  1641. (defcustom buffers-menu-max-size 10
  1642. "Maximum number of entries which may appear on the Buffers menu.
  1643. If this is 10, then only the ten most-recently-selected buffers are shown.
  1644. If this is nil, then all buffers are shown.
  1645. A large number or nil slows down menu responsiveness."
  1646. :type '(choice integer
  1647. (const :tag "All" nil))
  1648. :group 'menu)
  1649. (defcustom buffers-menu-buffer-name-length 30
  1650. "Maximum length of the buffer name on the Buffers menu.
  1651. If this is a number, then buffer names are truncated to this length.
  1652. If this is nil, then buffer names are shown in full.
  1653. A large number or nil makes the menu too wide."
  1654. :type '(choice integer
  1655. (const :tag "Full length" nil))
  1656. :group 'menu)
  1657. (defcustom buffers-menu-show-directories 'unless-uniquify
  1658. "If non-nil, show directories in the Buffers menu for buffers that have them.
  1659. The special value `unless-uniquify' means that directories will be shown
  1660. unless `uniquify-buffer-name-style' is non-nil (in which case, buffer
  1661. names should include enough of a buffer's directory to distinguish it
  1662. from other buffers).
  1663. Setting this variable directly does not take effect until next time the
  1664. Buffers menu is regenerated."
  1665. :set (lambda (symbol value)
  1666. (set symbol value)
  1667. (menu-bar-update-buffers t))
  1668. :initialize 'custom-initialize-default
  1669. :type '(choice (const :tag "Never" nil)
  1670. (const :tag "Unless uniquify is enabled" unless-uniquify)
  1671. (const :tag "Always" t))
  1672. :group 'menu)
  1673. (defcustom buffers-menu-show-status t
  1674. "If non-nil, show modified/read-only status of buffers in the Buffers menu.
  1675. Setting this variable directly does not take effect until next time the
  1676. Buffers menu is regenerated."
  1677. :set (lambda (symbol value)
  1678. (set symbol value)
  1679. (menu-bar-update-buffers t))
  1680. :initialize 'custom-initialize-default
  1681. :type 'boolean
  1682. :group 'menu)
  1683. (defvar list-buffers-directory nil
  1684. "String to display in buffer listings for buffers not visiting a file.")
  1685. (make-variable-buffer-local 'list-buffers-directory)
  1686. (defun menu-bar-select-buffer ()
  1687. (interactive)
  1688. (switch-to-buffer last-command-event))
  1689. (defun menu-bar-select-frame (frame)
  1690. (make-frame-visible frame)
  1691. (raise-frame frame)
  1692. (select-frame frame))
  1693. (defun menu-bar-update-buffers-1 (elt)
  1694. (let* ((buf (car elt))
  1695. (file
  1696. (and (if (eq buffers-menu-show-directories 'unless-uniquify)
  1697. (or (not (boundp 'uniquify-buffer-name-style))
  1698. (null uniquify-buffer-name-style))
  1699. buffers-menu-show-directories)
  1700. (or (buffer-file-name buf)
  1701. (buffer-local-value 'list-buffers-directory buf)))))
  1702. (when file
  1703. (setq file (file-name-directory file)))
  1704. (when (and file (> (length file) 20))
  1705. (setq file (concat "..." (substring file -17))))
  1706. (cons (if buffers-menu-show-status
  1707. (let ((mod (if (buffer-modified-p buf) "*" ""))
  1708. (ro (if (buffer-local-value 'buffer-read-only buf) "%" "")))
  1709. (if file
  1710. (format "%s %s%s -- %s" (cdr elt) mod ro file)
  1711. (format "%s %s%s" (cdr elt) mod ro)))
  1712. (if file
  1713. (format "%s -- %s" (cdr elt) file)
  1714. (cdr elt)))
  1715. buf)))
  1716. ;; Used to cache the menu entries for commands in the Buffers menu
  1717. (defvar menu-bar-buffers-menu-command-entries nil)
  1718. (defvar menu-bar-select-buffer-function 'switch-to-buffer
  1719. "Function to select the buffer chosen from the `Buffers' menu-bar menu.
  1720. It must accept a buffer as its only required argument.")
  1721. (defun menu-bar-update-buffers (&optional force)
  1722. ;; If user discards the Buffers item, play along.
  1723. (and (lookup-key (current-global-map) [menu-bar buffer])
  1724. (or force (frame-or-buffer-changed-p))
  1725. (let ((buffers (buffer-list))
  1726. (frames (frame-list))
  1727. buffers-menu)
  1728. ;; If requested, list only the N most recently selected buffers.
  1729. (if (and (integerp buffers-menu-max-size)
  1730. (> buffers-menu-max-size 1))
  1731. (if (> (length buffers) buffers-menu-max-size)
  1732. (setcdr (nthcdr buffers-menu-max-size buffers) nil)))
  1733. ;; Make the menu of buffers proper.
  1734. (setq buffers-menu
  1735. (let (alist)
  1736. ;; Put into each element of buffer-list
  1737. ;; the name for actual display,
  1738. ;; perhaps truncated in the middle.
  1739. (dolist (buf buffers)
  1740. (let ((name (buffer-name buf)))
  1741. (unless (eq ?\s (aref name 0))
  1742. (push (menu-bar-update-buffers-1
  1743. (cons buf
  1744. (if (and (integerp buffers-menu-buffer-name-length)
  1745. (> (length name) buffers-menu-buffer-name-length))
  1746. (concat
  1747. (substring
  1748. name 0 (/ buffers-menu-buffer-name-length 2))
  1749. "..."
  1750. (substring
  1751. name (- (/ buffers-menu-buffer-name-length 2))))
  1752. name)
  1753. ))
  1754. alist))))
  1755. ;; Now make the actual list of items.
  1756. (let ((buffers-vec (make-vector (length alist) nil))
  1757. (i (length alist)))
  1758. (dolist (pair alist)
  1759. (setq i (1- i))
  1760. (aset buffers-vec i
  1761. (nconc (list (car pair)
  1762. (cons nil nil))
  1763. `(lambda ()
  1764. (interactive)
  1765. (funcall menu-bar-select-buffer-function ,(cdr pair))))))
  1766. (list buffers-vec))))
  1767. ;; Make a Frames menu if we have more than one frame.
  1768. (when (cdr frames)
  1769. (let* ((frames-vec (make-vector (length frames) nil))
  1770. (frames-menu
  1771. (cons 'keymap
  1772. (list "Select Frame" frames-vec)))
  1773. (i 0))
  1774. (dolist (frame frames)
  1775. (aset frames-vec i
  1776. (nconc
  1777. (list
  1778. (frame-parameter frame 'name)
  1779. (cons nil nil))
  1780. `(lambda ()
  1781. (interactive) (menu-bar-select-frame ,frame))))
  1782. (setq i (1+ i)))
  1783. ;; Put it after the normal buffers
  1784. (setq buffers-menu
  1785. (nconc buffers-menu
  1786. `((frames-separator "--")
  1787. (frames menu-item "Frames" ,frames-menu))))))
  1788. ;; Add in some normal commands at the end of the menu. We use
  1789. ;; the copy cached in `menu-bar-buffers-menu-command-entries'
  1790. ;; if it's been set already. Note that we can't use constant
  1791. ;; lists for the menu-entries, because the low-level menu-code
  1792. ;; modifies them.
  1793. (unless menu-bar-buffers-menu-command-entries
  1794. (setq menu-bar-buffers-menu-command-entries
  1795. (list '(command-separator "--")
  1796. (list 'next-buffer
  1797. 'menu-item
  1798. "Next Buffer"
  1799. 'next-buffer
  1800. :help "Switch to the \"next\" buffer in a cyclic order")
  1801. (list 'previous-buffer
  1802. 'menu-item
  1803. "Previous Buffer"
  1804. 'previous-buffer
  1805. :help "Switch to the \"previous\" buffer in a cyclic order")
  1806. (list 'select-named-buffer
  1807. 'menu-item
  1808. "Select Named Buffer..."
  1809. 'switch-to-buffer
  1810. :help "Prompt for a buffer name, and select that buffer in the current window")
  1811. (list 'list-all-buffers
  1812. 'menu-item
  1813. "List All Buffers"
  1814. 'list-buffers
  1815. :help "Pop up a window listing all Emacs buffers"
  1816. ))))
  1817. (setq buffers-menu
  1818. (nconc buffers-menu menu-bar-buffers-menu-command-entries))
  1819. ;; We used to "(define-key (current-global-map) [menu-bar buffer]"
  1820. ;; but that did not do the right thing when the [menu-bar buffer]
  1821. ;; entry above had been moved (e.g. to a parent keymap).
  1822. (setcdr global-buffers-menu-map (cons "Select Buffer" buffers-menu)))))
  1823. (add-hook 'menu-bar-update-hook 'menu-bar-update-buffers)
  1824. (menu-bar-update-buffers)
  1825. ;; this version is too slow
  1826. ;;(defun format-buffers-menu-line (buffer)
  1827. ;; "Returns a string to represent the given buffer in the Buffer menu.
  1828. ;;nil means the buffer shouldn't be listed. You can redefine this."
  1829. ;; (if (string-match "\\` " (buffer-name buffer))
  1830. ;; nil
  1831. ;; (with-current-buffer buffer
  1832. ;; (let ((size (buffer-size)))
  1833. ;; (format "%s%s %-19s %6s %-15s %s"
  1834. ;; (if (buffer-modified-p) "*" " ")
  1835. ;; (if buffer-read-only "%" " ")
  1836. ;; (buffer-name)
  1837. ;; size
  1838. ;; mode-name
  1839. ;; (or (buffer-file-name) ""))))))
  1840. ;;; Set up a menu bar menu for the minibuffer.
  1841. (dolist (map (list minibuffer-local-map
  1842. ;; This shouldn't be necessary, but there's a funny
  1843. ;; bug in keymap.c that I don't understand yet. -stef
  1844. minibuffer-local-completion-map))
  1845. (define-key map [menu-bar minibuf]
  1846. (cons (purecopy "Minibuf") (make-sparse-keymap "Minibuf"))))
  1847. (let ((map minibuffer-local-completion-map))
  1848. (define-key map [menu-bar minibuf ?\?]
  1849. `(menu-item ,(purecopy "List Completions") minibuffer-completion-help
  1850. :help ,(purecopy "Display all possible completions")))
  1851. (define-key map [menu-bar minibuf space]
  1852. `(menu-item ,(purecopy "Complete Word") minibuffer-complete-word
  1853. :help ,(purecopy "Complete at most one word")))
  1854. (define-key map [menu-bar minibuf tab]
  1855. `(menu-item ,(purecopy "Complete") minibuffer-complete
  1856. :help ,(purecopy "Complete as far as possible"))))
  1857. (let ((map minibuffer-local-map))
  1858. (define-key map [menu-bar minibuf quit]
  1859. `(menu-item ,(purecopy "Quit") abort-recursive-edit
  1860. :help ,(purecopy "Abort input and exit minibuffer")))
  1861. (define-key map [menu-bar minibuf return]
  1862. `(menu-item ,(purecopy "Enter") exit-minibuffer
  1863. :key-sequence ,(purecopy "\r")
  1864. :help ,(purecopy "Terminate input and exit minibuffer")))
  1865. (define-key map [menu-bar minibuf isearch-forward]
  1866. `(menu-item ,(purecopy "Isearch History Forward") isearch-forward
  1867. :help ,(purecopy "Incrementally search minibuffer history forward")))
  1868. (define-key map [menu-bar minibuf isearch-backward]
  1869. `(menu-item ,(purecopy "Isearch History Backward") isearch-backward
  1870. :help ,(purecopy "Incrementally search minibuffer history backward")))
  1871. (define-key map [menu-bar minibuf next]
  1872. `(menu-item ,(purecopy "Next History Item") next-history-element
  1873. :help ,(purecopy "Put next minibuffer history element in the minibuffer")))
  1874. (define-key map [menu-bar minibuf previous]
  1875. `(menu-item ,(purecopy "Previous History Item") previous-history-element
  1876. :help ,(purecopy "Put previous minibuffer history element in the minibuffer"))))
  1877. (define-minor-mode menu-bar-mode
  1878. "Toggle display of a menu bar on each frame (Menu Bar mode).
  1879. With a prefix argument ARG, enable Menu Bar mode if ARG is
  1880. positive, and disable it otherwise. If called from Lisp, enable
  1881. Menu Bar mode if ARG is omitted or nil.
  1882. This command applies to all frames that exist and frames to be
  1883. created in the future."
  1884. :init-value t
  1885. :global t
  1886. ;; It's defined in C/cus-start, this stops the d-m-m macro defining it again.
  1887. :variable menu-bar-mode
  1888. ;; Turn the menu-bars on all frames on or off.
  1889. (let ((val (if menu-bar-mode 1 0)))
  1890. (dolist (frame (frame-list))
  1891. (set-frame-parameter frame 'menu-bar-lines val))
  1892. ;; If the user has given `default-frame-alist' a `menu-bar-lines'
  1893. ;; parameter, replace it.
  1894. (if (assq 'menu-bar-lines default-frame-alist)
  1895. (setq default-frame-alist
  1896. (cons (cons 'menu-bar-lines val)
  1897. (assq-delete-all 'menu-bar-lines
  1898. default-frame-alist)))))
  1899. ;; Make the message appear when Emacs is idle. We can not call message
  1900. ;; directly. The minor-mode message "Menu-bar mode disabled" comes
  1901. ;; after this function returns, overwriting any message we do here.
  1902. (when (and (called-interactively-p 'interactive) (not menu-bar-mode))
  1903. (run-with-idle-timer 0 nil 'message
  1904. "Menu-bar mode disabled. Use M-x menu-bar-mode to make the menu bar appear.")))
  1905. ;;;###autoload
  1906. ;; (This does not work right unless it comes after the above definition.)
  1907. ;; This comment is taken from tool-bar.el near
  1908. ;; (put 'tool-bar-mode ...)
  1909. ;; We want to pretend the menu bar by standard is on, as this will make
  1910. ;; customize consider disabling the menu bar a customization, and save
  1911. ;; that. We could do this for real by setting :init-value above, but
  1912. ;; that would overwrite disabling the menu bar from X resources.
  1913. (put 'menu-bar-mode 'standard-value '(t))
  1914. (defun toggle-menu-bar-mode-from-frame (&optional arg)
  1915. "Toggle menu bar on or off, based on the status of the current frame.
  1916. See `menu-bar-mode' for more information."
  1917. (interactive (list (or current-prefix-arg 'toggle)))
  1918. (if (eq arg 'toggle)
  1919. (menu-bar-mode
  1920. (if (menu-bar-positive-p
  1921. (frame-parameter (menu-bar-frame-for-menubar) 'menu-bar-lines))
  1922. 0 1))
  1923. (menu-bar-mode arg)))
  1924. (declare-function x-menu-bar-open "term/x-win" (&optional frame))
  1925. (declare-function w32-menu-bar-open "term/w32-win" (&optional frame))
  1926. (defun menu-bar-open (&optional frame)
  1927. "Start key navigation of the menu bar in FRAME.
  1928. This function decides which method to use to access the menu
  1929. depending on FRAME's terminal device. On X displays, it calls
  1930. `x-menu-bar-open'; on Windows, `w32-menu-bar-open' otherwise it
  1931. calls `tmm-menubar'.
  1932. If FRAME is nil or not given, use the selected frame."
  1933. (interactive)
  1934. (let ((type (framep (or frame (selected-frame)))))
  1935. (cond
  1936. ((eq type 'x) (x-menu-bar-open frame))
  1937. ((eq type 'w32) (w32-menu-bar-open frame))
  1938. (t (with-selected-frame (or frame (selected-frame))
  1939. (tmm-menubar))))))
  1940. (global-set-key [f10] 'menu-bar-open)
  1941. (provide 'menu-bar)
  1942. ;;; menu-bar.el ends here