From dff8978f5004561e2625b4199cefd8c262bb42cb Mon Sep 17 00:00:00 2001 From: Juri Linkov Date: Sun, 20 Oct 2019 19:30:30 +0300 Subject: [PATCH] Provide default value for tab-name/frame-name reading minibuffer * lisp/tab-bar.el (tab-bar-rename-tab, tab-bar-rename-tab-by-name): Provide default value for read-string. (tab-bar-select-tab-by-name): Alias for tab-bar-switch-to-tab. * lisp/frame.el (set-frame-name): Provide default value for read-string in interactive spec. * lisp/cus-start.el (tab-bar-position): Use choice instead of boolean. --- lisp/cus-start.el | 16 ++++++++++------ lisp/frame.el | 4 +++- lisp/tab-bar.el | 28 ++++++++++++++++++++-------- 3 files changed, 33 insertions(+), 15 deletions(-) diff --git a/lisp/cus-start.el b/lisp/cus-start.el index d1278192ef7..e4b6d8f2d62 100644 --- a/lisp/cus-start.el +++ b/lisp/cus-start.el @@ -591,12 +591,16 @@ since it could result in memory overflow and make Emacs crash." (const :tag "Text-image-horiz" :value text-image-horiz) (const :tag "System default" :value nil)) "24.1") (tool-bar-max-label-size frames integer "24.1") - (tab-bar-position tab-bar boolean "27.1" - :set (lambda (sym val) - (set-default sym val) - ;; Redraw the bars: - (tab-bar-mode -1) - (tab-bar-mode 1))) + (tab-bar-position + tab-bar (choice + (const :tag "Tab bar above tool bar" nil) + (const :tag "Tab bar below tool bar" t)) + "27.1" + :set (lambda (sym val) + (set-default sym val) + ;; Redraw the bars: + (tab-bar-mode -1) + (tab-bar-mode 1))) (auto-hscroll-mode scrolling (choice (const :tag "Don't scroll automatically" diff --git a/lisp/frame.el b/lisp/frame.el index 018c2f578e4..92fe57fbe63 100644 --- a/lisp/frame.el +++ b/lisp/frame.el @@ -1548,7 +1548,9 @@ often have their own features for raising or lowering frames." When called interactively, prompt for the name of the frame. On text terminals, the frame name is displayed on the mode line. On graphical displays, it is displayed on the frame's title bar." - (interactive "sFrame name: ") + (interactive + (list (read-string "Frame name: " nil nil + (cdr (assq 'name (frame-parameters)))))) (modify-frame-parameters (selected-frame) (list (cons 'name name)))) diff --git a/lisp/tab-bar.el b/lisp/tab-bar.el index 800b65091a0..117b8ea9d01 100644 --- a/lisp/tab-bar.el +++ b/lisp/tab-bar.el @@ -541,6 +541,8 @@ to the numeric argument. ARG counts from 1." (funcall tab-bar-tabs-function))))) (tab-bar-select-tab (1+ (tab-bar--tab-index-by-name name)))) +(defalias 'tab-bar-select-tab-by-name 'tab-bar-switch-to-tab) + (defcustom tab-bar-new-tab-to 'right "Defines where to create a new tab. @@ -669,13 +671,20 @@ TO-INDEX counts from 1." (force-mode-line-update) (message "Deleted all other tabs"))))) + (defun tab-bar-rename-tab (name &optional arg) "Rename the tab specified by its absolute position ARG. If no ARG is specified, then rename the current tab. ARG counts from 1. If NAME is the empty string, then use the automatic name function `tab-bar-tab-name-function'." - (interactive "sNew name for tab (leave blank for automatic naming): \nP") + (interactive + (let* ((tabs (funcall tab-bar-tabs-function)) + (tab-index (or current-prefix-arg (1+ (tab-bar--current-tab-index tabs)))) + (tab-name (cdr (assq 'name (nth (1- tab-index) tabs))))) + (list (read-string "New name for tab (leave blank for automatic naming): " + nil nil tab-name) + current-prefix-arg))) (let* ((tabs (funcall tab-bar-tabs-function)) (tab-index (if arg (1- (max 0 (min arg (length tabs)))) @@ -687,7 +696,7 @@ function `tab-bar-tab-name-function'." (funcall tab-bar-tab-name-function)))) (setf (cdr (assq 'name tab-to-rename)) tab-new-name (cdr (assq 'explicit-name tab-to-rename)) tab-explicit-name) - (if (tab-bar-mode) + (if tab-bar-mode (force-mode-line-update) (message "Renamed tab to '%s'" tab-new-name)))) @@ -695,12 +704,15 @@ function `tab-bar-tab-name-function'." "Rename the tab named TAB-NAME. If NEW-NAME is the empty string, then use the automatic name function `tab-bar-tab-name-function'." - (interactive (list (completing-read "Rename tab by name: " - (mapcar (lambda (tab) - (cdr (assq 'name tab))) - (funcall tab-bar-tabs-function))) - (read-from-minibuffer "New name for tab (leave blank for automatic naming): "))) - (tab-bar-rename-tab new-name (tab-bar--tab-index-by-name tab-name))) + (interactive + (let ((tab-name (completing-read "Rename tab by name: " + (mapcar (lambda (tab) + (cdr (assq 'name tab))) + (funcall tab-bar-tabs-function))))) + (list tab-name + (read-string "New name for tab (leave blank for automatic naming): " + nil nil tab-name)))) + (tab-bar-rename-tab new-name (1+ (tab-bar--tab-index-by-name tab-name)))) ;;; Short aliases -- 2.39.2