Context Menu is Personal (GNU Emacs)

 



Define custom menu based on your preferences. Note the definition of visibility conditions (:visible keyword) and sub-menu (More). They are helpful in reducing the clutter.

(Note: There are some placeholders in the code below.)

(easy-menu-define my-menu global-map "My context menu"
  '("Context Menu"
    ["Cut"   kill-region :visible (region-active-p)]
    ;; ["Copy"  kill-ring-save t] ;; Menu copies by default for further action
    ["Paste" yank :visible (not (region-active-p))]
    ["Open    " org-open-at-point t]
    ["Calculate    " calc-grab-region t]
    ["Execute    " (lambda () (interactive)
            (shell-command-on-region (region-beginning) (region-end) "sh")) t]
    ["Search Web" (lambda () (interactive) (eww (car kill-ring))) t]
    ["Email    " yank t]
    ["Print    " ps-print-region-with-faces t]
    "--"
    ["Define    " (lambda () (interactive) (dictionary-search (car kill-ring))) t]
    ["Synonyms    " synonymous-synonyms :visible (featurep 'synonymous)]
    ["Antonyms    " synonymous-antonyms :visible (featurep 'synonymous)]
    ["Translate    " yank :visible (featurep 'synonymous)]
    "--"
    ["Map    " (lambda () (interactive) (osm-search (car kill-ring)))
     :visible (featurep 'osm)]
    ["Shop    " (lambda () (interactive) (shop--item-search (car kill-ring))) t]
    ["Weather    " (lambda () (interactive) (sunshine-forecast (car kill-ring))) t]
    ;; ["--" 'ignore :visible (featurep 'bookmark+-lit)]
    ("More"
     ["Wikipedia" my-obscure-function t]
     ["Twitter" my-obscure-function t]
     ["Youtube" my-obscure-function t]
     )))

 

Define a custom command to associate it with a right click. This command copies the region into the kill ring. The commands above use this value (car kill-ring) for execution. The function (popup-menu) takes care of drawing the menu.

(defun context-menu-command (beg end)
  (interactive "r")
  (if (region-active-p)
      (kill-ring-save beg end))
  (popup-menu my-menu))

 

Define the keybinding for the context menu. Here it is being assigned to mouse3 button.

(global-set-key [mouse-3] 'context-menu-command)

 

Calculator

Emacs calc supports simple arithmetic calculation in algebraic mode. Use calc-grab-region for adding the functionality to the context-menu.

You can also solve an equation. e.g. Select the equation (2x = 10) and invoke "Calculate" from the context menu. Now press "a S" to solve for the variable x.


 

 

 

Comments

Popular posts from this blog

GNU Emacs as a Comic Book Reader

HTML Renderer (Emacs)

Mozilla Readability in GNU Emacs