Commit Graph

91 Commits

Author SHA1 Message Date
zeertzjq
ad2dbd4b5f
fix(man.vim): support calling :Man without a section again (#17119)
When `man -w` is called with an empty string as section name, it may
fail with an error code, which causes :Man to no longer work without a
section. Just remove that argument when no section is specified.
2022-01-17 11:45:46 -07:00
Will Eccles
7165e7770d
fix(man.vim): fix search function on some systems (#13709)
Fixes man.vim's searching on some systems (namely mandoc) where
previously it would not respect the value of b:man_default_sects. It now
properly parses man pages on these systems.
2022-01-10 09:36:46 -07:00
William Chargin
9fb0f12357
feat(man.vim): convert spaces to underscores #16068
PostgreSQL ships with man pages for SQL statements like `CREATE TABLE`,
which are provided with underscores as `man 7 CREATE_TABLE`. This patch
updates `man#open_page` (as used by `:Man`) such that visually selecting
the words `CREATE TABLE` in SQL code and pressing `K` properly opens the
desired man page.

Writing `:Man CREATE TABLE` still does not work, since `CREATE` is
interpreted as a section name. (Similarly, `:Man CREATE TABLE AS` fails
because there are too many arguments to `:Man`.) But this is okay,
because if you're typing it anyway then you can just enter underscores
and also tab-completion properly suggests `:Man CREATE_TABLE(7)`.

This is a bit bespoke, but my box has over 9000 man pages (as reported
by `man -k '' | wc -l`), and not one of them has a space in the man page
name, whereas the Postgres manuals do exist and are actually useful.

Test Plan:
On a machine with Postgres manual pages, running

    nvim -u NORC +'exe "norm iCREATE TABLE foo(x int);" | norm 0veeK'

should open the appropriate man page.

wchargin-branch: man-spaces-to-underscores
2021-10-19 07:24:43 -07:00
zeertzjq
29bc648d2b
fix(man.vim): ensure buftype=nofile after :tag or :stag #15675
Problem:
`buftype=help` occasionally propagates from help to man buffer. As a result the
next time you open help it opens in the man window, replacing the manpage.

Test case:
    nvim -u NORC
    :Man man
    :set bt?            " should print `buftype=nofile`
    :help
    <C-W><C-W><C-W>c    " go back to :Man window and close it
    :help               " focus help window
    :Man man            " open window with manpage again
    :set bt?            " prints `buftype=help`

Solution:
- call s:set_options()
    - man#read_page() (called by autocmd BufReadCmd man://*) should already do
      this. But BufReadCmd doesn't fire for already-existing man:// buffers.

Fix #15650
2021-09-16 06:51:26 -07:00
Justin M. Keyes
2548a9e180
fix(man.vim): filetype=man is too eager #15488
Problem:
"set filetype=man" assumes the user wants :Man features, this does extra
stuff like renaming the buffer as "man://".

Solution:
- old entrypoint was ":set filetype=man", but this is too presumptuous #15487
- make the entrypoints more explicit:
  1. when the ":Man" command is run
  2. when a "man://" buffer is opened
- remove the tricky b:man_sect checks in ftplugin/man.vim and syntax/man.vim
- MANPAGER is supported via ":Man!", as documented.

fixes #15487
2021-08-26 02:19:52 -07:00
Jan Edmund Lazo
ecb48e7f8a
fixup! man.vim: Refactor verify_exists to unset $MANSECT as needed
":unset" is not a valid Ex command.
Use setenv() to set/unset environment variables.
2021-04-27 09:21:28 -04:00
最上川
8399f48ca9
man.vim: :Man should not change global value of 'tagfunc' option (#13926) 2021-02-13 11:54:03 -05:00
James McCoy
ad43f789e7
Merge pull request #13439 from shade-of-noon/man-iskeyword
[RDY] man.vim: Set iskeyword explicitly.
2021-01-11 08:07:47 -05:00
Edwin Pujols
e8153ad9c2 man.vim: Set iskeyword explicitly.
This also fixes `:Man!`, which wasn't setting 'iskeyword' to contain
parentheses, etc.
2020-12-04 08:14:40 -04:00
Edwin Pujols
ba2e94d223 runtime: Fix man.vim count handling.
Here I use a negative number to decide whether the count has been
explicitly set. I think it unlikely that negative sections will ever be
created given that negative numbers complicate argument handling:
```
$ man -1 foo
man: invalid option -- '1'
```
and given that there's already precedence for alphanumeric sections like
`3p`, `3x`, `n`, etc.

---

This does work, though:
```
$ man -S -3 baz
```
With `man baz.-3` and `man 'baz(-3)'`, (GNU) man *might* consider `-3`
internally as a section, but in the end reports as if the whole
argument was the name of a topic:
```
$ man 'baz(-3)'
No manual entry for baz(-3)
```

---

Closes #13411.
2020-11-29 19:56:15 -04:00
shade-of-noon
71d4f5851f
man.vim: Use page title instead of full path. (#13353)
In commit 63f0ca3263, `tagfunc` was introduced to
`runtime/autoload/man.vim`. Nonetheless the tag function instead
of using a short buffer name (e.g. `man://foo(3)`) uses the full
path to the man page (e.g. `man:///usr/share/.../foo.3.gz`). This
behaviour is inconsistent with `:Man!`, thus this commit.

Closes #13334
2020-11-24 09:48:06 +01:00
Edwin Pujols
070d7c2950 runtime: Remove error handling for E145.
Restricted mode (-Z) has been removed per #11996.
Some runtime files had lingering error handling (error
identifier `E145`) so I cleaned them up.
2020-11-22 15:46:47 -04:00
Anmol Sethi
a6917f840d
man.vim: Simplify man#init to reduce load time (#12482)
I removed the SunOS stuff since no one uses SunOS and I've never tested
it on there.

I removed the section_flag init as we can just use -S instead of -s
and -S is used by every implementation as far as I know.

This brings man#init's time from 50-70ms to 15-20ms for me.

Closes #12318
Related #6766
Related #6815
2020-07-21 11:46:42 -04:00
Anmol Sethi
adc3425a37
man.vim: Fix tagfunc to respect b:man_default_sects
Also, kudos to @zsugabubus for fixing a related issue in #12417

This also prevents any sorting of the paths from man. We need to
respect the order we get from it otherwise you end up loading

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/share/man/man1/ls.1

on MacOS instead of /usr/share/man/man1/ls.1
2020-06-13 02:55:40 -04:00
Anmol Sethi
4aaffc5f33
man.vim: Refactor verify_exists to unset $MANSECT as needed
Also cleaned it up a little and made it faster.

Closes #9159 and #9271

Also changes man#extract_sect_and_name_ref to only return a single
section at a time. This fixes a bug in its usage in man#goto_tag
where get_paths would be called with multiple sections and it does
not support that.

I noticed that our tagfunc doesn't obey b:man_default_sects and
I'll fix that next.
2020-06-12 23:44:31 -04:00
Rob Pilling
5e0c435ca1 man.vim: Handle man errors when looking for man-paths
Fallback to simply globbing the tag we're given. This matches the
original behaviour of `man.vim`, prior to c6afad78d3.

fixes #11794
closes #11918
2020-02-29 23:44:43 -08:00
Rob Pilling
4a7d84ae60 man.vim: workaround for 'cscopetag' #11679
The old `:Man` implementation would take either the word under
the cursor, or the argument passed in, and load that as a man page.

Since we now use 'tagfunc' and look for all relevant man-pages, if
your system has several (i.e. same name, different sections), we return
several, giving the user an option.

This works for most tag commands except `:tjump`, which will
fail if there's multiple tags to choose from. This just happens to
be what the cscope code uses (it actually attempts to prompt the
user, but this fails).
2020-01-06 21:57:36 -08:00
Rob Pilling
33beeed4d9 man.vim: Improve ft=man 'iskeyword' #11457
This addresses a minor quality problem with the recent `'tagfunc'`
changes for `man.vim` (see [link]).

Currently, with the cursor on a parenthese, hitting `K` will jump us to
the man page of the next mentioned entry, instead of the one to which
the parenthese (or section number) belongs.

```
pcrepattern(3), terminfo(5), glob(7), regex(7).
       e.g. ^        e.g. ^
```

Adding the parentheses to `'iskeyword'` means we correctly handle these cases too.

[link]: https://github.com/neovim/neovim/pull/11280#discussion_r348342357
2019-11-27 21:01:04 -08:00
Justin M. Keyes
544eeeb0d6
Merge #11451 'man.vim: Fixes' 2019-11-24 17:37:47 -08:00
Anmol Sethi
4ce96e4979
man.vim: Hard wrap by default
Closes #11436
2019-11-24 20:31:46 -05:00
Anmol Sethi
526798a941 man.vim: Ensure 'modifiable' in man#init_pager #11450 2019-11-24 17:30:04 -08:00
Justin M. Keyes
525bb1b55d Merge #11280 "man.vim: implement 'tagfunc'" 2019-11-20 00:31:22 -08:00
Rob Pilling
807e4039cb Sort man pages by relevance during goto_tag() 2019-11-13 22:00:11 +00:00
Rob Pilling
18c5f6ab9f Don't attempt swapfiles for man pages
This is because we now use :tag to open a man page, which attempts
to open a swap file for a path under man://...
2019-11-13 21:57:17 +00:00
Rob Pilling
aeee41192b Remove eventignore - :Man now uses :tag to populate the page 2019-11-13 21:56:28 +00:00
Rob Pilling
c6afad78d3 man.vim: remove push_tag and simplify man#open_page 2019-10-29 18:41:30 +00:00
Joshua Rubin
99aa166cb1 man.vim: never switch to non-man window #11286
In order to find if there was already an open man page, the :Man command
would cycle through each window to see if &ft=='man'. This triggers
autocmds, e.g. BufEnter, unnecessarily and can have unexpected
side-effects.

Change the logic to check each window's ft without switching to it
unless it is actually a man window.

Signed-off-by: Joshua Rubin <me@jawa.dev>
2019-10-25 09:41:22 -07:00
Rob Pilling
0173bdf98b man.vim: parse the section from the tag 2019-10-24 22:15:57 +01:00
Rob Pilling
2f0412e61d man.vim: :Man preserves the tag stack 2019-10-24 22:15:57 +01:00
Rob Pilling
63f0ca3263 man.vim: use 'tagfunc' instead of remapping
man#pop_tag() is also no longer used
2019-10-24 21:15:18 +01:00
Rob Pilling
ed72d9597d man.vim: pull out s:get_paths() 2019-10-24 21:15:16 +01:00
Curtis McEnroe
40f5a6c4da man.vim: g:man_hardwrap #9633
This option allows restoring the behaviour prior to #9023.
Fixes #9583
Closes #9633
2019-02-21 00:06:26 +01:00
Justin M. Keyes
112a5b76e6 man.vim: lowercase title when invoked as $MANPAGER
man#init_pager() guesses the ref by the heading, which is usually
uppercase, so we don't know the correct casing. But lowercase is more
common, so use that for the buffer name instead of uppercase.

ref #9156
2018-10-26 02:50:21 +02:00
Justin M. Keyes
c03a0f5fc8 man.vim: avoid duplicate buffers, E95
Before this commit, man#init_pager() always tries to scrape the manpage
name and set the buffer name. That's much less important than avoiding
duplicate buffers and E95. And it doesn't seem to be necessary, usually.

Steps to reproduce:

    $ export MANPAGER="nvim -c 'set ft=man' -"
    $ man sleep
    :Man sleep

    Error detected while processing function man#init_pager:
    line   15:
    E95: Buffer with this name already exists

    :ls!
    1  h-  "man://SLEEP(1)"               line 4
    2 %a-  "man://sleep(1)"               line 1
2018-10-25 04:09:53 +02:00
Justin M. Keyes
3999aa755e man.vim: set $MANWIDTH=999
On some systems, mandoc disallows $MANWIDTH greater than 1000.
E.g. FreeBSD:
b7d613ae8a/contrib/mandoc/manpath.c (L312)

closes #9065
2018-09-30 18:35:19 +02:00
Justin M. Keyes
a1976c7390 man.vim: Start at the top #9023
fixes #9057
2018-09-27 10:08:31 +02:00
Justin M. Keyes
dc256e376d man.vim: Fix very long justified lines #9023
When nroff justifies a line, it fills the line with whitespace to meet
$MANWIDTH.  With $MANWIDTH=9999, that of course results in nonsense (and
behaves poorly with 'cursorline' option).

To work around that, instead of trying to hard-justify the lines, just
replace the mega-whitespace with a fixed size of 10 spaces.

Perhaps N/Vim needs a "soft justify" feature?
2018-09-21 10:17:37 +02:00
Doron Behar
9081cad514 man.vim: Ignore $MANWIDTH, use soft wrap #9023
fix #9017
close #9023
2018-09-21 10:17:37 +02:00
dm1try
71bb4fd481 man.vim: guard against reload (#8940)
Some plugins attempt to reload autoloaded scripts.
Use a guard to prevent this.

fix #8939
2018-09-01 11:42:43 +02:00
Brayden Banks
9afed40ea6 man.vim: fix for mandoc (#8698)
When giving a section, the first candidate selection was not performed.

followup/fixup #8341
2018-07-08 17:31:10 +02:00
Justin M. Keyes
1cd8517344 man.vim: s:get_path(): trim newline in all cases
ref #8372
2018-05-10 16:03:13 +02:00
Jon Bernard
f1a3075553 man.vim: get() first item if -w returns multiple paths #8372
OpenBSD's man returns all candidates when searching with -w instead of
the first one it finds.  So this patch takes the first one if multiple
entries are found.

closes #8372
closes #8341
2018-05-10 14:42:10 +02:00
Marco Hinz
dbcdd29139
man.vim: use correct offset in presence of modifier commands
The argument expansion for :Man depends on the number of arguments given to it
starting at the command itself. But user completion functions always provide the
entire command-line which can include modifier commands like :tab, :vert, etc.
leading to a wrong number of arguments.

Prune all arguments up to :Man.

Fixes #7872.
2018-01-22 17:05:52 +01:00
Justin M. Keyes
59888b68ab Merge #7623 'man.vim: highlight bold, underlined text' 2018-01-09 10:10:22 +01:00
Anmol Sethi
3eaa9a2579 man.vim: always keep the alternate buffer (#7784)
Closes #7772
2017-12-29 19:00:10 +01:00
Gabriel Holodak
eb44519b5d Address PR comments 2017-12-27 23:28:04 -05:00
Gabriel Holodak
6740c94562 Add support for escape sequences 2017-12-27 23:27:14 -05:00
Gabriel Holodak
c28ce5f619 Switch to processing in Lua 2017-12-27 23:27:14 -05:00
Gabriel Holodak
0446d4d691 Highlight backspaced characters 2017-12-27 23:27:14 -05:00
raichoo
967e892cb6 man.vim: feature-test section (-s) flag #6815
Different implementations of `man` might be using different
flags for sections.
2017-05-26 00:30:40 +02:00