unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Re: master 388a874 2/4: Do interactive mode tagging for man.el
@ 2021-02-19 15:56 Eli Zaretskii
  2021-02-20  2:24 ` Stefan Kangas
  0 siblings, 1 reply; 12+ messages in thread
From: Eli Zaretskii @ 2021-02-19 15:56 UTC (permalink / raw)
  To: Stefan Kangas; +Cc: emacs-devel

Stefan, did you consider the fact that woman.el defines a different
mode, but uses some commands from man.el?  (I didn't try invoking the
commands you tagged, so maybe there's no problem.)



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: master 388a874 2/4: Do interactive mode tagging for man.el
  2021-02-19 15:56 master 388a874 2/4: Do interactive mode tagging for man.el Eli Zaretskii
@ 2021-02-20  2:24 ` Stefan Kangas
  2021-02-20  7:39   ` Eli Zaretskii
  2021-02-20 12:23   ` Lars Ingebrigtsen
  0 siblings, 2 replies; 12+ messages in thread
From: Stefan Kangas @ 2021-02-20  2:24 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel

Eli Zaretskii <eliz@gnu.org> writes:

> Stefan, did you consider the fact that woman.el defines a different
> mode, but uses some commands from man.el?  (I didn't try invoking the
> commands you tagged, so maybe there's no problem.)

Thanks for catching this.

Yes, completion for these commands in Woman is indeed now broken when
filtering is enabled.  Sorry about that.

The problem here is that `woman-mode' uses `man-mode' but does not
inherit that mode.  Instead, it *calls* `Man-mode' from `woman-mode',
with some extra `fset' shenanigans that I don't see a trivial fix for.
(This unusual arrangement should probably be fixed at some point...)

So if we want to keep the tagging, I see two possible workarounds:

1) Tag the man-mode commands with both `Man-mode' and `woman-mode'.

2) Introduce a new mode, `man-shared-mode', inheriting from
   special-mode, that both `Man-mode' and `woman-mode' can inherit
   from.  Then tag the commands using that.

Both options have their pros and cons.

WDYT?



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: master 388a874 2/4: Do interactive mode tagging for man.el
  2021-02-20  2:24 ` Stefan Kangas
@ 2021-02-20  7:39   ` Eli Zaretskii
  2021-02-20 12:26     ` Lars Ingebrigtsen
  2021-02-20 12:23   ` Lars Ingebrigtsen
  1 sibling, 1 reply; 12+ messages in thread
From: Eli Zaretskii @ 2021-02-20  7:39 UTC (permalink / raw)
  To: Stefan Kangas; +Cc: emacs-devel

> From: Stefan Kangas <stefan@marxist.se>
> Date: Fri, 19 Feb 2021 20:24:49 -0600
> Cc: emacs-devel@gnu.org
> 
> Eli Zaretskii <eliz@gnu.org> writes:
> 
> > Stefan, did you consider the fact that woman.el defines a different
> > mode, but uses some commands from man.el?  (I didn't try invoking the
> > commands you tagged, so maybe there's no problem.)
> 
> Thanks for catching this.

So I think the procedure for tagging should include a mandatory
grepping of all the Lisp files to see if the mode or its features are
referenced or used anywhere else.

> So if we want to keep the tagging, I see two possible workarounds:
> 
> 1) Tag the man-mode commands with both `Man-mode' and `woman-mode'.
> 
> 2) Introduce a new mode, `man-shared-mode', inheriting from
>    special-mode, that both `Man-mode' and `woman-mode' can inherit
>    from.  Then tag the commands using that.
> 
> Both options have their pros and cons.

There's a 3rd option:

 3) Put a 'completion-predicate' property on the relevant woman.el
    commands, so that command-completion-default-include-p does TRT
    with them even though the modes don't match.

I will withhold my opinion for now, and let Lars and others speak up.
This is basically the first time we bump into the issues that were
discussed here already, but sounded theoretical back then.  We now
need to fix such an issue with the tagging in practice, and we might
as well invest some thinking before we decide which way to go.
Because whatever we decide to do now, and the considerations to go
into that decision, will be most probably taken as the canonical
solution for such situations.



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: master 388a874 2/4: Do interactive mode tagging for man.el
  2021-02-20  2:24 ` Stefan Kangas
  2021-02-20  7:39   ` Eli Zaretskii
@ 2021-02-20 12:23   ` Lars Ingebrigtsen
  2021-02-21 10:37     ` Stefan Kangas
  1 sibling, 1 reply; 12+ messages in thread
