Re: TeX-documentation-texdoc

2023-01-28 Thread Ikumi Keita
Hi,

> Arash Esbati  writes:
> Hi Keita,
> Ikumi Keita  writes:

>> That's a good idea. Can I leave that work to you?

> Yes, you can :-)  I'll try to work on this soonish.

Thank you. I pushed the commit except the prompt formatting.

Regards,
Ikumi Keita
#StandWithUkraine #StopWarInUkraine



Re: TeX-documentation-texdoc

2023-01-27 Thread Arash Esbati
Hi Keita,

Ikumi Keita  writes:

> That's a good idea. Can I leave that work to you?

Yes, you can :-)  I'll try to work on this soonish.

Best, Arash



Re: TeX-documentation-texdoc

2023-01-27 Thread Ikumi Keita
Hi Arash,

> Arash Esbati  writes:
> Thanks for working on this.  Reg.
> 0001-Make-TeX-documentation-texdoc-work-for-okular, I have some minor
> comments:

Thanks.

> I think we can shorten this by calling `thing-at-point' with the
> optional second argument NO-PROPERTIES

>   (thing-at-point THING  NO-PROPERTIES)

>   When the optional argument NO-PROPERTIES is non-nil,
>   strip text properties from the return value.

> => (let ((pkg (thing-at-point 'symbol t))

Indeed. I wasn't aware of the optional argument.

> Is this `save-excursion' really necessary?  Or am I missing something?

Thanks, I just copied the previous code without looking at it well.

