From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Jonas Bernoulli via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#75355: [PATCH 1/1] Improve comment cycling in log-edit Date: Sat, 4 Jan 2025 18:11:08 +0100 Message-ID: <20250104171108.18590-1-jonas@bernoul.li> References: <20250104162859.13378-1-jonas@bernoul.li> Reply-To: Jonas Bernoulli Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="5860"; mail-complaints-to="usenet@ciao.gmane.io" To: 75355@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Jan 04 18:12:20 2025 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1tU7hE-0001PI-89 for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 04 Jan 2025 18:12:20 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tU7gz-0005tS-C0; Sat, 04 Jan 2025 12:12:05 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tU7gx-0005t5-AW for bug-gnu-emacs@gnu.org; Sat, 04 Jan 2025 12:12:03 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tU7gx-0003Jy-2P for bug-gnu-emacs@gnu.org; Sat, 04 Jan 2025 12:12:03 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:References:In-Reply-To:Date:From:To:Subject; bh=SwvkYdFcI1UQngyXWExhTNhFB8g41918GoT4TJUxvlc=; b=pQ2tYnpwuJxIf85oVBoAyTj+bEfUoCV9+8kB1r48r/QSUuhznqBkKF4ar/Nrit8AWuPNIJ3HKmWdE522rvr3zs7wySG0KJlNiFPyLTu0yiOF1DMF5J94fUprOQi2TWbFcfIzeDcdYgUCdbypIL14Iz1TuVP8c2C5wyQVRsN33T3Px5Z4DwJStSVRS/5sDuexl7qVL6XTU5W0KggoCV4I83SRRxK8/D9gtVoHr22YIYLpweERNsDXhfnLbzljdTjumhQX+Y7eWt3Oi6jDFmGhATqdHQRGzSO3fTRzu0n/M8udGbub0kP0GGEfxqQQgaBJwlG3uipxZ5tubWywigH+Xg==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tU7gw-0002fB-Q4 for bug-gnu-emacs@gnu.org; Sat, 04 Jan 2025 12:12:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Jonas Bernoulli Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 04 Jan 2025 17:12:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 75355 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 75355-submit@debbugs.gnu.org id=B75355.173601067810187 (code B ref 75355); Sat, 04 Jan 2025 17:12:02 +0000 Original-Received: (at 75355) by debbugs.gnu.org; 4 Jan 2025 17:11:18 +0000 Original-Received: from localhost ([127.0.0.1]:57018 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tU7gD-0002eF-MU for submit@debbugs.gnu.org; Sat, 04 Jan 2025 12:11:18 -0500 Original-Received: from mail.hostpark.net ([212.243.197.30]:37824) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1tU7gB-0002dx-6V for 75355@debbugs.gnu.org; Sat, 04 Jan 2025 12:11:16 -0500 Original-Received: from localhost (localhost [127.0.0.1]) by mail.hostpark.net (Postfix) with ESMTP id 9A7E316609; Sat, 4 Jan 2025 18:11:12 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=bernoul.li; h= content-transfer-encoding:mime-version:references:in-reply-to :x-mailer:message-id:date:date:subject:subject:from:from; s= sel2011a; t=1736010672; bh=RNVO10dRtzWblyR4a/7foQok8J5PPrhjZFd/c 0qGAYw=; b=JbgGP4VMCGMh7sywaizCW/fROyJQhZzm3IYNn+OrFWWYHEi4Bjq6N AwmdF3ROdRNVswvw7G07et2c0Mwj80skGArhiEzZT4Xgmb0WHxa5ossrsQWHWOiw rgTzngIBy5Mq3vxfbVTAeHvnvcd1A3TthtryKxJmDsRt02BbmhbH44= X-Virus-Scanned: by Hostpark/NetZone Mailprotection at hostpark.net Original-Received: from mail.hostpark.net ([127.0.0.1]) by localhost (mail1.hostpark.net [127.0.0.1]) (amavisd-new, port 10224) with ESMTP id KWt0AlL1fQgZ; Sat, 4 Jan 2025 18:11:12 +0100 (CET) Original-Received: from customer (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mail.hostpark.net (Postfix) with ESMTPSA id 093F616275; Sat, 4 Jan 2025 18:11:11 +0100 (CET) X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250104162859.13378-1-jonas@bernoul.li> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:298433 Archived-At: Save the current message before cycling to older messages, making it possible to cycle back to that initial message. * lisp/vc/log-edit.el (log-edit-buffer-comment): New function. (log-edit-save-comment): New command, using new function. (log-edit-mode-map, log-edit-menu): Bind new command. (log-edit-previous-comment): Use new function. Port log-edit-comment-ring improvements from git-commit.el --- lisp/vc/log-edit.el | 62 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 59 insertions(+), 3 deletions(-) diff --git a/lisp/vc/log-edit.el b/lisp/vc/log-edit.el index e23e7414a18..79ea89bc728 100644 --- a/lisp/vc/log-edit.el +++ b/lisp/vc/log-edit.el @@ -61,6 +61,7 @@ log-edit-mode-map "C-c C-d" #'log-edit-show-diff "C-c C-f" #'log-edit-show-files "C-c C-k" #'log-edit-kill-buffer + "C-c C-s" #'log-edit-save-comment "M-n" #'log-edit-next-comment "M-p" #'log-edit-previous-comment "M-r" #'log-edit-comment-search-backward @@ -86,6 +87,8 @@ log-edit-menu ["List files" log-edit-show-files :help "Show the list of relevant files."] "--" + ["Save comment" log-edit-save-comment + :help "Save the current comment to comment history"] ["Previous comment" log-edit-previous-comment :help "Cycle backwards through comment history"] ["Next comment" log-edit-next-comment @@ -280,15 +283,68 @@ log-edit-new-comment-index (t stride)) len)) +(defun log-edit-buffer-comment () + "Return the comment in the current buffer. +Remove lines after the scissors line (\"------- >8 ------\") and +commented lines from the returned string. Also remove leading and +trailing whitespace. If the comment consists solely of whitespace, +return nil." + (let ((flush (concat "^" comment-start)) + (str (buffer-substring-no-properties (point-min) (point-max)))) + (with-temp-buffer + (insert str) + (goto-char (point-min)) + (when (re-search-forward (concat flush " -+ >8 -+$") nil t) + (delete-region (line-beginning-position) (point-max))) + (goto-char (point-min)) + (flush-lines flush) + (goto-char (point-max)) + (unless (eq (char-before) ?\n) + (insert ?\n)) + (setq str (buffer-string))) + (and (not (string-match "\\`[ \t\n\r]*\\'" str)) + (progn + (when (string-match "\\`\n\\{2,\\}" str) + (setq str (replace-match "\n" t t str))) + (when (string-match "\n\\{2,\\}\\'" str) + (setq str (replace-match "\n" t t str))) + str)))) + +(defun log-edit-save-comment () + "Save current comment to `log-edit-comment-ring'." + (interactive) + (if-let* ((comment (log-edit-buffer-comment))) + (progn + (when-let* ((index (ring-member log-edit-comment-ring comment))) + (ring-remove log-edit-comment-ring index)) + (ring-insert log-edit-comment-ring comment) + ;; This hook can be used, e.g., to store this in an alternative, + ;; repository-local ring. + (run-hooks 'log-edit-save-comment-hook) + (message "Comment saved")) + (message "Only whitespace and/or comments; message not saved"))) + (defun log-edit-previous-comment (arg) "Cycle backwards through VC commit comment history. With a numeric prefix ARG, go back ARG comments." (interactive "*p") (let ((len (ring-length log-edit-comment-ring))) (if (<= len 0) - (progn (message "Empty comment ring") (ding)) - ;; Don't use `erase-buffer' because we don't want to `widen'. - (delete-region (point-min) (point-max)) + (progn (message "Empty comment ring") (ding)) + (when-let* ((comment (log-edit-buffer-comment)) + ((not (ring-member log-edit-comment-ring comment)))) + (ring-insert log-edit-comment-ring comment) + (cl-incf arg) + (setq len (ring-length log-edit-comment-ring))) + ;; Delete the message but not the instructions at the end. + (save-restriction + (goto-char (point-min)) + (narrow-to-region + (point) + (if (re-search-forward (concat "^" comment-start) nil t) + (max 1 (- (point) 2)) + (point-max))) + (delete-region (point-min) (point))) (setq log-edit-comment-ring-index (log-edit-new-comment-index arg len)) (message "Comment %d" (1+ log-edit-comment-ring-index)) (insert (ring-ref log-edit-comment-ring log-edit-comment-ring-index))))) -- 2.47.1