From: Lars Ingebrigtsen @ 2021-02-20 12:23 UTC (permalink / raw)
  To: Stefan Kangas; +Cc: Eli Zaretskii, emacs-devel

Stefan Kangas <stefan@marxist.se> writes:

> 2) Introduce a new mode, `man-shared-mode', inheriting from
>    special-mode, that both `Man-mode' and `woman-mode' can inherit
>    from.  Then tag the commands using that.

I think that makes sense, and would have the additional effect of
documenting, right in the Man-* command functions, that these aren't
just used in man.el, which may be nice if somebody later alters the
functions.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: master 388a874 2/4: Do interactive mode tagging for man.el
  2021-02-20  7:39   ` Eli Zaretskii
@ 2021-02-20 12:26     ` Lars Ingebrigtsen
  2021-02-20 12:56       ` Eli Zaretskii
  0 siblings, 1 reply; 12+ messages in thread
From: Lars Ingebrigtsen @ 2021-02-20 12:26 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Stefan Kangas, emacs-devel

Eli Zaretskii <eliz@gnu.org> writes:

> So I think the procedure for tagging should include a mandatory
> grepping of all the Lisp files to see if the mode or its features are
> referenced or used anywhere else.

Yup.

> There's a 3rd option:
>
>  3) Put a 'completion-predicate' property on the relevant woman.el
>     commands, so that command-completion-default-include-p does TRT
>     with them even though the modes don't match.

But the problem here is that these aren't woman.el commands -- they are
man.el commands, but used by woman.el?

> Because whatever we decide to do now, and the considerations to go
> into that decision, will be most probably taken as the canonical
> solution for such situations.

Yes, it's good to bump into something like this this early in the
tagging process.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: master 388a874 2/4: Do interactive mode tagging for man.el
  2021-02-20 12:26     ` Lars Ingebrigtsen
@ 2021-02-20 12:56       ` Eli Zaretskii
  0 siblings, 0 replies; 12+ messages in thread
From: Eli Zaretskii @ 2021-02-20 12:56 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: stefan, emacs-devel

> From: Lars Ingebrigtsen <larsi@gnus.org>
> Cc: Stefan Kangas <stefan@marxist.se>,  emacs-devel@gnu.org
> Date: Sat, 20 Feb 2021 13:26:03 +0100
> 
> > There's a 3rd option:
> >
> >  3) Put a 'completion-predicate' property on the relevant woman.el
> >     commands, so that command-completion-default-include-p does TRT
> >     with them even though the modes don't match.
> 
> But the problem here is that these aren't woman.el commands -- they are
> man.el commands, but used by woman.el?

Sorry, I meant the relevant man.el commands.



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: master 388a874 2/4: Do interactive mode tagging for man.el
  2021-02-20 12:23   ` Lars Ingebrigtsen
@ 2021-02-21 10:37     ` Stefan Kangas
  2021-02-21 15:48       ` Lars Ingebrigtsen
                         ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Stefan Kangas @ 2021-02-21 10:37 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: Eli Zaretskii, emacs-devel

[-- Attachment #1: Type: text/plain, Size: 515 bytes --]

Lars Ingebrigtsen <larsi@gnus.org> writes:

> Stefan Kangas <stefan@marxist.se> writes:
>
>> 2) Introduce a new mode, `man-shared-mode', inheriting from
>>    special-mode, that both `Man-mode' and `woman-mode' can inherit
>>    from.  Then tag the commands using that.
>
> I think that makes sense, and would have the additional effect of
> documenting, right in the Man-* command functions, that these aren't
> just used in man.el, which may be nice if somebody later alters the
> functions.

OK, here's a patch.

