commit 679c0c7b940687a63937a361d0439c68b7bf4d51 (HEAD, refs/remotes/origin/master) Author: Sean Whitton Date: Wed Oct 30 09:34:12 2024 +0800 ; Revise improvements to vc-git-stash-read * lisp/vc/vc-git.el (vc-git-stash-read): Use a keyword argument. Abbreviate the prompt reference to the most recent stash. (vc-git-stash-pop): Update call to vc-git-stash-read. diff --git a/lisp/vc/vc-git.el b/lisp/vc/vc-git.el index 5757b22b767..c3a9fb0f99a 100644 --- a/lisp/vc/vc-git.el +++ b/lisp/vc/vc-git.el @@ -2206,7 +2206,7 @@ In other modes, call `vc-deduce-fileset' to determine files to stash." (defvar vc-git-stash-read-history nil "History for `vc-git-stash-read'.") -(defun vc-git-stash-read (prompt &optional default-most-recent) +(cl-defun vc-git-stash-read (prompt &key default-most-recent) "Prompt the user, with PROMPT, to select a git stash. PROMPT is passed to `format-prompt'. If DEFAULT-MOST-RECENT is non-nil, then the most recently pushed stash is the default selection." @@ -2215,7 +2215,9 @@ then the most recently pushed stash is the default selection." "stash" "list") "\n" t))) (let* ((default (and default-most-recent (car stashes))) - (prompt (format-prompt prompt default)) + (prompt (format-prompt prompt + (and default-most-recent + "most recent, stash@{0}"))) (stash (completing-read prompt stashes nil :require-match nil 'vc-git-stash-read-history @@ -2247,7 +2249,8 @@ then the most recently pushed stash is the default selection." "Pop stash NAME." ;; Stashes are commonly popped off in reverse order, so pass non-nil ;; DEFAULT-MOST-RECENT to `vc-git-stash-read'. - (interactive (list (vc-git-stash-read "Pop stash" t))) + (interactive (list (vc-git-stash-read "Pop stash" + :default-most-recent t))) (vc-git-command "*vc-git-stash*" 0 nil "stash" "pop" "-q" name) (vc-resynch-buffer (vc-git-root default-directory) t t)) commit 6a2e49e53f1072bf1b41e113531627024d8b9845 Author: Sean Whitton Date: Tue Oct 29 20:54:59 2024 +0800 ; * lisp/vc/vc-git.el (vc-git-stash-read): Use string-empty-p. diff --git a/lisp/vc/vc-git.el b/lisp/vc/vc-git.el index 07be6c3189a..5757b22b767 100644 --- a/lisp/vc/vc-git.el +++ b/lisp/vc/vc-git.el @@ -2220,7 +2220,7 @@ then the most recently pushed stash is the default selection." nil :require-match nil 'vc-git-stash-read-history default))) - (if (string-equal stash "") + (if (string-empty-p stash) (user-error "Not a stash") (string-match "^stash@{[[:digit:]]+}" stash) (match-string 0 stash))) commit 4024c5db892b910ee66167479596131c8d64841f Author: Sean Whitton Date: Tue Oct 29 20:32:14 2024 +0800 ; * lisp/vc/vc-git.el (vc-deduce-fileset): Declare. diff --git a/lisp/vc/vc-git.el b/lisp/vc/vc-git.el index d7fc833a2ec..07be6c3189a 100644 --- a/lisp/vc/vc-git.el +++ b/lisp/vc/vc-git.el @@ -2177,6 +2177,10 @@ This command shares argument histories with \\[rgrep] and \\[grep]." (if (eq next-error-last-buffer (current-buffer)) (setq default-directory dir)))))) +(declare-function vc-deduce-fileset "vc" + (&optional observer allow-unregistered + state-model-only-files)) + (autoload 'vc-dir-marked-files "vc-dir") (defun vc-git--deduce-files-for-stash () commit 90ffe8a36b16801eaf0ca9b0ffca07156cf3c26d Author: Sean Whitton Date: Tue Oct 29 19:55:08 2024 +0800 Improve prompting for git stashes * lisp/vc/vc-git.el (vc-git-stash-read): New DEFAULT-MOST-RECENT optional argument. Use format-prompt. Signal user-error immediately if there are no stashes. Rewrite docstring. (vc-git-stash-show, vc-git-stash-apply, vc-git-stash-pop) (vc-git-stash-delete): Drop trailing ": " from prompts. (vc-git-stash-pop): Pass non-nil DEFAULT-MOST-RECENT to vc-git-stash-read. diff --git a/lisp/vc/vc-git.el b/lisp/vc/vc-git.el index b751ead3f1d..d7fc833a2ec 100644 --- a/lisp/vc/vc-git.el +++ b/lisp/vc/vc-git.el @@ -2202,21 +2202,29 @@ In other modes, call `vc-deduce-fileset' to determine files to stash." (defvar vc-git-stash-read-history nil "History for `vc-git-stash-read'.") -(defun vc-git-stash-read (prompt) - "Read a Git stash. PROMPT is a string to prompt with." - (let ((stash (completing-read - prompt - (split-string - (or (vc-git--run-command-string nil "stash" "list") "") "\n" t) - nil :require-match nil 'vc-git-stash-read-history))) - (if (string-equal stash "") - (user-error "Not a stash") - (string-match "^stash@{[[:digit:]]+}" stash) - (match-string 0 stash)))) +(defun vc-git-stash-read (prompt &optional default-most-recent) + "Prompt the user, with PROMPT, to select a git stash. +PROMPT is passed to `format-prompt'. If DEFAULT-MOST-RECENT is non-nil, +then the most recently pushed stash is the default selection." + (if-let* ((stashes + (split-string (vc-git--run-command-string nil + "stash" "list") + "\n" t))) + (let* ((default (and default-most-recent (car stashes))) + (prompt (format-prompt prompt default)) + (stash (completing-read prompt stashes + nil :require-match nil + 'vc-git-stash-read-history + default))) + (if (string-equal stash "") + (user-error "Not a stash") + (string-match "^stash@{[[:digit:]]+}" stash) + (match-string 0 stash))) + (user-error "No stashes"))) (defun vc-git-stash-show (name) "Show the contents of stash NAME." - (interactive (list (vc-git-stash-read "Show stash: "))) + (interactive (list (vc-git-stash-read "Show stash"))) (vc-setup-buffer "*vc-git-stash*") (vc-git-command "*vc-git-stash*" 'async nil "stash" "show" "--color=never" "-p" name) @@ -2227,19 +2235,21 @@ In other modes, call `vc-deduce-fileset' to determine files to stash." (defun vc-git-stash-apply (name) "Apply stash NAME." - (interactive (list (vc-git-stash-read "Apply stash: "))) + (interactive (list (vc-git-stash-read "Apply stash"))) (vc-git-command "*vc-git-stash*" 0 nil "stash" "apply" "-q" name) (vc-resynch-buffer (vc-git-root default-directory) t t)) (defun vc-git-stash-pop (name) "Pop stash NAME." - (interactive (list (vc-git-stash-read "Pop stash: "))) + ;; Stashes are commonly popped off in reverse order, so pass non-nil + ;; DEFAULT-MOST-RECENT to `vc-git-stash-read'. + (interactive (list (vc-git-stash-read "Pop stash" t))) (vc-git-command "*vc-git-stash*" 0 nil "stash" "pop" "-q" name) (vc-resynch-buffer (vc-git-root default-directory) t t)) (defun vc-git-stash-delete (name) "Delete stash NAME." - (interactive (list (vc-git-stash-read "Delete stash: "))) + (interactive (list (vc-git-stash-read "Delete stash"))) (vc-git-command "*vc-git-stash*" 0 nil "stash" "drop" "-q" name) (vc-resynch-buffer (vc-git-root default-directory) t t)) commit 4a49c50a4c351503a94c223da05888e5fd3d4fa1 Author: Sean Whitton Date: Tue Oct 29 19:25:31 2024 +0800 VC Git: Use vc-deduce-fileset to determine what to stash * lisp/vc/vc-git.el (vc-git--deduce-files-for-stash): New function. (vc-git-stash, vc-git-stash-snapshot): Use it to determine what to stash. Update and expand docstrings. (vc-git-stash-snapshot): No longer unconditionally snapshot all uncommitted changes across the whole working tree. diff --git a/lisp/vc/vc-git.el b/lisp/vc/vc-git.el index e4969aede74..b751ead3f1d 100644 --- a/lisp/vc/vc-git.el +++ b/lisp/vc/vc-git.el @@ -2179,14 +2179,24 @@ This command shares argument histories with \\[rgrep] and \\[grep]." (autoload 'vc-dir-marked-files "vc-dir") +(defun vc-git--deduce-files-for-stash () + ;; In *vc-dir*, if nothing is marked, act on the whole working tree + ;; regardless of the position of point. This preserves historical + ;; behavior and is also probably more useful. + (if (derived-mode-p 'vc-dir-mode) + (vc-dir-marked-files) + (cadr (vc-deduce-fileset)))) + (defun vc-git-stash (name) - "Create a stash given the name NAME." + "Create a stash named NAME. +In `vc-dir-mode', if there are files marked, stash the changes to those. +If no files are marked, stash all uncommitted changes to tracked files. +In other modes, call `vc-deduce-fileset' to determine files to stash." (interactive "sStash name: ") (let ((root (vc-git-root default-directory))) (when root (apply #'vc-git--call nil "stash" "push" "-m" name - (when (derived-mode-p 'vc-dir-mode) - (vc-dir-marked-files))) + (vc-git--deduce-files-for-stash)) (vc-resynch-buffer root t t)))) (defvar vc-git-stash-read-history nil @@ -2234,10 +2244,14 @@ This command shares argument histories with \\[rgrep] and \\[grep]." (vc-resynch-buffer (vc-git-root default-directory) t t)) (defun vc-git-stash-snapshot () - "Create a stash with the current tree state." + "Create a stash with the current uncommitted changes. +In `vc-dir-mode', if there are files marked, stash the changes to those. +If no files are marked, stash all uncommitted changes to tracked files. +In other modes, call `vc-deduce-fileset' to determine files to stash." (interactive) - (vc-git--call nil "stash" "save" - (format-time-string "Snapshot on %Y-%m-%d at %H:%M")) + (apply #'vc-git--call nil "stash" "push" "-m" + (format-time-string "Snapshot on %Y-%m-%d at %H:%M") + (vc-git--deduce-files-for-stash)) (vc-git-command "*vc-git-stash*" 0 nil "stash" "apply" "-q" "stash@{0}") (vc-resynch-buffer (vc-git-root default-directory) t t)) commit 9aa186592634212fcdb2dbafdfd0c52a2475ba96 Author: Yuan Fu Date: Tue Oct 29 00:27:34 2024 -0700 Fix c-ts-common-comment-indent-new-line (bug#73900) * lisp/progmodes/c-ts-common.el: (c-ts-common-comment-indent-new-line): Delete trailing whitespace before inserting newline. The insert-line-break function is the same as in c-indent-new-comment-line. diff --git a/lisp/progmodes/c-ts-common.el b/lisp/progmodes/c-ts-common.el index 4fb61c4ba13..5c7909ae858 100644 --- a/lisp/progmodes/c-ts-common.el +++ b/lisp/progmodes/c-ts-common.el @@ -331,55 +331,61 @@ and /* */ comments. SOFT works the same as in ;; is a // comment, insert a newline and a // prefix; if the current ;; line is in a /* comment, insert a newline and a * prefix. No ;; auto-fill or other smart features. - (cond - ;; Line starts with //, or ///, or ////... - ;; Or //! (used in rust). - ((save-excursion - (beginning-of-line) - (re-search-forward - (rx "//" (group (* (any "/!")) (* " "))) - (line-end-position) - t nil)) - (let ((offset (- (match-beginning 0) (line-beginning-position))) - (whitespaces (match-string 1))) - (if soft (insert-and-inherit ?\n) (newline 1)) - (delete-region (line-beginning-position) (point)) - (insert (make-string offset ?\s) "//" whitespaces))) - - ;; Line starts with /* or /**. - ((save-excursion - (beginning-of-line) - (re-search-forward - (rx "/*" (group (? "*") (* " "))) - (line-end-position) - t nil)) - (let ((offset (- (match-beginning 0) (line-beginning-position))) - (whitespace-and-star-len (length (match-string 1)))) - (if soft (insert-and-inherit ?\n) (newline 1)) - (delete-region (line-beginning-position) (point)) - (insert - (make-string offset ?\s) - " *" - (make-string whitespace-and-star-len ?\s)))) - - ;; Line starts with *. - ((save-excursion - (beginning-of-line) - (looking-at (rx (group (* " ") (any "*|") (* " "))))) - (let ((prefix (match-string 1))) - (if soft (insert-and-inherit ?\n) (newline 1)) - (delete-region (line-beginning-position) (point)) - (insert prefix))) - - ;; Line starts with whitespaces or no space. This is basically the - ;; default case since (rx (* " ")) matches anything. - ((save-excursion - (beginning-of-line) - (looking-at (rx (* " ")))) - (let ((whitespaces (match-string 0))) - (if soft (insert-and-inherit ?\n) (newline 1)) - (delete-region (line-beginning-position) (point)) - (insert whitespaces))))) + (let ((insert-line-break + (lambda () + (delete-horizontal-space) + (if soft + (insert-and-inherit ?\n) + (newline (if allow-auto-fill nil 1)))))) + (cond + ;; Line starts with //, or ///, or ////... + ;; Or //! (used in rust). + ((save-excursion + (beginning-of-line) + (re-search-forward + (rx "//" (group (* (any "/!")) (* " "))) + (line-end-position) + t nil)) + (let ((offset (- (match-beginning 0) (line-beginning-position))) + (whitespaces (match-string 1))) + (funcall insert-line-break) + (delete-region (line-beginning-position) (point)) + (insert (make-string offset ?\s) "//" whitespaces))) + + ;; Line starts with /* or /**. + ((save-excursion + (beginning-of-line) + (re-search-forward + (rx "/*" (group (? "*") (* " "))) + (line-end-position) + t nil)) + (let ((offset (- (match-beginning 0) (line-beginning-position))) + (whitespace-and-star-len (length (match-string 1)))) + (funcall insert-line-break) + (delete-region (line-beginning-position) (point)) + (insert + (make-string offset ?\s) + " *" + (make-string whitespace-and-star-len ?\s)))) + + ;; Line starts with *. + ((save-excursion + (beginning-of-line) + (looking-at (rx (group (* " ") (any "*|") (* " "))))) + (let ((prefix (match-string 1))) + (funcall insert-line-break) + (delete-region (line-beginning-position) (point)) + (insert prefix))) + + ;; Line starts with whitespaces or no space. This is basically the + ;; default case since (rx (* " ")) matches anything. + ((save-excursion + (beginning-of-line) + (looking-at (rx (* " ")))) + (let ((whitespaces (match-string 0))) + (funcall insert-line-break) + (delete-region (line-beginning-position) (point)) + (insert whitespaces)))))) ;; Font locking using doxygen parser (defvar c-ts-mode-doxygen-comment-font-lock-settings