From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Robert Pluim Newsgroups: gmane.emacs.devel Subject: Re: [PATCH] Implement texinfo @ref dwim Date: Tue, 05 Feb 2019 20:42:57 +0100 Message-ID: References: <83lg2utcwv.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="9498"; mail-complaints-to="usenet@blaine.gmane.org" Cc: emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Feb 05 20:58:58 2019 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gr6rv-0002MF-T6 for ged-emacs-devel@m.gmane.org; Tue, 05 Feb 2019 20:58:56 +0100 Original-Received: from localhost ([127.0.0.1]:39469 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gr6ru-0002qn-Ok for ged-emacs-devel@m.gmane.org; Tue, 05 Feb 2019 14:58:54 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:37637) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gr6cd-0006fx-0U for emacs-devel@gnu.org; Tue, 05 Feb 2019 14:43:08 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gr6cb-0007KO-1C for emacs-devel@gnu.org; Tue, 05 Feb 2019 14:43:06 -0500 Original-Received: from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c]:37445) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gr6cZ-0007Ij-5b; Tue, 05 Feb 2019 14:43:03 -0500 Original-Received: by mail-wm1-x32c.google.com with SMTP id g67so190626wmd.2; Tue, 05 Feb 2019 11:43:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:mail-followup-to:mail-copies-to :gmane-reply-to-list:date:in-reply-to:message-id:mime-version; bh=Pv8tLhiWkELc1UYgz5DU30OblHxL5x03Xq0ZSHaVTow=; b=m/wK6SweX7/ohYtAdtvQRVWgb6Y0CECTTgcqIDMrinwkrbV8nPKyQb57A2SSlTMv6T vT62vOe1yGEFL1qiOlTENR9d8613F/Ftvt0TK2h2FzM1kefmwMn6kMQyEKNfUAOSyJXa Ie6BxXcz6IKQU0HGR0RKy6ZFOrkrOY2FTeF97ipiXKsYYgFZF+RXIl6k2lKJt7Pmdf/A JYZmYGPRwBdFrtDMtPgkWMeyyj5cxm5CsrvPM+2qxFaz/STR50qWzRkDLBC882RpcYgo Hyeiu1WRj8WJnNvnSbRhVxDyg9GzY5mx8X66ZEaEw142CDz1UhhEUkInQ2VPFqKA2sfE stFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:mail-followup-to :mail-copies-to:gmane-reply-to-list:date:in-reply-to:message-id :mime-version; bh=Pv8tLhiWkELc1UYgz5DU30OblHxL5x03Xq0ZSHaVTow=; b=XOSbi/3/PcMjFontKN9cGZym/7rgU0SifDUOVu0NtQE/82QIhF8wpzWwLGa9I7RRdh d1LISv2kDmcKFJIIVd+ve+MHIoq4B4AaJN1wyz6BJ25tLjRBffEgO/RrcZ5uw16isvko dFecMv4ynlDP25ULdT2b7sOHwsDTyOHoU5LnRqOKtlzJ/0IZ509c3OLrAePYMUmze7v0 JT2SIs70UoXVRtOidAp0AIUnAG04ZzhyuEsRYHaE5BvEcmJrnQ4SZtKrYqFfds8DKsHt UFEH9PuI14wJFTIJhUwnRDy3l46ycwdo86TBn1npSvAtCUpX7cQKtkY/RY71+iJo9VBX zOsQ== X-Gm-Message-State: AHQUAuZY2AfKhxDI4w4mJzSIaQyhhW7T0tWXiISnkzPN+3xohHRuCDna UlWDDZA3JjJ33Dt1fyDLYZA1zBId X-Google-Smtp-Source: AHgI3IZvUKAZq2S1IBnMFsA+OMKwePvcJJf1KAGzeb8BlHzb8eTsgY1DkXmuf5W/oz78zw3yzRPfLA== X-Received: by 2002:a1c:67d7:: with SMTP id b206mr224160wmc.77.1549395781022; Tue, 05 Feb 2019 11:43:01 -0800 (PST) Original-Received: from rpluim-mac ([2a01:e34:ecfc:a860:1dc2:6257:c250:f8ca]) by smtp.gmail.com with ESMTPSA id s66sm12388517wmf.34.2019.02.05.11.42.59 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 05 Feb 2019 11:42:59 -0800 (PST) Mail-Followup-To: emacs-devel@gnu.org Mail-Copies-To: never Gmane-Reply-To-List: yes In-Reply-To: <83lg2utcwv.fsf@gnu.org> (Eli Zaretskii's message of "Tue, 05 Feb 2019 18:31:28 +0200") X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::32c X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:233009 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Eli Zaretskii writes: >> From: Robert Pluim >> Date: Tue, 05 Feb 2019 13:10:07 +0100 >>=20 >> This has been sitting around in my patch queue for a while, and I=CA=BCd >> like to get it in so I can also get the manual update into the texinfo >> project. I think I=CA=BCve addressed all the comments from the last time >> around. > > Thanks, I think this command will be useful. > >> * etc/NEWS: Describe new texinfo dwim reference functionality. > > I understand that the corresponding update to the Texinfo manual will > be submitted to the Texinfo maintainers? If so, the NEWS entry should > be marked with "+++", I think. > Yes and yes. >> +(define-skeleton texinfo-insert-dwim-@ref >> + "Insert appropriate `@pxref{...}', `@xref{}', or `@ref{}' command. > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > Is Emacs smart enough not to highlight these as links? > You mean in (describe-function 'texinfo-insert-dwim-@ref)? They show up unadorned. >> + ;; parenthesis >> + ((eq (char-before) ?\() >> + "@pxref{") > > @pxref is also good inside parentheses, not just after the opening > paren. Can this command be smarter and support also cases like > > (bla-bla yak-yak @pxref{foo}) > > ? Yes, that=CA=BCs possible. I=CA=BCve limited the opening parenthesis to bei= ng on the same or previous line though (I don=CA=BCt want excessive backwards matching). >> + ;; beginning of sentence >> + ((looking-back (sentence-end) (point-at-bol 0)) >> + "@xref{") > > What about BOB? Can we produce @xref there as well? Yes. Revised version attached. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-Add-dwim-function-for-inserting-ref-variants.patch >From d38394e5d54fe1c7997634bb2ebd966a36a52f82 Mon Sep 17 00:00:00 2001 From: Robert Pluim Date: Tue, 5 Feb 2019 20:38:39 +0100 Subject: [PATCH] Add dwim function for inserting @ref variants To: emacs-devel@gnu.org * lisp/textmodes/texinfo.el (texinfo-insert-dwim-@ref): New function. Insert @ref variant based on surrounding context. (texinfo-mode-map): Add binding for texinfo-insert-dwim-@ref. * etc/NEWS: Describe new texinfo dwim reference functionality. --- etc/NEWS | 9 +++++++++ lisp/textmodes/texinfo.el | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/etc/NEWS b/etc/NEWS index 9bbe6befcf..5c06edd00a 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -472,6 +472,15 @@ To enable it, set the new defcustom 'diff-font-lock-prettify' to t. of the file under version control if point is on an old changed line, or to the new revision of the file otherwise. +** Texinfo + ++++ +*** New function for inserting @pxref, @xref, or @ref commands. +The function 'texinfo-insert-dwim-@ref', bound to 'C-c C-c r' by +default, inserts one of three types of references based on the text +surrounding point, namely @pxref near a parenthesis, @xref at the +start of a sentence or at (point-min), else @ref. + ** Browse-url *** The function 'browse-url-emacs' can now visit a URL in selected window. diff --git a/lisp/textmodes/texinfo.el b/lisp/textmodes/texinfo.el index 1a900122f9..71cdcab57e 100644 --- a/lisp/textmodes/texinfo.el +++ b/lisp/textmodes/texinfo.el @@ -470,6 +470,7 @@ texinfo-mode-map (define-key map "\C-c\C-cu" 'texinfo-insert-@uref) (define-key map "\C-c\C-ct" 'texinfo-insert-@table) (define-key map "\C-c\C-cs" 'texinfo-insert-@samp) + (define-key map "\C-c\C-cr" 'texinfo-insert-dwim-@ref) (define-key map "\C-c\C-cq" 'texinfo-insert-@quotation) (define-key map "\C-c\C-co" 'texinfo-insert-@noindent) (define-key map "\C-c\C-cn" 'texinfo-insert-@node) @@ -825,6 +826,38 @@ texinfo-insert-@quotation "Insert the string `@quotation' in a Texinfo buffer." \n "@quotation" \n _ \n) +(define-skeleton texinfo-insert-dwim-@ref + "Insert appropriate `@pxref{...}', `@xref{}', or `@ref{}' command. + +Looks at text around point to decide what to insert; an unclosed +preceding open parenthesis results in '@pxref{}', point at the +beginning of a sentence or at (point-min) yields '@xref{}', any +other location (including inside a word), will result in '@ref{}' +at the nearest previous whitespace or beginning-of-line. A +numeric argument says how many words the braces should surround. +The default is not to surround any existing words with the +braces." + nil + (cond + ;; parenthesis + ((looking-back "([^)]*" (point-at-bol 0)) + "@pxref{") + ;; beginning of sentence or buffer + ((or (looking-back (sentence-end) (point-at-bol 0)) + (= (point) (point-min))) + "@xref{") + ;; bol or eol + ((looking-at "^\\|$") + "@ref{") + ;; inside word + ((not (eq (char-syntax (char-after)) ? )) + (skip-syntax-backward "^ " (point-at-bol)) + "@ref{") + ;; everything else + (t + "@ref{")) + _ "}") + (define-skeleton texinfo-insert-@samp "Insert a `@samp{...}' command in a Texinfo buffer. A numeric argument says how many words the braces should surround. -- 2.20.1.142.g77556354bb --=-=-=--