From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: npostavs@users.sourceforge.net Newsgroups: gmane.emacs.bugs Subject: bug#385: [PATCH] comment-indent doesn't respect comment-indent-function Date: Wed, 14 Jun 2017 00:33:06 -0400 Message-ID: <87efuntchp.fsf@users.sourceforge.net> References: <20080611171102.7261.qmail@byte.local> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1497414740 28299 195.159.176.226 (14 Jun 2017 04:32:20 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 14 Jun 2017 04:32:20 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2.50 (gnu/linux) Cc: "Christopher J. Madsen" , 385@debbugs.gnu.org To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Jun 14 06:32:15 2017 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dKzyY-0006pI-CF for geb-bug-gnu-emacs@m.gmane.org; Wed, 14 Jun 2017 06:32:14 +0200 Original-Received: from localhost ([::1]:46320 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dKzya-0003Aa-AA for geb-bug-gnu-emacs@m.gmane.org; Wed, 14 Jun 2017 00:32:16 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:38021) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dKzyQ-00039H-5i for bug-gnu-emacs@gnu.org; Wed, 14 Jun 2017 00:32:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dKzyN-0000Pa-0X for bug-gnu-emacs@gnu.org; Wed, 14 Jun 2017 00:32:06 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:43859) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dKzyM-0000PW-SI for bug-gnu-emacs@gnu.org; Wed, 14 Jun 2017 00:32:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1dKzyM-000888-Ga for bug-gnu-emacs@gnu.org; Wed, 14 Jun 2017 00:32:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: npostavs@users.sourceforge.net Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 14 Jun 2017 04:32:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 385 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 385-submit@debbugs.gnu.org id=B385.149741469731217 (code B ref 385); Wed, 14 Jun 2017 04:32:02 +0000 Original-Received: (at 385) by debbugs.gnu.org; 14 Jun 2017 04:31:37 +0000 Original-Received: from localhost ([127.0.0.1]:46536 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dKzxx-00087M-2j for submit@debbugs.gnu.org; Wed, 14 Jun 2017 00:31:37 -0400 Original-Received: from mail-it0-f43.google.com ([209.85.214.43]:38781) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dKzxv-000873-5Z; Wed, 14 Jun 2017 00:31:35 -0400 Original-Received: by mail-it0-f43.google.com with SMTP id l6so40953502iti.1; Tue, 13 Jun 2017 21:31:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=Q99BLSFz68Huot7NQ3KMfLGnBPBgsJo1qwbSFZQfQAw=; b=QC2fT9YUZ675rCP8O59lhfb32aKHq7vkU1abqp0s3nowKNjUQQQ4cLd5xz8QpcJgZ8 9azetNPwGtVMTDFQYru1lzDUitJeZx70Wgq5uQ6N4Uavl7lOB0XT19kjaRG9kFYNMd25 IKllHS3wlQzXpJ4Zyt8xOw9NxHieXN0nDYHLIujUWY3rcuAV6MuiSLp6OX2mX+V94+9z 7e42qrMfRKSPq8yzEB2TvUdMYx2ZoNEukZVw/Eh1qN7cXIsKqu7VjDe3smVJ8+ppGGaI KPOQjkGnLo6dPYKTKiK++8dGLa0fqNFL0WTxpOLEo62xg5JPqeOwE2JQmz1xUBctNft2 OqlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:references:date :in-reply-to:message-id:user-agent:mime-version; bh=Q99BLSFz68Huot7NQ3KMfLGnBPBgsJo1qwbSFZQfQAw=; b=qB82slgDXrbZHHOTkwzJz8iJzJzdtzD2PXdR5SQYWdM2/OCIIMCNMNhqiFwOINzxWM TVp3jJM7tJW++KmpZ46ACvrquwO2Cu5cYmuTt525okiXxiqznmoUqikVZkxoYXWreFqa 0uU3lyAKTorFverlMMBzmVX8jVgGH7NO13WPIMaebBoXIxCT0M71Trh3Skgb1npEr6a9 SGoNHmz2Xt71nRKtU7UmiifE/3VRdtMWYpWUSy9MtDkn718UnAlR5PlLmSMQ87IiStMa vKfwdWw9vW0CPho28XCwfNpve11ydy7Z6eNslF3BCBKhJtgESOpBMvB4z226rhOtYqch Ntbg== X-Gm-Message-State: AKS2vOyZ7Uf09kpI7m2czdtOtX5UAx9dHjV4na+mDVjsAR8JDFth3uJp 2uw4WRbY4buFaHvB X-Received: by 10.36.11.68 with SMTP id 65mr4247282itd.80.1497414689357; Tue, 13 Jun 2017 21:31:29 -0700 (PDT) Original-Received: from zony ([45.2.7.65]) by smtp.googlemail.com with ESMTPSA id o14sm82120itb.8.2017.06.13.21.31.27 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 13 Jun 2017 21:31:27 -0700 (PDT) In-Reply-To: (Stefan Monnier's message of "Wed, 11 Jun 2008 14:04:57 -0400") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 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.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:133573 Archived-At: --=-=-= Content-Type: text/plain tags 19740 + patch block 19740 by 385 quit Stefan Monnier writes: > If you need more control over the placement, rather than a variable > comment-indent-fixed, maybe we should just say that if > comment-indent-function returns a list of a single integer, it should be > taken as the indentation position and not second-guessed. Or it could > return a cons cell (MIN . MAX) to say "anywhere between MIN and MAX". Here's a patch. This seems to be a prerequisite to fix #19740. Regarding incompatibility of new comment-indent-functions for old Emacs, some simple advice on comment-choose-indent should easily do the trick. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=v1-0001-Allow-comment-indent-functions-to-specify-exact-i.patch Content-Description: patch >From cc9db0dbb5590ee909386078128e55c5ee24f319 Mon Sep 17 00:00:00 2001 From: Noam Postavsky Date: Wed, 14 Jun 2017 00:08:15 -0400 Subject: [PATCH v1] Allow comment-indent-functions to specify exact indentation (Bug#385) * lisp/newcomment.el (comment-choose-indent): Interpret a cons of two integers as indicating a range of acceptable indentation. (comment-indent): Don't apply `comment-inline-offset', `comment-choose-indent' already does that. (comment-indent-function): * doc/emacs/programs.texi (Options for Comments): Document new acceptable return values. * etc/NEWS: Announce it. --- doc/emacs/programs.texi | 9 ++++++--- etc/NEWS | 4 ++++ lisp/newcomment.el | 35 ++++++++++++++++++----------------- 3 files changed, 28 insertions(+), 20 deletions(-) diff --git a/doc/emacs/programs.texi b/doc/emacs/programs.texi index 222d1c2a4d..27ac0eb640 100644 --- a/doc/emacs/programs.texi +++ b/doc/emacs/programs.texi @@ -1146,9 +1146,12 @@ Options for Comments various major modes. The function is called with no arguments, but with point at the beginning of the comment, or at the end of a line if a new comment is to be inserted. It should return the column in which the -comment ought to start. For example, in Lisp mode, the indent hook -function bases its decision on how many semicolons begin an existing -comment, and on the code in the preceding lines. +comment ought to start. For example, the default hook function bases +its decision on how many comment characters begin an existing comment. + +Emacs also tries to align comments on adjacent lines. To override +this, the function may return a cons of two (possibly equal) integers +to indicate an acceptable range of indentation. @node Documentation @section Documentation Lookup diff --git a/etc/NEWS b/etc/NEWS index 7e955ad26d..2467e81fe3 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -377,6 +377,10 @@ display of raw bytes from octal to hex. ** You can now provide explicit field numbers in format specifiers. For example, '(format "%2$s %1$s" "X" "Y")' produces "Y X". ++++ +** 'comment-indent-function' values may now return a cons to specify a +range of indentation. + * Editing Changes in Emacs 26.1 diff --git a/lisp/newcomment.el b/lisp/newcomment.el index 118549f421..8772b52376 100644 --- a/lisp/newcomment.el +++ b/lisp/newcomment.el @@ -142,9 +142,10 @@ (put 'comment-end 'safe-local-variable 'stringp) ;;;###autoload (defvar comment-indent-function 'comment-indent-default "Function to compute desired indentation for a comment. -This function is called with no args with point at the beginning of -the comment's starting delimiter and should return either the desired -column indentation or nil. +This function is called with no args with point at the beginning +of the comment's starting delimiter and should return either the +desired column indentation, a range of acceptable +indentation (MIN . MAX), or nil. If nil is returned, indentation is delegated to `indent-according-to-mode'.") ;;;###autoload @@ -649,13 +650,20 @@ (defun comment-choose-indent (&optional indent) - prefer INDENT (or `comment-column' if nil). Point is expected to be at the start of the comment." (unless indent (setq indent comment-column)) - ;; Avoid moving comments past the fill-column. - (let ((max (+ (current-column) - (- (or comment-fill-column fill-column) - (save-excursion (end-of-line) (current-column))))) - (other nil) - (min (save-excursion (skip-chars-backward " \t") - (if (bolp) 0 (+ comment-inline-offset (current-column)))))) + (let ((other nil) + min max) + (pcase indent + (`(,lo . ,hi) (setq min lo) (setq max hi) + (setq indent comment-column)) + (_ ;; Avoid moving comments past the fill-column. + (setq max (+ (current-column) + (- (or comment-fill-column fill-column) + (save-excursion (end-of-line) (current-column))))) + (setq min (save-excursion + (skip-chars-backward " \t") + ;; Leave at least `comment-inline-offset' space after + ;; other nonwhite text on the line. + (if (bolp) 0 (+ comment-inline-offset (current-column))))))) ;; Fix up the range. (if (< max min) (setq max min)) ;; Don't move past the fill column. @@ -750,13 +758,6 @@ (defun comment-indent (&optional continue) ;; If the comment is at the right of code, adjust the indentation. (unless (save-excursion (skip-chars-backward " \t") (bolp)) (setq indent (comment-choose-indent indent))) - ;; Update INDENT to leave at least one space - ;; after other nonwhite text on the line. - (save-excursion - (skip-chars-backward " \t") - (unless (bolp) - (setq indent (max indent - (+ (current-column) comment-inline-offset))))) ;; If that's different from comment's current position, change it. (unless (= (current-column) indent) (delete-region (point) (progn (skip-chars-backward " \t") (point))) -- 2.11.1 --=-=-=--