djcb / mu

maildir indexer/searcher + emacs mail client + guile bindings
http://www.djcbsoftware.nl/code/mu
GNU General Public License v3.0
1.62k stars 391 forks source link

[misc] The zero width space in man-link prevents emacs from referencing related man pages #2753

Closed quaepoena closed 2 months ago

quaepoena commented 2 months ago

Describe the issue

The use of a zero width space (0x200B) in the man-link macro prevents Emacs' man page viewer from parsing the SEE ALSO section of the mu* man pages, e.g. with Man-follow-manual-reference. I understand why it's there, and I don't see a way to fix this issue that involves changing the macro itself.

I was somewhat able to fix this, though, with the following code and then running C-c C-e M m or (org-export-to-buffer 'man "mu.1.org-out").

;; Replace the ZERO WIDTH SPACE inserted by the man-link macro.
(defun qp-man-filter-remove-zero-width-space (text backend _info)
  (when (org-export-derived-backend-p backend 'man)
    (replace-regexp-in-string "​" "" text)))
(add-to-list 'org-export-filter-plain-text-functions 'qp-man-filter-remove-zero-width-space)

When I tried to add that code to man/meson.build, however, the resulting files in build/man/ still have the zero width spaces.

expr_tmpl = ''.join([
  '(progn',
  '  (require \'ox-man)',
  '  (setq org-export-with-sub-superscripts \'{})',
  '  (org-export-to-file \'man "@0@")',
  '  (defun qp-man-filter-remove-zero-width-space (text backend _info)',
  '    (when (org-export-derived-backend-p backend \'man)',
  '      (replace-regexp-in-string "​" "" text)))',
  '  (add-to-list \'org-export-filter-plain-text-functions \'qp-man-filter-remove-zero-width-space))'])

An example line exported manually:

\fBmu-add\fP(1),

An example line exported from make:

\fBmu-add\fP​(1),

I know very little about exporting from org and building with meson, so I don't have any further ideas about how to solve this.

Environment

Emacs 29.4 mu 1.12.6

djcb commented 2 months ago

@Tristan02d: any thoughts on this? Thanks!

quaepoena commented 2 months ago

I was making a silly mistake in meson.build by defining my function and adding to org-export-filter-plain-text-functions after org-export-to-file was called. The code below works as intended.

expr_tmpl = ''.join([
  '(progn',
  '  (require \'ox-man)',
  '  (setq org-export-with-sub-superscripts \'{})',
  '  (defun qp-man-filter-remove-zero-width-space (text backend _info)',
  '    (when (org-export-derived-backend-p backend \'man)',
  '      (replace-regexp-in-string "​" "" text)))',
  '  (add-to-list \'org-export-filter-plain-text-functions',
  '    \'qp-man-filter-remove-zero-width-space)',
  '  (org-export-to-file \'man "@0@"))'])

Now it's a question of whether this fix is desirable. One further thing to note is that the check in when isn't strictly necessary since this is only used to build man pages.

quaepoena commented 2 months ago

Suggested fix using a lambda and no when-statement.

Tristan02d commented 2 months ago

All these spaces do is deleting an extra visual space when manual pages are rendered in either the terminal or Emacs. This small enhancement might not be worth adding too much complexity to the build system. For now the provided fix works well and is simple, so I think keeping these spaces and merging it is OK. But if one day a problem from these spaces require adding 10 lines in the Meson files, just getting rid of them would be better I think.

djcb commented 2 months ago

@Tristan02d: thanks!

@quaepoena: can you make a PR? The change looks okay but could you add a comment describing with it does? And esp. the replace-regexp-in-string, can we use some unicode codepoint for the zero-width string so it becomes a bit clearer? Thanks.