context-menu.el 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. ;; The method of displaying buffers and frames has been borrowed from `menu-bar.el`
  2. (global-set-key [mouse-3] 'lawlist-popup-context-menu)
  3. (defvar lawlist-context-menu-map
  4. (let ((map (make-sparse-keymap "Context Menu")))
  5. map) "Keymap for the LAWLIST context menu.")
  6. (defun lawlist-popup-context-menu (event &optional prefix)
  7. "Popup a context menu."
  8. (interactive "@e \nP")
  9. (define-key lawlist-context-menu-map [buffers-menu]
  10. `(menu-item nil ,(lawlist-buffer-frame-menu t)))
  11. (popup-menu lawlist-context-menu-map event prefix))
  12. (setq buffers-menu-max-size 20) ;; default is 10
  13. (defun lawlist-buffer-frame-menu (&optional force)
  14. (let (
  15. (buffers (buffer-list))
  16. (frames (frame-list))
  17. lawlist-buffers-menu)
  18. (if (and (integerp buffers-menu-max-size)
  19. (> buffers-menu-max-size 1))
  20. (if (> (length buffers) buffers-menu-max-size)
  21. (setcdr (nthcdr buffers-menu-max-size buffers) nil)))
  22. (setq lawlist-buffers-menu
  23. (let (alist)
  24. (dolist (buf buffers)
  25. (let ((name (buffer-name buf)))
  26. ;; To show the hidden buffers, comment out:
  27. ;; (unless (eq ?\s (aref name 0))
  28. ;; along with the appropriate closing quote.
  29. (unless (eq ?\s (aref name 0))
  30. (push (menu-bar-update-buffers-1 (cons buf
  31. (if (and (integerp buffers-menu-buffer-name-length)
  32. (> (length name) buffers-menu-buffer-name-length))
  33. (concat
  34. (substring name 0 (/ buffers-menu-buffer-name-length 2))
  35. "..."
  36. (substring name (- (/ buffers-menu-buffer-name-length 2))))
  37. name) ))
  38. alist))))
  39. (let ((buffers-vec (make-vector (length alist) nil)) (i (length alist)))
  40. (dolist (pair alist)
  41. (setq i (1- i))
  42. (aset buffers-vec i
  43. (nconc (list (car pair)
  44. (cons nil nil))
  45. `(lambda () (interactive)
  46. (funcall menu-bar-select-buffer-function ,(cdr pair))))))
  47. (setq lawlist-buffers-menu
  48. (nconc lawlist-buffers-menu `(
  49. (clipboard-kill-ring-save menu-item "Copy"
  50. ,(cons "Copy" 'clipboard-kill-ring-save))
  51. (clipboard-kill-region menu-item "Cut"
  52. ,(cons "Cut" 'clipboard-kill-region))
  53. (clipboard-yank menu-item "Paste"
  54. ,(cons "Paste" 'clipboard-yank))
  55. (undo-tree-visualize menu-item "Undo tree"
  56. ,(cons "Undo tree" 'undo-tree-visualize))
  57. (lawlist-buffers menu-item "Buffers" ,(cons 'keymap (list "Select Buffers" buffers-vec)))))))))
  58. (when (cdr frames)
  59. (let* (
  60. (frames-vec (make-vector (length frames) nil))
  61. (frames-menu (cons 'keymap (list "Select Frame" frames-vec)))
  62. (i 0) )
  63. (dolist (frame frames)
  64. (aset frames-vec i
  65. (nconc
  66. (list (frame-parameter frame 'name) (cons nil nil))
  67. `(lambda () (interactive)
  68. (menu-bar-select-frame ,frame))))
  69. (setq i (1+ i)))
  70. (setq lawlist-buffers-menu
  71. (nconc lawlist-buffers-menu `(
  72. (frames-separator "--")
  73. (frames menu-item "Frames" ,frames-menu))))))
  74. (setq lawlist-context-menu-entries `(
  75. (first-separator "--")
  76. (major-mode-menu menu-item (symbol-name major-mode)
  77. ,(mouse-menu-major-mode-map))
  78. (second-separator "--")
  79. (yas-mode-menu menu-item (concat "YAS " (symbol-name major-mode))
  80. ,(gethash major-mode yas--menu-table))
  81. (third-separator "--")
  82. (dired-insert-file menu-item "Insert File"
  83. ,(cons "Insert File" 'dired-insert-file))
  84. (copy-buffer-file-name-as-kill menu-item "Copy Filename / Path"
  85. ,(cons "Copy Filename / Path" 'copy-buffer-file-name-as-kill))
  86. (rename-file-and-buffer menu-item "Rename File"
  87. ,(cons "Rename File" 'rename-file-and-buffer))
  88. (fourth-separator "--")
  89. (first-folder-heading menu-item "Multiple Cursors"
  90. ,(cons 'keymap (list
  91. (list
  92. 'mc/cycle-backward
  93. 'menu-item
  94. "mc/cycle-backward"
  95. 'mc/cycle-backward
  96. :help " ")
  97. (list
  98. 'mc/cycle-forward
  99. 'menu-item
  100. "mc/cycle-forward"
  101. 'mc/cycle-forward
  102. :help " ")
  103. (list
  104. 'mc/mark-all-like-this
  105. 'menu-item
  106. "mc/mark-all-like-this"
  107. 'mc/mark-all-like-this
  108. :help " ")
  109. (list
  110. 'mark-previous-like-this-cycle-forward
  111. 'menu-item
  112. "mark-previous-like-this-cycle-forward"
  113. 'mark-previous-like-this-cycle-forward
  114. :help " ")
  115. (list
  116. 'mark-next-like-this-cycle-forward
  117. 'menu-item
  118. "mark-next-like-this-cycle-forward"
  119. 'mark-next-like-this-cycle-forward
  120. :help " ")
  121. (list
  122. 'mc/edit-beginnings-of-lines
  123. 'menu-item
  124. "mc/edit-beginnings-of-lines"
  125. 'mc/edit-beginnings-of-lines
  126. :help " ")
  127. (list
  128. 'mc/edit-ends-of-lines
  129. 'menu-item
  130. "mc/edit-ends-of-lines"
  131. 'mc/edit-ends-of-lines
  132. :help " ") )))
  133. (third-separator "--")
  134. (second-folder-heading menu-item "B.B.D.B."
  135. ,(cons 'keymap (list
  136. (list
  137. 'bbdb-info
  138. 'menu-item
  139. "info see bbdb.texinfo"
  140. 'bbdb-info
  141. :help " ")
  142. (list
  143. 'bbdb-help
  144. 'menu-item
  145. "help"
  146. 'bbdb-help
  147. :help " ")
  148. (list
  149. 'bbdb-bury-buffer
  150. 'menu-item
  151. "bury-buffer"
  152. 'bbdb-bury-buffer
  153. :help " ")
  154. (list
  155. 'bbdb-notes
  156. 'menu-item
  157. "search notes"
  158. 'bbdb-notes
  159. :help " ")
  160. (list
  161. 'bbdb-net
  162. 'menu-item
  163. "search net"
  164. 'bbdb-net
  165. :help " ")
  166. (list
  167. 'bbdb-company
  168. 'menu-item
  169. "search company name"
  170. 'bbdb-company
  171. :help " ")
  172. (list
  173. 'bbdb-name
  174. 'menu-item
  175. "search name"
  176. 'bbdb-name
  177. :help " ")
  178. (list
  179. 'bbdb-refile-record
  180. 'menu-item
  181. "merge records"
  182. 'bbdb-refile-record
  183. :help " ")
  184. (list
  185. 'bbdb-save-db
  186. 'menu-item
  187. "save-db"
  188. 'bbdb-save-db
  189. :help " ")
  190. (list
  191. 'bbdb-send-mail
  192. 'menu-item
  193. "compose email"
  194. 'bbdb-send-mail
  195. :help " ")
  196. (list
  197. 'bbdb-omit-record
  198. 'menu-item
  199. "hide search result"
  200. 'bbdb-omit-record
  201. :help " ")
  202. (list
  203. 'bbdb-toggle-records-display-layout
  204. 'menu-item
  205. "expand / collapse"
  206. 'bbdb-toggle-records-display-layout
  207. :help " ")
  208. (list
  209. 'bbdb-next-record
  210. 'menu-item
  211. "next-record"
  212. 'bbdb-next-record
  213. :help " ")
  214. (list
  215. 'bbdb-prev-record
  216. 'menu-item
  217. "prev-record"
  218. 'bbdb-prev-record
  219. :help " ")
  220. (list
  221. 'bbdb-transpose-fields "transpose-like-fields"
  222. 'menu-item
  223. "transpose-like-fields"
  224. 'bbdb-transpose-fields
  225. :help " ")
  226. (list
  227. 'bbdb-delete-current-field-or-record
  228. 'menu-item
  229. "delete field/record"
  230. 'bbdb-delete-current-field-or-record
  231. :help " ")
  232. (list
  233. 'bbdb-record-edit-notes
  234. 'menu-item
  235. "edit-notes"
  236. 'bbdb-record-edit-notes
  237. :help " ")
  238. (list
  239. 'bbdb-insert-new-field
  240. 'menu-item
  241. "insert-new-field"
  242. 'bbdb-insert-new-field
  243. :help " ")
  244. (list
  245. 'bbdb-edit-current-field
  246. 'menu-item
  247. "edit-current-field"
  248. 'bbdb-edit-current-field
  249. :help " ")
  250. (list
  251. 'bbdb-create
  252. 'menu-item
  253. "create"
  254. 'bbdb-create
  255. :help " ")
  256. (list
  257. 'bbdb
  258. 'menu-item
  259. "search"
  260. 'bbdb
  261. :help " "))))))
  262. (setq lawlist-buffers-menu (nconc lawlist-buffers-menu lawlist-context-menu-entries))
  263. (setcdr lawlist-context-menu-map (cons "Context Menu" lawlist-buffers-menu)) ))
  264. (provide 'context-menu)