menu-bar.el 103 KB

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