-
Notifications
You must be signed in to change notification settings - Fork 69
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
Allow WikiPageRename to move the page to another directory (including creating the directory) #108
Conversation
I also added a proposal how to check whether a target directory exists and produce a controlled error message. If this is what you want then we should revert the second test as success now, and start working on |
From #107:
I fully agree that we should improve this.
I think a solution could be something like this:
Essentially, I think asking the user should be an OK way to handle it that should make the |
Since you are already working on this in your fork I'll not work on it myself yet. But I'll be glad both to help you with the PR and also, if you prefer, to finalize the implementation. |
Thanks, I'll finish this. Just not sure when. It may take 2-3 days. |
Great. And, as you also said in #107: no rush. :) |
Sorry for being quiet here. I am completely swamped, but I have not forgotten this. It just needs to wait a bit! |
I know how it can be, no worries :) |
I wouldn't say this is done @lervag but I think you should have a look at this as I am ending in difficulties that show my lack of understanding of wiki.vim invariants. I think I (mostly) did what you suggested. I ask for the permission to create a new dir (in the 'ask' function) and then the non-interactive function should just succeed. Still when testing I am arriving at many small problems that I am not sure if they are directly related to the patch, or whether they are problems overall that need to be looked at separately:
In general I struggle with the 'cwd-invariant' - vim has a working directory active in the buffer we are renaming. This could be anything (in my tests it was often outside the wiki tree!). Typically vim file operations work with respect to the CWD, but here I would prefer to give path with respect to the position of the wiki file open, or with respect to the wiki root. Only the former works now. Perhaps I should implement a detection if someone starts with a slash? (or is there any machinery in place?) As you see these are many questions. I think it would be best to address those that you consider bugs in this specific functionality (creating a dir) and separate the others into their own issues, to make it easier to work with in small chunks. Comments? |
I think this actually looks good. I'm looking into it now if it might be merged already.
These looks unrelated to your patch, so I would be happy to look into them as one or more separate issues. Perhaps you could raise both of them? It would be useful with a simple example of how to observce each of them. You don't need many words for this, really, just the simple description and an example.
This is not caused by
My "philosophy" is to always work with absolute paths, because I can never assume anything about how a user "operates". I personally like to avoid keeping a distinct CWD for Vim. That is, I prefer to let CWD always be the same as the current file ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code to check if the new directory exists is only applied for rename_ask
: I'm curious if it would be better to move this code to rename()
and add an extra option: e.g. ask_for_mkdir
. If true, we ask before mkdir
, else we run mkdir
without asking. Or something like that.
Else I think this looks good now.
autoload/wiki/page.vim
Outdated
@@ -95,7 +95,7 @@ function! wiki#page#rename(newname) abort "{{{1 | |||
for l:bufname in l:bufs | |||
execute 'buffer' fnameescape(l:bufname) | |||
update | |||
execute 'bwipeout' fnameescape(l:bufname) | |||
execute 'bwipeout' fnameescape(l:bufname) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for this change?
autoload/wiki/page.vim
Outdated
@@ -125,6 +125,19 @@ function! wiki#page#rename_ask() abort "{{{1 | |||
redraw! | |||
echo 'Enter new name (without extension):' | |||
let l:name = input('> ') | |||
|
|||
" Check if directory exists | |||
let l:newpath = printf('%s/%s', expand('%:h'), l:name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should use expand('%:p:h')
to ensure you are using an absolute path. I would also move the simplify
from line 131 to 130. I would also consider to combine lines 130 and 131, since l:newpath
is not used any further. E.g.:
let l:target_dir = fnamemodify(
\ simplify(printf('%s/%s', expand('%:h'), l:name)), ':h')
Finally, note that the expand()
on line 131 is not necessary.
autoload/wiki/page.vim
Outdated
redraw! | ||
echo "Directory '" . l:target_dir . "' does not exist. " | ||
if input("Create [Y]es/[n]o ? ", "Y") !=? "y" | ||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use two spaces per indent :)
hmm. I can of course do this. No problem. However, I thought that it was quite neat to separate a function that is interactive from the function that is non-interactive. Perhaps I have misread the original design intention (between Also when renaming the page with the current patch, the path for the new file is interpreted from the position of the renamed page (relative to the renamed page). I think this is fine, but just wanted to make it clear, since you stated your 'absolute path' policy. I have addressed the other minor issues, and will look into opening separate entries for the buffer problems now (done, issue #124). |
Yes, I can see what you mean. However, I'm thinking the original function should also handle the missing directories. So, as a minimum, it should raise an error or something if the target directory does not exist. My suggested solution was to move the interactive handling of a missing directory to the main function and to add an argument to avoid the interactivity. I'm thinking: If we want to change a filename and possibly move it to a different directory, then the function needs to account for this problem. If we don't explicitly say how to solve it, then we should ask. Perhaps the argument should be mandatory and be one of
Yes, good point. I think this is fine. My point about absolute paths was mainly that I try and always work with paths as absolute paths in the code. Not necessarily from the user perspective.
Great! Let's merge this before working with #124, ok? |
3f526ea
to
373cda0
Compare
Moved the directory creation code to |
Thanks! I've merged and made some minor adjustments. |
These are two tests that demonstrate how WikiPageRename works for moving pages around. It succeeds if target dir exists and fails if target dir does not exist. These tests are supporting discussion in issue #107