;;; menu-bar.el --- define a default menu bar
-;; Copyright (C) 1993-1995, 2000-2015 Free Software Foundation, Inc.
+;; Copyright (C) 1993-1995, 2000-2016 Free Software Foundation, Inc.
;; Author: Richard M. Stallman
;; Maintainer: emacs-devel@gnu.org
(cond
((and (eq menu-bar-last-search-type 'string)
search-ring)
- (search-forward (car search-ring)))
+ (nonincremental-search-forward))
((and (eq menu-bar-last-search-type 'regexp)
regexp-search-ring)
(re-search-forward (car regexp-search-ring)))
(cond
((and (eq menu-bar-last-search-type 'string)
search-ring)
- (search-backward (car search-ring)))
+ (nonincremental-search-backward))
((and (eq menu-bar-last-search-type 'regexp)
regexp-search-ring)
(re-search-backward (car regexp-search-ring)))
(t
(error "No previous search"))))
-(defun nonincremental-search-forward (string)
+(defun nonincremental-search-forward (&optional string backward)
"Read a string and search for it nonincrementally."
(interactive "sSearch for string: ")
(setq menu-bar-last-search-type 'string)
- (if (equal string "")
- (search-forward (car search-ring))
- (isearch-update-ring string nil)
- (search-forward string)))
-
-(defun nonincremental-search-backward (string)
+ ;; Ideally, this whole command would be equivalent to `C-s RET'.
+ (let ((isearch-forward (not backward))
+ (isearch-regexp-function search-default-mode)
+ (isearch-regexp nil))
+ (if (or (equal string "") (not string))
+ (funcall (isearch-search-fun-default) (car search-ring))
+ (isearch-update-ring string nil)
+ (funcall (isearch-search-fun-default) string))))
+
+(defun nonincremental-search-backward (&optional string)
"Read a string and search backward for it nonincrementally."
- (interactive "sSearch for string: ")
- (setq menu-bar-last-search-type 'string)
- (if (equal string "")
- (search-backward (car search-ring))
- (isearch-update-ring string nil)
- (search-backward string)))
+ (interactive "sSearch backwards for string: ")
+ (nonincremental-search-forward string 'backward))
(defun nonincremental-re-search-forward (string)
"Read a regular expression and search for it nonincrementally."
menu))
(defun menu-bar-goto-uses-etags-p ()
- (or (not (boundp 'xref-find-function))
- (eq xref-find-function 'etags-xref-find)))
+ (or (not (boundp 'xref-backend-functions))
+ (eq (car xref-backend-functions) 'etags--xref-backend)))
(defvar yank-menu (cons (purecopy "Select Yank") nil))
(fset 'yank-menu (cons 'keymap yank-menu))
(yank)))
(defun clipboard-kill-ring-save (beg end &optional region)
- "Copy region to kill ring, and save in the GUI's clipboard."
+ "Copy region to kill ring, and save in the GUI's clipboard.
+If the optional argument REGION is non-nil, the function ignores
+BEG and END, and saves the current region instead."
(interactive "r\np")
(let ((gui-select-enable-clipboard t))
(kill-ring-save beg end region)))
(defun clipboard-kill-region (beg end &optional region)
- "Kill the region, and save it in the GUI's clipboard."
+ "Kill the region, and save it in the GUI's clipboard.
+If the optional argument REGION is non-nil, the function ignores
+BEG and END, and kills the current region instead."
(interactive "r\np")
(let ((gui-select-enable-clipboard t))
(kill-region beg end region)))
;; Function for setting/saving default font.
(defun menu-set-font ()
- "Interactively select a font and make it the default on all existing frames."
+ "Interactively select a font and make it the default on all frames.
+
+The selected font will be the default on both the existing and future frames."
(interactive)
(set-frame-font (if (fboundp 'x-select-font)
(x-select-font)
;; For the radio buttons below we check whether the respective dividers
;; are displayed on the selected frame. This is not fully congruent
-;; with `window-divder-mode' but makes the menu entries work also when
+;; with `window-divider-mode' but makes the menu entries work also when
;; dividers are displayed by manipulating frame parameters directly.
(defvar menu-bar-showhide-window-divider-menu
(let ((menu (make-sparse-keymap "Window Divider")))
:enable (not (truncated-partial-width-window-p))))
menu))
+(defvar menu-bar-search-options-menu
+ (let ((menu (make-sparse-keymap "Search Options")))
+
+ (dolist (x '((char-fold-to-regexp "Fold Characters" "Character folding")
+ (isearch-symbol-regexp "Whole Symbols" "Whole symbol")
+ (word-search-regexp "Whole Words" "Whole word")))
+ (bindings--define-key menu (vector (nth 0 x))
+ `(menu-item ,(nth 1 x)
+ (lambda ()
+ (interactive)
+ (setq search-default-mode #',(nth 0 x))
+ (message ,(format "%s search enabled" (nth 2 x))))
+ :help ,(format "Enable %s search" (downcase (nth 2 x)))
+ :button (:radio . (eq search-default-mode #',(nth 0 x))))))
+
+ (bindings--define-key menu [regexp-search]
+ '(menu-item "Regular Expression"
+ (lambda ()
+ (interactive)
+ (setq search-default-mode t)
+ (message "Regular-expression search enabled"))
+ :help "Enable regular-expression search"
+ :button (:radio . (eq search-default-mode t))))
+
+ (bindings--define-key menu [regular-search]
+ '(menu-item "Literal Search"
+ (lambda ()
+ (interactive)
+ (when search-default-mode
+ (setq search-default-mode nil)
+ (when (symbolp search-default-mode)
+ (message "Literal search enabled"))))
+ :help "Disable special search modes"
+ :button (:radio . (not search-default-mode))))
+
+ (bindings--define-key menu [custom-separator]
+ menu-bar-separator)
+ (bindings--define-key menu [case-fold-search]
+ (menu-bar-make-toggle
+ toggle-case-fold-search case-fold-search
+ "Ignore Case"
+ "Case-Insensitive Search %s"
+ "Ignore letter-case in search commands"))
+
+ menu))
+
(defvar menu-bar-options-menu
(let ((menu (make-sparse-keymap "Options")))
(bindings--define-key menu [customize]
(:visible (and (boundp 'cua-enable-cua-keys)
(not cua-enable-cua-keys)))))
- (bindings--define-key menu [case-fold-search]
- (menu-bar-make-toggle
- toggle-case-fold-search case-fold-search
- "Ignore Case for Search"
- "Case-Insensitive Search %s"
- "Ignore letter-case in search commands"))
+ (bindings--define-key menu [search-options]
+ `(menu-item "Default Search Options"
+ ,menu-bar-search-options-menu))
(bindings--define-key menu [line-wrapping]
`(menu-item "Line Wrapping in This Buffer"
"Popup the given menu and call the selected option.
MENU can be a keymap, an easymenu-style menu or a list of keymaps as for
`x-popup-menu'.
-The menu is shown at the place where POSITION specifies. About
-the form of POSITION, see `popup-menu-normalize-position'.
+The menu is shown at the place where POSITION specifies.
+For the form of POSITION, see `popup-menu-normalize-position'.
PREFIX is the prefix argument (if any) to pass to the command.
FROM-MENU-BAR, if non-nil, means we are dropping one of menu-bar's menus."
(let* ((map (cond
(defun popup-menu-normalize-position (position)
"Convert the POSITION to the form which `popup-menu' expects internally.
-POSITION can an event, a posn- value, a value having
+POSITION can be an event, a posn- value, a value having the
form ((XOFFSET YOFFSET) WINDOW), or nil.
-If nil, the current mouse position is used."
+If nil, the current mouse position is used, or nil if there is no mouse."
(pcase position
;; nil -> mouse cursor position
(`nil