[-- Attachment #2: 0001-Fix-interactive-mode-tagging-for-man-and-woman.patch --]
[-- Type: text/x-diff, Size: 6943 bytes --]

From 583f66871145c60797f0b148f502d6e3516aff5a Mon Sep 17 00:00:00 2001
From: Stefan Kangas <stefan@marxist.se>
Date: Sun, 21 Feb 2021 11:19:57 +0100
Subject: [PATCH] Fix interactive mode tagging for man and woman

* lisp/man.el (man-shared-mode): New mode inheriting special-mode.
(Man-mode):
* lisp/woman.el (woman-mode): Inherit from man-shared-mode.

* lisp/man.el (man-follow, Man-update-manpage)
(Man-fontify-manpage, Man-cleanup-manpage, Man-next-section)
(Man-previous-section, Man-goto-section)
(Man-goto-see-also-section, Man-follow-manual-reference)
(Man-kill, Man-goto-page, Man-next-manpage)
(Man-previous-manpage): Change interactive mode tag to
man-shared-mode.

This was discussed in:
https://lists.gnu.org/r/emacs-devel/2021-02/msg01619.html
---
 lisp/man.el   | 35 +++++++++++++++++++++--------------
 lisp/woman.el |  4 +++-
 2 files changed, 24 insertions(+), 15 deletions(-)

diff --git a/lisp/man.el b/lisp/man.el
index 70b8aa8eb2..2d8bf340b1 100644
--- a/lisp/man.el
+++ b/lisp/man.el
@@ -1024,7 +1024,7 @@ man
 ;;;###autoload
 (defun man-follow (man-args)
   "Get a Un*x manual page of the item under point and put it in a buffer."
-  (interactive (list (Man-default-man-entry)) Man-mode)
+  (interactive (list (Man-default-man-entry)) man-shared-mode)
   (if (or (not man-args)
 	  (string= man-args ""))
       (error "No item under point")
@@ -1143,7 +1143,7 @@ Man-getpage-in-background
 
 (defun Man-update-manpage ()
   "Reformat current manpage by calling the man command again synchronously."
-  (interactive nil Man-mode)
+  (interactive nil man-shared-mode)
   (when (eq Man-arguments nil)
     ;;this shouldn't happen unless it is not in a Man buffer."
     (error "Man-arguments not initialized"))
@@ -1239,7 +1239,7 @@ Man-softhyphen-to-minus
 (defun Man-fontify-manpage ()
   "Convert overstriking and underlining to the correct fonts.
 Same for the ANSI bold and normal escape sequences."
-  (interactive nil Man-mode)
+  (interactive nil man-shared-mode)
   (goto-char (point-min))
   ;; Fontify ANSI escapes.
   (let ((ansi-color-apply-face-function #'ansi-color-apply-text-property-face)
@@ -1355,7 +1355,7 @@ Man-cleanup-manpage
 Normally skip any jobs that should have been done by the sed script,
 but when called interactively, do those jobs even if the sed
 script would have done them."
-  (interactive "p" Man-mode)
+  (interactive "p" man-shared-mode)
   (if (or interactive (not Man-sed-script))
       (progn
 	(goto-char (point-min))
@@ -1527,7 +1527,14 @@ Man-page-from-arguments
 
 (defvar bookmark-make-record-function)
 
-(define-derived-mode Man-mode special-mode "Man"
+(define-derived-mode man-shared-mode special-mode "Man Shared"
+  "Parent mode for `Man-mode' like modes.
+This mode is here to be inherited by modes that need to use
+commands from `Man-mode'.  Used by `woman'.
+(In itself, this mode currently does nothing.)"
+  :interactive nil)
+
+(define-derived-mode Man-mode man-shared-mode "Man"
   "A mode for browsing Un*x manual pages.
 
 The following man commands are available in the buffer.  Try
@@ -1723,7 +1730,7 @@ Man-unindent
 
 (defun Man-next-section (n)
   "Move point to Nth next section (default 1)."
-  (interactive "p" Man-mode)
+  (interactive "p" man-shared-mode)
   (let ((case-fold-search nil)
         (start (point)))
     (if (looking-at Man-heading-regexp)
@@ -1739,7 +1746,7 @@ Man-next-section
 
 (defun Man-previous-section (n)
   "Move point to Nth previous section (default 1)."
-  (interactive "p" Man-mode)
+  (interactive "p" man-shared-mode)
   (let ((case-fold-search nil))
     (if (looking-at Man-heading-regexp)
 	(forward-line -1))
@@ -1771,7 +1778,7 @@ Man-goto-section
           (chosen (completing-read prompt Man--sections
                                    nil nil nil nil default)))
      (list chosen))
-   Man-mode)
+   man-shared-mode)
   (setq Man--last-section section)
   (unless (Man-find-section section)
     (error "Section %s not found" section)))
@@ -1780,7 +1787,7 @@ Man-goto-section
 (defun Man-goto-see-also-section ()
   "Move point to the \"SEE ALSO\" section.
 Actually the section moved to is described by `Man-see-also-regexp'."
-  (interactive nil Man-mode)
+  (interactive nil man-shared-mode)
   (if (not (Man-find-section Man-see-also-regexp))
       (error "%s" (concat "No " Man-see-also-regexp
 		     " section found in the current manpage"))))
@@ -1835,7 +1842,7 @@ Man-follow-manual-reference
 	     (chosen (completing-read prompt Man--refpages
 				      nil nil nil nil defaults)))
         chosen)))
-   Man-mode)
+   man-shared-mode)
   (if (not Man--refpages)
       (error "Can't find any references in the current manpage")
     (setq Man--last-refpage reference)
@@ -1844,7 +1851,7 @@ Man-follow-manual-reference
 
 (defun Man-kill ()
   "Kill the buffer containing the manpage."
-  (interactive nil Man-mode)
+  (interactive nil man-shared-mode)
   (quit-window t))
 
 (defun Man-goto-page (page &optional noerror)
@@ -1856,7 +1863,7 @@ Man-goto-page
 	 (error "You're looking at the only manpage in the buffer")
        (list (read-minibuffer (format "Go to manpage [1-%d]: "
                                       (length Man-page-list))))))
-    Man-mode)
+    man-shared-mode)
   (if (and (not Man-page-list) (not noerror))
       (error "Not a man page buffer"))
   (when Man-page-list
@@ -1878,7 +1885,7 @@ Man-goto-page
 
 (defun Man-next-manpage ()
   "Find the next manpage entry in the buffer."
-  (interactive nil Man-mode)
+  (interactive nil man-shared-mode)
   (if (= (length Man-page-list) 1)
       (error "This is the only manpage in the buffer"))
   (if (< Man-current-page (length Man-page-list))
@@ -1889,7 +1896,7 @@ Man-next-manpage
 
 (defun Man-previous-manpage ()
   "Find the previous manpage entry in the buffer."
-  (interactive nil Man-mode)
+  (interactive nil man-shared-mode)
   (if (= (length Man-page-list) 1)
       (error "This is the only manpage in the buffer"))
   (if (> Man-current-page 1)
diff --git a/lisp/woman.el b/lisp/woman.el
index 98f1a47d24..0cd72cb261 100644
--- a/lisp/woman.el
+++ b/lisp/woman.el
@@ -1856,13 +1856,15 @@ woman-reset-emulation
 
 (defvar bookmark-make-record-function)
 
-(define-derived-mode woman-mode special-mode "WoMan"
+(define-derived-mode woman-mode man-shared-mode "WoMan"
   "Turn on (most of) Man mode to browse a buffer formatted by WoMan.
 WoMan is an ELisp emulation of much of the functionality of the Emacs
 `man' command running the standard UN*X man and ?roff programs.
 WoMan author: F.J.Wright@Maths.QMW.ac.uk
 See `Man-mode' for additional details.
 \\{woman-mode-map}"
+  ;; FIXME: Should all this just be re-arranged so that this can just
+  ;; inherit `man-shared-mode' and be done with it?
   (let ((Man-build-page-list (symbol-function 'Man-build-page-list))
 	(Man-strip-page-headers (symbol-function 'Man-strip-page-headers))
 	(Man-unindent (symbol-function 'Man-unindent))
-- 
2.30.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: master 388a874 2/4: Do interactive mode tagging for man.el
  2021-02-21 10:37     ` Stefan Kangas
@ 2021-02-21 15:48       ` Lars Ingebrigtsen
  2021-02-21 19:18         ` Stefan Kangas
  2021-02-21 17:43       ` Eli Zaretskii
  2021-02-22 22:34       ` Lars Ingebrigtsen
  2 siblings, 1 reply; 12+ messages in thread
From: Lars Ingebrigtsen @ 2021-02-21 15:48 UTC (permalink / raw)
  To: Stefan Kangas; +Cc: Eli Zaretskii, emacs-devel

Stefan Kangas <stefan@marxist.se> writes:

>> I think that makes sense, and would have the additional effect of
>> documenting, right in the Man-* command functions, that these aren't
>> just used in man.el, which may be nice if somebody later alters the
>> functions.
>
> OK, here's a patch.

Looks good to me.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: master 388a874 2/4: Do interactive mode tagging for man.el
  2021-02-21 10:37     ` Stefan Kangas
  2021-02-21 15:48       ` Lars Ingebrigtsen
@ 2021-02-21 17:43       ` Eli Zaretskii
  2021-02-21 19:03         ` Stefan Kangas
  2021-02-22 22:34       ` Lars Ingebrigtsen
  2 siblings, 1 reply; 12+ messages in thread
From: Eli Zaretskii @ 2021-02-21 17:43 UTC (permalink / raw)
  To: Stefan Kangas; +Cc: larsi, emacs-devel

> From: Stefan Kangas <stefan@marxist.se>
> Date: Sun, 21 Feb 2021 04:37:45 -0600
> Cc: Eli Zaretskii <eliz@gnu.org>, emacs-devel@gnu.org
> 
> * lisp/man.el (man-shared-mode): New mode inheriting special-mode.

I suggest to call it "man-common" or "man-basic".

Thanks.



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: master 388a874 2/4: Do interactive mode tagging for man.el
  2021-02-21 17:43       ` Eli Zaretskii
@ 2021-02-21 19:03         ` Stefan Kangas
  0 siblings, 0 replies; 12+ messages in thread
From: Stefan Kangas @ 2021-02-21 19:03 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: larsi, emacs-devel

Eli Zaretskii <eliz@gnu.org> writes:

>> From: Stefan Kangas <stefan@marxist.se>
>> Date: Sun, 21 Feb 2021 04:37:45 -0600
>> Cc: Eli Zaretskii <eliz@gnu.org>, emacs-devel@gnu.org
>>
>> * lisp/man.el (man-shared-mode): New mode inheriting special-mode.
>
> I suggest to call it "man-common" or "man-basic".

Yes, that's better.  I'll change it.



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: master 388a874 2/4: Do interactive mode tagging for man.el
  2021-02-21 15:48       ` Lars Ingebrigtsen
@ 2021-02-21 19:18         ` Stefan Kangas
  0 siblings, 0 replies; 12+ messages in thread
From: Stefan Kangas @ 2021-02-21 19:18 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: Eli Zaretskii, emacs-devel

Lars Ingebrigtsen <larsi@gnus.org> writes:

> Looks good to me.

Thanks, pushed to master (with Eli's suggested name change).

See commit ff759b1d0a.



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: master 388a874 2/4: Do interactive mode tagging for man.el
  2021-02-21 10:37     ` Stefan Kangas
  2021-02-21 15:48       ` Lars Ingebrigtsen
  2021-02-21 17:43       ` Eli Zaretskii
@ 2021-02-22 22:34       ` Lars Ingebrigtsen
  2 siblings, 0 replies; 12+ messages in thread
From: Lars Ingebrigtsen @ 2021-02-22 22:34 UTC (permalink / raw)
  To: Stefan Kangas; +Cc: Eli Zaretskii, emacs-devel

I've further tweaked my interactive tagging helper command to do
grepping to give a bit of information about whether the command in
question is used in other places in Emacs (like in the wo/man case) and
tested it in a couple of small files.  Seems to work OK, but can
probably do with some tweaking to reduce false positives.

(global-set-key [(hyper l)] 'my-fix-command)
(defvar my-prev-mode nil)
(defun my-fix-command ()
  (interactive)
  (let ((mode nil)
	(regexp "(define-derived-mode \\([^ \t\n]+\\)\\|(defun \\([^ \t\n]+-mode\\) ")
	change bindings)
    (if (not (re-search-forward "^ *\\((interactive\\)" nil t))
	(message "No more interactive in this file")
      (recenter nil t)
      (save-match-data
	(save-excursion
	  (beginning-of-defun)
	  (let ((form (read (current-buffer))))
	    (when (and (listp form)
		       (eq (car form) 'defun))
	      (setq bindings
		    (shell-command-to-string
		     (format
		      "cd %s../lisp; grep -r --include '*.el' \"define-key.*'%s\""
		      data-directory (cadr form)))))))
	(save-excursion
	  (when (or (re-search-backward regexp nil t)
		    (re-search-forward regexp nil t))
	    (setq mode (or (match-string 1) (match-string 2)))))
	(setq change (read-string (format "%sChange to: "
					  (or bindings ""))
				  (or mode my-prev-mode))))
      (when (plusp (length change))
	(setq mode change)
	(goto-char (match-beginning 1))
	(let ((form (read (current-buffer))))
	  (goto-char (match-beginning 1))
	  (forward-char 1)
	  (if (> (length form) 1)
	      (progn
		(forward-sexp 2)
		(insert " " mode))
	    (forward-sexp 1)
	    (insert " nil " mode))
	  (forward-sexp -1))
	(setq my-prev-mode mode)))))

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2021-02-22 22:34 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-19 15:56 master 388a874 2/4: Do interactive mode tagging for man.el Eli Zaretskii
2021-02-20  2:24 ` Stefan Kangas
2021-02-20  7:39   ` Eli Zaretskii
2021-02-20 12:26     ` Lars Ingebrigtsen
2021-02-20 12:56       ` Eli Zaretskii
2021-02-20 12:23   ` Lars Ingebrigtsen
2021-02-21 10:37     ` Stefan Kangas
2021-02-21 15:48       ` Lars Ingebrigtsen
2021-02-21 19:18         ` Stefan Kangas
2021-02-21 17:43       ` Eli Zaretskii
2021-02-21 19:03         ` Stefan Kangas
2021-02-22 22:34       ` Lars Ingebrigtsen

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).