Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Which strategy to open several (non-contiguous) files at once? #76

Closed
lifepillar opened this issue Feb 20, 2017 · 17 comments
Closed

Which strategy to open several (non-contiguous) files at once? #76

lifepillar opened this issue Feb 20, 2017 · 17 comments

Comments

@lifepillar
Copy link
Contributor

The main reason (I believe) why netrw uses mf/me to open several files at once is that it allows you to act on non-contiguous files (even in different directories if I remember well). This is something that from time to time I miss in Dirvish.

What do you think is the best way to achieve that? Using the location list, arglist, or something else? Any plan to include a similar feature in Dirvish?

@justinmk
Copy link
Owner

justinmk commented Feb 20, 2017

Do you really mean open several files at once? Why "batch" that? Just mash a or i- as needed. (Todo: Need to fix p so that it keeps focus, then you can send many buffers to a single window).

For deleting or renaming multiple non-contiguous buffers, I'd probably just select the entire dirvish buffer, :Shdo, then use :g to filer out what I don't want.

Alternatively, the readme suggests :.caddb (or :.laddb), though I haven't developed anything for this yet. The workflow could be something like:

:lexpr []
:.laddb
:lopen
:Shdo  " need to enhance :Shdo to remove the `||` noise from the location list

That obviously would need some mappings to make it nicer. I'd like to have that built-in but haven't thought about it much. I am wondering how others use the location list and whether anyone has a workflow for this already.

@lifepillar
Copy link
Contributor Author

Maybe “edit” would be more accurate, i.e., add to the buffer list.

I've played a bit with your idea. This works nicely for me:

:set errorformat=%f
:lexpr []
:.laddb
:lfdo edit

It's sufficiently simple to define some mappings to streamline this workflow. One problem to make something like this into Dirvish is that the user may be using the location list for something else in the current window, so to make it robust one should probably use :lolder and :lnewer somewhere. Also, errorformat should be set locally.

Using the argument list may be a more natural choice for this task, since its purpose is to work with paths. You may also have window-local arglists (with :arglocal). But I am less familiar with arglists than with location lists, so I may be missing something.

@bounceme
Copy link
Contributor

bounceme commented Apr 20, 2017