> +  (while (re-search-forward
> +  ;; XXX: XEmacs doesn't support character classes in
> +  ;; regexps, like "[:alnum:]".

> I think we can delete this comment.

OK.

> I think we should borrow some code from the compat-package[1] and
> introduce our `TeX-format-prompt' and once we're at Emacs 28, we just
> alias it to `format-prompt' or use `format-prompt' directly.  Suppose we
> have this in tex.el:

> Then we could write:
> (setq pkg (TeX-read-string (TeX-format-prompt
> "View documentation for" pkg)
>nil nil pkg))
> Adjusting the other 30 occurrences in the repo should be easy.  WDYT?

That's a good idea. Can I leave that work to you?

Regards,
Ikumi Keita
#StandWithUkraine #StopWarInUkraine



0001-Fix-TeX-documentation-texdoc-for-okular.patch.gz
Description: revised patch


Re: TeX-documentation-texdoc

2023-01-26 Thread Arash Esbati
Hi Keita,

Ikumi Keita  writes:

> Thanks for confirmation. I'll commit the attached patch #1,
> incorporating Arash's suggestion.

Thanks for working on this.  Reg.
0001-Make-TeX-documentation-texdoc-work-for-okular, I have some minor
comments:

diff --git a/tex.el b/tex.el
index 456c0310..c905ce29 100644
--- a/tex.el
+++ b/tex.el
@@ -6390,81 +6390,55 @@ If called with a prefix argument ARG, after selecting 
the
 package, prompt for selection of the manual of that package to
 show."
[...]
+  (if (not (executable-find "texdoc"))
+  (message "texdoc not found")
+(let ((pkg (thing-at-point 'symbol))
+  buffer list doc)
+  ;; Strip off properties.
+  (set-text-properties 0 (length pkg) nil pkg)

I think we can shorten this by calling `thing-at-point' with the
optional second argument NO-PROPERTIES

  (thing-at-point THING  NO-PROPERTIES)

  Return the THING at point.
  THING should be a symbol specifying a type of syntactic entity.
  Possibilities include ‘symbol’, ‘list’, ‘sexp’, ‘defun’,
  ‘filename’, ‘existing-filename’, ‘url’, ‘email’, ‘uuid’, ‘word’,
  ‘sentence’, ‘whitespace’, ‘line’, ‘number’, ‘face’ and ‘page’.

  When the optional argument NO-PROPERTIES is non-nil,
  strip text properties from the return value.

=> (let ((pkg (thing-at-point 'symbol t))

+  (setq pkg (TeX-read-string "View documentation for: " pkg))
+  (unless (zerop (length pkg))
+(if arg
+;; Called with prefix argument: run "texdoc --list --nointeract 
"
+(progn
+  ;; Create the buffer, insert the result of the command, and
+  ;; accumulate the list of manuals.
+  (with-current-buffer (get-buffer-create
+(setq buffer (format "*texdoc: %s*" pkg)))
+(erase-buffer)
+(insert (shell-command-to-string
+ (concat "texdoc --list --nointeract " pkg)))
+(goto-char 1) ; No need to use `point-min' here.
+(save-excursion

Is this `save-excursion' really necessary?  Or am I missing something?

+  (while (re-search-forward
+  ;; XXX: XEmacs doesn't support character classes in
+  ;; regexps, like "[:alnum:]".

I think we can delete this comment.

> I think I should go further to settle out the discrepancy between
> `shell-command-*' and `call-process' by the patch #2.

+1

> It also turns INITIAL-INPUT argument for `TeX-read-string' into
> DEFAULT, taking your effort into accout. What do you think about it?

Thanks for thinking about it :-)  I have an idea here:

diff --git a/tex.el b/tex.el
index c905ce29..4ab5d170 100644
--- a/tex.el
+++ b/tex.el
-  (setq pkg (TeX-read-string "View documentation for: " pkg))
+  (if pkg
+  (set-text-properties 0 (length pkg) nil pkg))
+  (setq pkg (TeX-read-string (concat
+  "View documentation for"
+  (if pkg
+  (format " (default %s)" pkg))
+  ": ")
+ nil nil pkg))

I think we should borrow some code from the compat-package[1] and
introduce our `TeX-format-prompt' and once we're at Emacs 28, we just
alias it to `format-prompt' or use `format-prompt' directly.  Suppose we
have this in tex.el:

--8<---cut here---start->8---
(defun TeX-format-prompt (prompt default  format-args)
  "Format PROMPT with DEFAULT.
If FORMAT-ARGS is nil, PROMPT is used as a plain string.  If
FORMAT-ARGS is non-nil, PROMPT is used as a format control
string, and FORMAT-ARGS are the arguments to be substituted into
it.  See `format' for details.
If DEFAULT is a list, the first element is used as the default.
If not, the element is used as is.
If DEFAULT is nil or an empty string, no \"default value\" string
is included in the return value."
  (concat
   (if (null format-args)
   prompt
 (apply #'format prompt format-args))
   (and default
(or (not (stringp default))
(> (length default) 0))
(format " (default %s)"
(if (consp default)
(car default)
  default)))
   ": "))
--8<---cut here---end--->8---

Then we could write:

--8<---cut here---start->8---
(setq pkg (TeX-read-string (TeX-format-prompt
"View documentation for" pkg)
   nil nil pkg))
--8<---cut here---end--->8---

Adjusting the other 30 occurrences in the repo should be easy.  WDYT?

Best, Arash

Footnotes:
[1]  
https://github.com/emacs-compat/compat/blob/f6c5ffc6485ea2d2b0c65e7189895ec06124792e/compat-28.el#L610



Re: TeX-documentation-texdoc

2023-01-26 Thread Ikumi Keita
Hi Greg and Arash,

> Greg Bognar  writes:
> Great, it works now! It opens the requested file in the viewer and
> gives an error message if it does not exist. (Well, it often opens a
> file even if I give it a nonsensical string, like "d", which opens
> the documentation for baskervaldadf -- but I assume that's a texdoc
> thing.)

Thanks for confirmation. I'll commit the attached patch #1,
incorporating Arash's suggestion.

To Arash:
I think I should go further to settle out the discrepancy between
`shell-command-*' and `call-process' by the patch #2. It also turns
INITIAL-INPUT argument for `TeX-read-string' into DEFAULT, taking
your effort into accout. What do you think about it?

Regards,
Ikumi Keita
#StandWithUkraine #StopWarInUkraine



0001-Make-TeX-documentation-texdoc-work-for-okular.patch.gz
Description: Fix for okular


0002-Don-t-use-INITIAL-INPUT-argument-for-TeX-read-string.patch.gz
Description: Small improvement


Re: TeX-documentation-texdoc

2023-01-24 Thread Ikumi Keita
Hi Arash,

> Arash Esbati  writes:
> thanks for looking at this.  I have one question: Would it make sense to
> move the (executable-find "texdoc") further up in the function body?

Yes, I think that it would make sense well. I honored the following
comment in the former half of the defun, but it doesn't seem much
important for me actually.
,
|   ;; Note: `shell-command-to-string' uses shell, only
|   ;; `call-process' looks at `exec-path', thus only here makes
|   ;; sense to use `executable-find' to test whether texdoc is
|   ;; available.
`
Thus I'm fine to follow your suggestion.

Regards,
Ikumi Keita
#StandWithUkraine #StopWarInUkraine



Re: TeX-documentation-texdoc

2023-01-24 Thread Arash Esbati
Hi Keita,

Ikumi Keita  writes:

> Thus I think that AUCTeX need not collect the output now; it just has to
> look at the exit code. We can use `call-process' (with `executable-find'
> test in case that Texdoc isn't available) to run Texdoc.

thanks for looking at this.  I have one question: Would it make sense to
move the (executable-find "texdoc") further up in the function body?
Currently, we do:

(if arg
(progn
  (insert (shell-command-to-string
   (concat "texdoc --list --nointeract " pkg)))
  ...
  (cond
   ((null (executable-find "texdoc"))
(message "texdoc not found"
  (if (executable-find "texdoc")
  ...
(message "texdoc not found")))

The way I see it the code executes texdoc and checks later if it finds
it, and then again further below in else part.

Or am I missing something?

Best, Arash



Re: TeX-documentation-texdoc

2023-01-24 Thread Greg Bognar via General discussion about AUCTeX
Great, it works now!  It opens the requested file in the viewer and gives an
error message if it does not exist.  (Well, it often opens a file even if I give
it a nonsensical string, like "d", which opens the documentation for
baskervaldadf -- but I assume that's a texdoc thing.)

All the best,
Greg

---
On Tue 24 Jan 2023 at 06:27 Ikumi Keita wrote:
> > Greg Bognar  writes:
> > 1. Unfortunately, the new function definition below does not work with
> > okular. Same problem as before.
> 
> Too bad. :-)
> 
> > 2. All of the environment variables PDFVIEWER, PDFVIEWER_texdoc,
> > TEXDOCVIEW_pdf, and TEXDOC_VIEWER_PDF have an empty value.
> 
> Thank you. It seems that the reported behavior originates from okular's
> own nature.
> 
> Then can you test the code at the last of this message?
> 
> [Rationale] The reason that `TeX-documentation-texdoc' tries hard to
> collect and show the output from Texdoc is that the exit code wasn't
> meaningful once[1]. However, recent Texdoc is improved to return
> non-zero exit code when it can't find documentation for the given
> keyword[2].
> 
> Thus I think that AUCTeX need not collect the output now; it just has to
> look at the exit code. We can use `call-process' (with `executable-find'
> test in case that Texdoc isn't available) to run Texdoc.
> 
> This has a drawback that the user who sticks to older TeX Live
> distribution isn't notified at all when the given keyword didn't match
> any documentation, but I expect it's permissible. Mosè, what do you
> think about it?
> 
> Regards,
> Ikumi Keita
> #StandWithUkraine #StopWarInUkraine
> 
> [1] https://debbugs.gnu.org/cgi/bugreport.cgi?bug=28905#17
> [2] https://tug.org/texdoc/doc/texdoc.man1.pdf
> 
> --
> (defun TeX-documentation-texdoc ( arg)
>   "Run texdoc to read documentation.
> 
> Prompt for selection of the package of which to show the documentation.
> 
> If called with a prefix argument ARG, after selecting the
> package, prompt for selection of the manual of that package to
> show."
>   (interactive "P")
>   (let ((pkg (thing-at-point 'symbol))
> buffer list doc)
> ;; Strip off properties.  XXX: XEmacs doesn't have
> ;; `substring-no-properties'.
> (set-text-properties 0 (length pkg) nil pkg)
> (setq pkg (TeX-read-string "View documentation for: " pkg))
> (unless (zerop (length pkg))
>   (if arg
>   ;; Called with prefix argument: run "texdoc --list --nointeract 
> "
>   (progn
> ;; Create the buffer, insert the result of the command, and
> ;; accumulate the list of manuals.
> (with-current-buffer (get-buffer-create
>   (setq buffer (format "*texdoc: %s*" pkg)))
>   (erase-buffer)
>   (insert (shell-command-to-string
>(concat "texdoc --list --nointeract " pkg)))
>   (goto-char 1) ; No need to use `point-min' here.
>   (save-excursion
> (while (re-search-forward
> ;; XXX: XEmacs doesn't support character classes in
> ;; regexps, like "[:alnum:]".
> "^ *\\([0-9]+\\) +\\([-~/a-zA-Z0-9_.${}#%,:\\ 
> ()]+\\)" nil t)
>   (push (cons (match-string 1) (match-string 2)) list
> (unwind-protect
> (cond
>  ((null (executable-find "texdoc"))
>   ;; Note: `shell-command-to-string' uses shell, only
>   ;; `call-process' looks at `exec-path', thus only here makes
>   ;; sense to use `executable-find' to test whether texdoc is
>   ;; available.
>   (message "texdoc not found"))
>  (list
>   ;; Go on if there are manuals listed: show the buffer, 
> prompt
>   ;; for the number of the manual, then run
>   ;; texdoc --just-view 
>   (TeX-pop-to-buffer (get-buffer buffer))
>   (condition-case nil
>   (when (setq doc
>   (cdr (assoc (TeX-read-string "Please enter \
> the number of the file to view, anything else to skip: ") list)))
> (call-process "texdoc" nil 0 nil "--just-view" doc))
> ;; Exit gently if a `quit' signal is thrown.
> (quit nil)))
>  (t (message "No documentation found for %s" pkg)))
>   ;; In any case quit-and-kill the window.
>   (when (get-buffer-window buffer)
> (quit-window t (get-buffer-window buffer)
> ;; Called without prefix argument: just run "texdoc --view ".
> ;; The folowing code to the end of `defun' used to be just
> ;; (message "%s" 

Re: TeX-documentation-texdoc

2023-01-23 Thread Ikumi Keita
> Greg Bognar  writes:
> 1. Unfortunately, the new function definition below does not work with
> okular. Same problem as before.

Too bad. :-)

> 2. All of the environment variables PDFVIEWER, PDFVIEWER_texdoc,
> TEXDOCVIEW_pdf, and TEXDOC_VIEWER_PDF have an empty value.

Thank you. It seems that the reported behavior originates from okular's
own nature.

Then can you test the code at the last of this message?

[Rationale] The reason that `TeX-documentation-texdoc' tries hard to
collect and show the output from Texdoc is that the exit code wasn't
meaningful once[1]. However, recent Texdoc is improved to return
non-zero exit code when it can't find documentation for the given
keyword[2].

Thus I think that AUCTeX need not collect the output now; it just has to
look at the exit code. We can use `call-process' (with `executable-find'
test in case that Texdoc isn't available) to run Texdoc.

This has a drawback that the user who sticks to older TeX Live
distribution isn't notified at all when the given keyword didn't match
any documentation, but I expect it's permissible. Mosè, what do you
think about it?

Regards,
Ikumi Keita
#StandWithUkraine #StopWarInUkraine

[1] https://debbugs.gnu.org/cgi/bugreport.cgi?bug=28905#17
[2] https://tug.org/texdoc/doc/texdoc.man1.pdf

--
(defun TeX-documentation-texdoc ( arg)
  "Run texdoc to read documentation.

Prompt for selection of the package of which to show the documentation.

If called with a prefix argument ARG, after selecting the
package, prompt for selection of the manual of that package to
show."
  (interactive "P")
  (let ((pkg (thing-at-point 'symbol))
buffer list doc)
;; Strip off properties.  XXX: XEmacs doesn't have
;; `substring-no-properties'.
(set-text-properties 0 (length pkg) nil pkg)
(setq pkg (TeX-read-string "View documentation for: " pkg))
(unless (zerop (length pkg))
  (if arg
  ;; Called with prefix argument: run "texdoc --list --nointeract "
  (progn
;; Create the buffer, insert the result of the command, and
;; accumulate the list of manuals.
(with-current-buffer (get-buffer-create
  (setq buffer (format "*texdoc: %s*" pkg)))
  (erase-buffer)
  (insert (shell-command-to-string
   (concat "texdoc --list --nointeract " pkg)))
  (goto-char 1) ; No need to use `point-min' here.
  (save-excursion
(while (re-search-forward
;; XXX: XEmacs doesn't support character classes in
;; regexps, like "[:alnum:]".
"^ *\\([0-9]+\\) +\\([-~/a-zA-Z0-9_.${}#%,:\\ ()]+\\)" 
nil t)
  (push (cons (match-string 1) (match-string 2)) list
(unwind-protect
(cond
 ((null (executable-find "texdoc"))
  ;; Note: `shell-command-to-string' uses shell, only
  ;; `call-process' looks at `exec-path', thus only here makes
  ;; sense to use `executable-find' to test whether texdoc is
  ;; available.
  (message "texdoc not found"))
 (list
  ;; Go on if there are manuals listed: show the buffer, prompt
  ;; for the number of the manual, then run
  ;; texdoc --just-view 
  (TeX-pop-to-buffer (get-buffer buffer))
  (condition-case nil
  (when (setq doc
  (cdr (assoc (TeX-read-string "Please enter \
the number of the file to view, anything else to skip: ") list)))
(call-process "texdoc" nil 0 nil "--just-view" doc))
;; Exit gently if a `quit' signal is thrown.
(quit nil)))
 (t (message "No documentation found for %s" pkg)))
  ;; In any case quit-and-kill the window.
  (when (get-buffer-window buffer)
(quit-window t (get-buffer-window buffer)
;; Called without prefix argument: just run "texdoc --view ".
;; The folowing code to the end of `defun' used to be just
;; (message "%s" (shell-command-to-string (concat "texdoc --view " 
pkg)))
;; , but in some cases it blocks emacs until the user
;; quits the viewer (bug#28905).
;; (2023-01-24) Now we use `call-process' instead of
;; `start-process-shell-command'.  This can introduce
;; discrepancy in the process environment, especially PATH.
;; But we need to do so to support both okular and evince.  We
;; hope that it doesn't cause major problem.
(if (executable-find "texdoc")
;; Recent Texdoc returns exit code 3 when it can't find the
;; specified document, according to

Re: TeX-documentation-texdoc

2023-01-23 Thread Greg Bognar via General discussion about AUCTeX
Hi Ikumi,

1. Unfortunately, the new function definition below does not work with okular.
Same problem as before.

2. All of the environment variables PDFVIEWER, PDFVIEWER_texdoc, TEXDOCVIEW_pdf,
and TEXDOC_VIEWER_PDF have an empty value.

All the best,
Greg
 

---
On Mon 23 Jan 2023 at 08:33 Ikumi Keita wrote:
> Hi Greg,
> 
> > Greg Bognar  writes:
> > Your code works! So yes, your commit harmed okular in some way.
> 
> Thank you. That's a bad news for me :-)
> 
> > Where do we go from here?
> 
> Then we have to find out the way compatible for both okular and evince.
> Unfortunately, the old code is bad for evince; it still blocks emacs
> until the user quits evince as described in bug#28905[1].
> 
> [1] https://debbugs.gnu.org/28905
> 
> 1. Can you please test the following code, then? This uses
>`start-process' instead of `start-process-shell-command', as suggested
>by Mosè in the thread of [1].
> --
> (defun TeX-documentation-texdoc ( arg)
>   "Run texdoc to read documentation.
> 
> Prompt for selection of the package of which to show the documentation.
> 
> If called with a prefix argument ARG, after selecting the
> package, prompt for selection of the manual of that package to
> show."
>   (interactive "P")
>   (let ((pkg (thing-at-point 'symbol))
> buffer list doc)
> ;; Strip off properties.  XXX: XEmacs doesn't have
> ;; `substring-no-properties'.
> (set-text-properties 0 (length pkg) nil pkg)
> (setq pkg (TeX-read-string "View documentation for: " pkg))
> (unless (zerop (length pkg))
>   (if arg
>   ;; Called with prefix argument: run "texdoc --list --nointeract 
> "
>   (progn
> ;; Create the buffer, insert the result of the command, and
> ;; accumulate the list of manuals.
> (with-current-buffer (get-buffer-create
>   (setq buffer (format "*texdoc: %s*" pkg)))
>   (erase-buffer)
>   (insert (shell-command-to-string
>(concat "texdoc --list --nointeract " pkg)))
>   (goto-char 1) ; No need to use `point-min' here.
>   (save-excursion
> (while (re-search-forward
> ;; XXX: XEmacs doesn't support character classes in
> ;; regexps, like "[:alnum:]".
> "^ *\\([0-9]+\\) +\\([-~/a-zA-Z0-9_.${}#%,:\\ 
> ()]+\\)" nil t)
>   (push (cons (match-string 1) (match-string 2)) list
> (unwind-protect
> (cond
>  ((null (executable-find "texdoc"))
>   ;; Note: `shell-command-to-string' uses shell, only
>   ;; `call-process' looks at `exec-path', thus only here makes
>   ;; sense to use `executable-find' to test whether texdoc is
>   ;; available.
>   (message "texdoc not found"))
>  (list
>   ;; Go on if there are manuals listed: show the buffer, 
> prompt
>   ;; for the number of the manual, then run
>   ;; texdoc --just-view 
>   (TeX-pop-to-buffer (get-buffer buffer))
>   (condition-case nil
>   (when (setq doc
>   (cdr (assoc (TeX-read-string "Please enter \
> the number of the file to view, anything else to skip: ") list)))
> (call-process "texdoc" nil 0 nil "--just-view" doc))
> ;; Exit gently if a `quit' signal is thrown.
> (quit nil)))
>  (t (message "No documentation found for %s" pkg)))
>   ;; In any case quit-and-kill the window.
>   (when (get-buffer-window buffer)
> (quit-window t (get-buffer-window buffer)
> ;; Called without prefix argument: just run "texdoc --view " and
> ;; show the output, so that the user is warned in case it doesn't find
> ;; the documentation or "texdoc" is not available.
> (message "%s"
>  ;; The folowing code to the end of `defun' used to be
>  ;; just
>  ;; (shell-command-to-string (concat "texdoc --view " pkg))
>  ;; , but in some cases it blocks emacs until the user
>  ;; quits the viewer (bug#28905).
>  (with-output-to-string
>(let* (;; Use pipe rather than pty because the
>   ;; latter causes atril (evince variant
>   ;; viewer) to exit before showing anything.
>   (process-connection-type nil)
>   (process (start-process
> "Doc view" 

Re: TeX-documentation-texdoc

2023-01-22 Thread Ikumi Keita
Hi Greg,

> Greg Bognar  writes:
> Your code works! So yes, your commit harmed okular in some way.

Thank you. That's a bad news for me :-)

> Where do we go from here?

Then we have to find out the way compatible for both okular and evince.
Unfortunately, the old code is bad for evince; it still blocks emacs
until the user quits evince as described in bug#28905[1].

[1] https://debbugs.gnu.org/28905

1. Can you please test the following code, then? This uses
   `start-process' instead of `start-process-shell-command', as suggested
   by Mosè in the thread of [1].
--
(defun TeX-documentation-texdoc ( arg)
  "Run texdoc to read documentation.

Prompt for selection of the package of which to show the documentation.

If called with a prefix argument ARG, after selecting the
package, prompt for selection of the manual of that package to
show."
  (interactive "P")
  (let ((pkg (thing-at-point 'symbol))
buffer list doc)
;; Strip off properties.  XXX: XEmacs doesn't have
;; `substring-no-properties'.
(set-text-properties 0 (length pkg) nil pkg)
(setq pkg (TeX-read-string "View documentation for: " pkg))
(unless (zerop (length pkg))
  (if arg
  ;; Called with prefix argument: run "texdoc --list --nointeract "
  (progn
;; Create the buffer, insert the result of the command, and
;; accumulate the list of manuals.
(with-current-buffer (get-buffer-create
  (setq buffer (format "*texdoc: %s*" pkg)))
  (erase-buffer)
  (insert (shell-command-to-string
   (concat "texdoc --list --nointeract " pkg)))
  (goto-char 1) ; No need to use `point-min' here.
  (save-excursion
(while (re-search-forward
;; XXX: XEmacs doesn't support character classes in
;; regexps, like "[:alnum:]".
"^ *\\([0-9]+\\) +\\([-~/a-zA-Z0-9_.${}#%,:\\ ()]+\\)" 
nil t)
  (push (cons (match-string 1) (match-string 2)) list
(unwind-protect
(cond
 ((null (executable-find "texdoc"))
  ;; Note: `shell-command-to-string' uses shell, only
  ;; `call-process' looks at `exec-path', thus only here makes
  ;; sense to use `executable-find' to test whether texdoc is
  ;; available.
  (message "texdoc not found"))
 (list
  ;; Go on if there are manuals listed: show the buffer, prompt
  ;; for the number of the manual, then run
  ;; texdoc --just-view 
  (TeX-pop-to-buffer (get-buffer buffer))
  (condition-case nil
  (when (setq doc
  (cdr (assoc (TeX-read-string "Please enter \
the number of the file to view, anything else to skip: ") list)))
(call-process "texdoc" nil 0 nil "--just-view" doc))
;; Exit gently if a `quit' signal is thrown.
(quit nil)))
 (t (message "No documentation found for %s" pkg)))
  ;; In any case quit-and-kill the window.
  (when (get-buffer-window buffer)
(quit-window t (get-buffer-window buffer)
;; Called without prefix argument: just run "texdoc --view " and
;; show the output, so that the user is warned in case it doesn't find
;; the documentation or "texdoc" is not available.
(message "%s"
 ;; The folowing code to the end of `defun' used to be
 ;; just
 ;; (shell-command-to-string (concat "texdoc --view " pkg))
 ;; , but in some cases it blocks emacs until the user
 ;; quits the viewer (bug#28905).
 (with-output-to-string
   (let* (;; Use pipe rather than pty because the
  ;; latter causes atril (evince variant
  ;; viewer) to exit before showing anything.
  (process-connection-type nil)
  (process (start-process
"Doc view" standard-output
"texdoc" "--view" pkg)))
 ;; Suppress the message "Process Doc view
 ;; finished".
 (set-process-sentinel process #'ignore)
 ;; Kill temp buffer without query.  This is
 ;; necessary, at least for some environment, if
 ;; the underlying shell can't find the texdoc
 ;; executable.
 (set-process-query-on-exit-flag process nil)
 ;; Don't discard shell output.
 

Re: TeX-documentation-texdoc

2023-01-22 Thread Greg Bognar via General discussion about AUCTeX
Hi Ikumi,

Your code works!  So yes, your commit harmed okular in some way.  Where do we go
from here?

All the best,
Greg

---
On Sun 22 Jan 2023 at 10:37 Ikumi Keita wrote:
> 
> Hi Greg,
> 
> > Greg Bognar via General discussion about AUCTeX  writes:
> > It turns out that C-u C-c? works: it opens a buffer with a list of related 
> > files
> > and then opens the selected one in my PDF viewer (okular).  It's only when I
> > call `TeX-documentation-texdoc' without a prefix argument that okular seems 
> > to
> > be started (a startup notification appears in the panel), but then 
> > disappears
> > and nothing happens.
> 
> > texdoc itself has no problem starting the PDF viewer, and it seems all
> > `TeX-documentation-texdoc' does is calling it.  I don't understand why it 
> > works
> > with a prefix argument but not without one.
> 
> That's because `TeX-documentation-texdoc' is written to behave in such a
> way:
> ,
> | (defun TeX-documentation-texdoc ( arg)
> |   "Run texdoc to read documentation.
> | [...]
> | If called with a prefix argument ARG, after selecting the
> | package, prompt for selection of the manual of that package to
> | show."
> | [...]
> |   (if arg
> |   ;; Called with prefix argument: run "texdoc --list --nointeract 
> "
> | [...]
> | (call-process "texdoc" nil 0 nil "--just-view" doc))
> | [...]
> | ;; Called without prefix argument: just run "texdoc --view " 
> and
> | ;; show the output, so that the user is warned in case it doesn't 
> find
> | ;; the documentation or "texdoc" is not available.
> | [...]
> |   (process (start-process-shell-command
> | "Doc view" standard-output
> | (concat "texdoc --view " pkg
> | [...]
> `
> 
> The difference is that it calls texdoc by `call-process' if prefix
> arugment is given while by `start-process-shell-command' without prefix
> argument.
> 
> By the way, I remember there was a similar bug report[1] before. In that
> report, the PDF viewer was okular, too. So I suspect that AUCTeX has
> something potentially inconsistent with okular.
> 
> [1] https://debbugs.gnu.org/cgi/bugreport.cgi?bug=40577
> 
> Can you test whether the following code works for you? This was used
> before my commit mentioned in [1]. I'd like to know whether my commit
> harmed okular or not.
> 
> Regards,
> Ikumi Keita
> #StandWithUkraine #StopWarInUkraine
> 
> --
> (defun TeX-documentation-texdoc ( arg)
>   "Run texdoc to read documentation.
> 
> Prompt for selection of the package of which to show the documentation.
> 
> If called with a prefix argument ARG, after selecting the
> package, prompt for selection of the manual of that package to
> show."
>   (interactive "P")
>   (let ((pkg (thing-at-point 'symbol))
>   buffer list doc)
> ;; Strip off properties.  XXX: XEmacs doesn't have
> ;; `substring-no-properties'.
> (set-text-properties 0 (length pkg) nil pkg)
> (setq pkg (TeX-read-string "View documentation for: " pkg))
> (unless (zerop (length pkg))
>   (if arg
> ;; Called with prefix argument: run "texdoc --list --nointeract "
> (progn
>   ;; Create the buffer, insert the result of the command, and
>   ;; accumulate the list of manuals.
>   (with-current-buffer (get-buffer-create
> (setq buffer (format "*texdoc: %s*" pkg)))
> (erase-buffer)
> (insert (shell-command-to-string
>  (concat "texdoc --list --nointeract " pkg)))
> (goto-char 1) ; No need to use `point-min' here.
> (save-excursion
>   (while (re-search-forward
>   ;; XXX: XEmacs doesn't support character classes in
>   ;; regexps, like "[:alnum:]".
>   "^ *\\([0-9]+\\) +\\([-~/a-zA-Z0-9_.${}#%,:\\ ()]+\\)" 
> nil t)
> (push (cons (match-string 1) (match-string 2)) list
>   (unwind-protect
>   (cond
>((null (executable-find "texdoc"))
> ;; Note: `shell-command-to-string' uses shell, only
> ;; `call-process' looks at `exec-path', thus only here makes
> ;; sense to use `executable-find' to test whether texdoc is
> ;; available.
> (message "texdoc not found"))
>(list
> ;; Go on if there are manuals listed: show the buffer, prompt
> ;; for the number of the manual, then run
> ;; texdoc --just-view 
> (TeX-pop-to-buffer (get-buffer buffer))
> (condition-case nil
> (when (setq doc
>  

Re: TeX-documentation-texdoc

2023-01-22 Thread Ikumi Keita
Hi Greg,

> Greg Bognar via General discussion about AUCTeX  writes:
> It turns out that C-u C-c? works: it opens a buffer with a list of related 
> files
> and then opens the selected one in my PDF viewer (okular).  It's only when I
> call `TeX-documentation-texdoc' without a prefix argument that okular seems to
> be started (a startup notification appears in the panel), but then disappears
> and nothing happens.

> texdoc itself has no problem starting the PDF viewer, and it seems all
> `TeX-documentation-texdoc' does is calling it.  I don't understand why it 
> works
> with a prefix argument but not without one.

That's because `TeX-documentation-texdoc' is written to behave in such a
way:
,
| (defun TeX-documentation-texdoc ( arg)
|   "Run texdoc to read documentation.
| [...]
| If called with a prefix argument ARG, after selecting the
| package, prompt for selection of the manual of that package to
| show."
| [...]
|   (if arg
|   ;; Called with prefix argument: run "texdoc --list --nointeract 
"
| [...]
| (call-process "texdoc" nil 0 nil "--just-view" doc))
| [...]
| ;; Called without prefix argument: just run "texdoc --view " and
| ;; show the output, so that the user is warned in case it doesn't find
| ;; the documentation or "texdoc" is not available.
| [...]
|   (process (start-process-shell-command
| "Doc view" standard-output
| (concat "texdoc --view " pkg
| [...]
`

The difference is that it calls texdoc by `call-process' if prefix
arugment is given while by `start-process-shell-command' without prefix
argument.

By the way, I remember there was a similar bug report[1] before. In that
report, the PDF viewer was okular, too. So I suspect that AUCTeX has
something potentially inconsistent with okular.

[1] https://debbugs.gnu.org/cgi/bugreport.cgi?bug=40577

Can you test whether the following code works for you? This was used
before my commit mentioned in [1]. I'd like to know whether my commit
harmed okular or not.

Regards,
Ikumi Keita
#StandWithUkraine #StopWarInUkraine

--
(defun TeX-documentation-texdoc ( arg)
  "Run texdoc to read documentation.

Prompt for selection of the package of which to show the documentation.

If called with a prefix argument ARG, after selecting the
package, prompt for selection of the manual of that package to
show."
  (interactive "P")
  (let ((pkg (thing-at-point 'symbol))
buffer list doc)
;; Strip off properties.  XXX: XEmacs doesn't have
;; `substring-no-properties'.
(set-text-properties 0 (length pkg) nil pkg)
(setq pkg (TeX-read-string "View documentation for: " pkg))
(unless (zerop (length pkg))
  (if arg
  ;; Called with prefix argument: run "texdoc --list --nointeract "
  (progn
;; Create the buffer, insert the result of the command, and
;; accumulate the list of manuals.
(with-current-buffer (get-buffer-create
  (setq buffer (format "*texdoc: %s*" pkg)))
  (erase-buffer)
  (insert (shell-command-to-string
   (concat "texdoc --list --nointeract " pkg)))
  (goto-char 1) ; No need to use `point-min' here.
  (save-excursion
(while (re-search-forward
;; XXX: XEmacs doesn't support character classes in
;; regexps, like "[:alnum:]".
"^ *\\([0-9]+\\) +\\([-~/a-zA-Z0-9_.${}#%,:\\ ()]+\\)" 
nil t)
  (push (cons (match-string 1) (match-string 2)) list
(unwind-protect
(cond
 ((null (executable-find "texdoc"))
  ;; Note: `shell-command-to-string' uses shell, only
  ;; `call-process' looks at `exec-path', thus only here makes
  ;; sense to use `executable-find' to test whether texdoc is
  ;; available.
  (message "texdoc not found"))
 (list
  ;; Go on if there are manuals listed: show the buffer, prompt
  ;; for the number of the manual, then run
  ;; texdoc --just-view 
  (TeX-pop-to-buffer (get-buffer buffer))
  (condition-case nil
  (when (setq doc
  (cdr (assoc (TeX-read-string "Please enter \
the number of the file to view, anything else to skip: ") list)))
(call-process "texdoc" nil 0 nil "--just-view" doc))
;; Exit gently if a `quit' signal is thrown.
(quit nil)))
 (t (message "No documentation found for %s" pkg)))
  ;; In any case quit-and-kill the window.  XXX: 

Re: TeX-documentation-texdoc

2023-01-21 Thread Greg Bognar via General discussion about AUCTeX
It turns out that C-u C-c? works: it opens a buffer with a list of related files
and then opens the selected one in my PDF viewer (okular).  It's only when I
call `TeX-documentation-texdoc' without a prefix argument that okular seems to
be started (a startup notification appears in the panel), but then disappears
and nothing happens.

texdoc itself has no problem starting the PDF viewer, and it seems all
`TeX-documentation-texdoc' does is calling it.  I don't understand why it works
with a prefix argument but not without one.

---
On Fri 20 Jan 2023 at 14:55 Greg Bognar wrote:
> Hi,
> 
> When I run `TeX-documentation-texdoc' (from the menu or with C-c ?), nothing
> happens.  The mouse pointer does turn into busy, but it stops after a while.
> Nothing is written to *Messages* or to .xsession-errors.
> 
> The texdoc command works from the terminal, opening a PDF viewer with the
> requested document.
> 
> I'm not sure whether this is an AUCTeX, Emacs, or window manager issue.  Any
> ideas how I could find out what the problem is?
> 
> All the best,
> Greg



Re: TeX-documentation-texdoc

2023-01-20 Thread Pieter van Oostrum
Greg Bognar via General discussion about AUCTeX  writes:

> Hi,
>
> When I run `TeX-documentation-texdoc' (from the menu or with C-c ?), nothing
> happens.  The mouse pointer does turn into busy, but it stops after a while.
> Nothing is written to *Messages* or to .xsession-errors.
>
> The texdoc command works from the terminal, opening a PDF viewer with the
> requested document.
>
> I'm not sure whether this is an AUCTeX, Emacs, or window manager issue.  Any
> ideas how I could find out what the problem is?
>
> All the best,
> Greg

On my system (MacOS Ventura 13.1, GNU Emacs 28.2, AUCTeX 13.1.8) it works.
Maybe you can do some tracing on TeX-documentation-texdoc, using edebug-defun.
-- 
Pieter van Oostrum 
www: http://pieter.vanoostrum.org/
PGP key: [8DAE142BE17999C4]



Re: TeX-documentation-texdoc

2023-01-20 Thread Greg Bognar via General discussion about AUCTeX
I forgot to mention that I tried that too.  It works.  It prints

Icon theme "gnome" not found.
Icon theme "gnome" not found.
Icon theme "gnome" not found.

... but opens the requested document in a PDF viewer.

It's only when I try TeX-documentation-texdoc that I have the problem.  

---
On Fri 20 Jan 2023 at 15:52 David Kastrup wrote:
> Greg Bognar via General discussion about AUCTeX  writes:
> > Hi,
> >
> > When I run `TeX-documentation-texdoc' (from the menu or with C-c ?), nothing
> > happens.  The mouse pointer does turn into busy, but it stops after a while.
> > Nothing is written to *Messages* or to .xsession-errors.
> >
> > The texdoc command works from the terminal, opening a PDF viewer with the
> > requested document.
> >
> > I'm not sure whether this is an AUCTeX, Emacs, or window manager issue.  Any
> > ideas how I could find out what the problem is?
> 
> Try M-x shell RET and run texdoc from _that_ command line.  That should at
> least carry around some of the environment that TeX-documentation-texdoc is
> working with.  If it fails, you'll probably get some info in the Emacs buffer
> used as terminal.
> 
> -- 
> David Kastrup



Re: TeX-documentation-texdoc

2023-01-20 Thread David Kastrup
Greg Bognar via General discussion about AUCTeX  writes:

> Hi,
>
> When I run `TeX-documentation-texdoc' (from the menu or with C-c ?), nothing
> happens.  The mouse pointer does turn into busy, but it stops after a while.
> Nothing is written to *Messages* or to .xsession-errors.
>
> The texdoc command works from the terminal, opening a PDF viewer with the
> requested document.
>
> I'm not sure whether this is an AUCTeX, Emacs, or window manager issue.  Any
> ideas how I could find out what the problem is?

Try M-x shell RET and run texdoc from _that_ command line.  That should
at least carry around some of the environment that
TeX-documentation-texdoc is working with.  If it fails, you'll probably
get some info in the Emacs buffer used as terminal.

-- 
David Kastrup