here is what i came up with for a similar idea (opening all files in qf list). it works around a few things and is a ~fast method. it actually visits each file and makes a buffer (though it is deleted/hidden in my script

https://gist.github.com/bounceme/72aa91b4f2a473818d93384b7fff3bd4

i could imagine the filter concept to work with 'marking' files for actions

@justinmk
Copy link
Owner

justinmk commented Apr 20, 2017

As @lifepillar noted, doesn't the args list make the most sense?

@bounceme
Copy link
Contributor

i guess someone could just :next multiple files. that would bypass the qflist. i never use the argslist though, the n files remaining, you can't quit messages are annoying

justinmk added a commit that referenced this issue May 26, 2017
@justinmk
Copy link
Owner

e3c9a2c adds experimental support for the arglist.

  • Use . in normal or visual mode to add files to the arglist.
  • da. starts a new window-local arglist.
  • Add ! to :Shdo to use the arglist when generating the shell script.

Not totally happy with the mappings, I might swap x and ..

arglist is pretty awkward, managing "global" vs "local", dealing with window inheritance, etc....

@lifepillar
Copy link
Contributor Author

In my limited testing, it works beautifully! Just a minor remark: when a file is added to the arglist, it is highlighted (nice!). It seems, however, that only the file name is used, not the path. As a consequence, if you move into a different directory which contains a file with the same name, it is also highlighted. For instance, move into dirvish/autoload, press . to add dirvish.vim to the arglist, then move into dirvish/plugin or dirvish/syntax.

As for the mappings, why not use v to open a file in a vertical split, and reserve a for adding to the arglist? Does character visual mode have any plausible use in a Dirvish buffer?

@justinmk
Copy link
Owner

justinmk commented May 27, 2017

@lifepillar Thanks for the feedback.

It seems, however, that only the file name is used, not the path. As a consequence, if you move into a different directory which contains a file with the same name, it is also highlighted

This is a known issue. Including the path "head" would fix it, but I couldn't get it to work with the existing "conceal". I gave up since I wanted to see if anyone actually uses this feature first. Help welcome if anyone is a Vim syntax adept.

As for the mappings, why not use v to open a file in a vertical split, and reserve a for adding to the arglist? Does character visual mode have any plausible use in a Dirvish buffer?

Visual mode is used to operate on multiple files, v is easier to type than V and behaves the same. Also a has harmony with i and o. I'd rather use x for marking files.

@lifepillar
Copy link
Contributor Author

This is a known issue. Including the path "head" would fix it, but I couldn't get it to work with the existing "conceal".

Have you considered using matchadd() instead?

@justinmk
Copy link
Owner

justinmk commented May 27, 2017

Yes, but matchadd() is a big pain in the ass for other reasons. It must be carefully managed when buffers are switched, etc. That was actually the first thing I tried.

syn match is the "right" way, and it generally works better, just some syntax expert needs to figure out the correct contains magic to make it work with the other syntax groups.

@lifepillar
Copy link
Contributor Author

syn match is the "right" way, and it generally works better

Ok. I have just noted that you use \V in DirvishArg. According to :h syn-pattern, syntax patterns are always interpreted as if 'magic' is on, so \V in that context is probably ignored.

@lifepillar
Copy link
Contributor Author

Btw, how about using an invisible character, like a leading or trailing space, to distinguish marked paths? Then, matching them becomes a breeze and you do not need to dynamically update the syntax items.

@justinmk
Copy link
Owner

justinmk commented May 27, 2017

According to :h syn-pattern, syntax patterns are always interpreted as if 'magic' is on,

Thanks, that explains a few things.

Btw, how about using an invisible character,

That would break the dirvish concept of "the buffer is just a list of paths". And, paths may contain spaces... :/

@lifepillar
Copy link
Contributor Author

lifepillar commented Jul 11, 2017

Matching a full path is also a PITA. How about using signs (:h signs) instead of highlighting? Signs are buffer-specific, and each sign has a unique id that Dirvish can easily map to a path. CtrlP does that, for example.

The drawback is that modifying a Dirvish buffer might invalidate the (visual) correspondence between signs and paths. But that is easily solved by enforcing a simple rule: make the buffer unmodifiable when there are marked paths, and make the buffer modifiable again when the user clears all the signs. With some more work, one might also redraw the signs when the buffer changes.

@bounceme
Copy link
Contributor

are dirvish buffers reused (so going to different folders just updates the buffer)? and i guess matching a full path is possible, i actually think i was trying stuff like this before but with /? searches (didn't work well). Patterns will get really large though with multiple paths/dirs

@justinmk
Copy link
Owner

How about using signs (:h signs) instead of highlighting?

I don't have the patience to deal with the signs API, I'd rather fix the syntax approach.

are dirvish buffers reused (so going to different folders just updates the buffer)?

No. Each dirvish buffer maps one-to-one with a directory, just like any other file.

@justinmk
Copy link
Owner

justinmk commented Jan 7, 2018

This is addressed by x and :Shdo!.

The cosmetic/usability bug mentioned in #76 (comment) is still an issue. Fixed in #123 .

@justinmk justinmk closed this as completed Jan 7, 2018
lifepillar added a commit to lifepillar/vim-dirvish that referenced this issue Jun 12, 2018
This commit addresses justinmk#76
and more specifically, this comment: justinmk#76 (comment).
It likely needs some cleanup, but it basically works.

A few notes:

- Syntax rules for DirvishFullPath and DirvishArg must follow the other
  rules, otherwise they may be overriden (see :h syn-priority).
- I am not sure whether \v has any effect in syntax rule, as the manual
  says that syntax patterns are always magic (:h syn-pattern).
- map() has been replaced by a for loop: this way the code is cleaner
  (IMO) and the resulting syntax rules shorter.
- I am not sure what the place for the condition testing for
  b:current_syntax is. That might need to be changed.
justinmk pushed a commit that referenced this issue Nov 15, 2018
Define DirvishArgFullPath syntax group which "contains" DirvishPathHead,
DirvishArg.

ref #76
ref #76 (comment)
close #123

- Also escape() the "@" symbol.
- map() has been replaced by a for loop: the code is cleaner (IMO) and
  the resulting syntax rules shorter.
- I am not sure what the place for the condition testing for
  b:current_syntax is. That might need to be changed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants