[Github-comments] Re: [geany/geany-plugins] Vimode: Added folding support (PR #1327)

2024-05-24 Thread cresto sylvain via Github-comments
Sorry, I made a mistake and this closed this pull request...

I just created a new pull request 
[#1350](https://github.com/geany/geany-plugins/pull/1350)  with all these 
changes.. sorry!

-- 
Reply to this email directly or view it on GitHub:
https://github.com/geany/geany-plugins/pull/1327#issuecomment-2129190321
You are receiving this because you are subscribed to this thread.

Message ID: 

[Github-comments] Re: [geany/geany-plugins] Vimode: Added folding support (PR #1327)

2024-05-23 Thread Jiří Techet via Github-comments
@scresto09 You seem to have pushed an unmodified branch and the pull request 
closed as a result. There are no commits in this pull request now.

-- 
Reply to this email directly or view it on GitHub:
https://github.com/geany/geany-plugins/pull/1327#issuecomment-2127082048
You are receiving this because you are subscribed to this thread.

Message ID: 

[Github-comments] Re: [geany/geany-plugins] Vimode: Added folding support (PR #1327)

2024-05-23 Thread cresto sylvain via Github-comments
Closed #1327.

-- 
Reply to this email directly or view it on GitHub:
https://github.com/geany/geany-plugins/pull/1327#event-12908283439
You are receiving this because you are subscribed to this thread.

Message ID: 

[Github-comments] Re: [geany/geany-plugins] Vimode: Added folding support (PR #1327)

2024-05-23 Thread cresto sylvain via Github-comments
@scresto09 pushed 0 commits.


-- 
View it on GitHub:
https://github.com/geany/geany-plugins/pull/1327/files/e0252c96bc17c21d1f9723cfa8e89fbb021644ad..0e299a898165cedfc8010d1ae43fa14a0c9f8e00
You are receiving this because you are subscribed to this thread.

Message ID: 


[Github-comments] Re: [geany/geany-plugins] Vimode: Added folding support (PR #1327)

2024-05-23 Thread cresto sylvain via Github-comments
@scresto09 pushed 1 commit.

e0252c96bc17c21d1f9723cfa8e89fbb021644ad  Vimode: constants and functions 
renamed and README completed

-- 
View it on GitHub:
https://github.com/geany/geany-plugins/pull/1327/files/c902da4df5df85fcbcb2bd6a2d8048480635ebc7..e0252c96bc17c21d1f9723cfa8e89fbb021644ad
You are receiving this because you are subscribed to this thread.

Message ID: 


[Github-comments] Re: [geany/geany-plugins] Vimode: Added folding support (PR #1327)

2024-05-22 Thread Jiří Techet via Github-comments
One more thing, the README file contains all the supported vi commands - would 
you copy the added commands from `index.txt` in the vimode directory into 
README?

-- 
Reply to this email directly or view it on GitHub:
https://github.com/geany/geany-plugins/pull/1327#issuecomment-2125868073
You are receiving this because you are subscribed to this thread.

Message ID: 

[Github-comments] Re: [geany/geany-plugins] Vimode: Added folding support (PR #1327)

2024-05-22 Thread Jiří Techet via Github-comments
@techee requested changes on this pull request.

I think it looks good functionality-wise, I have just suggested to rename some 
things to make them clearer (at least to me).

> I was unable to reproduce the issue you are talking about with commit 
> https://github.com/geany/geany-plugins/commit/33984abc9bd24bbf03db3ac517eb45ca2c7e6b7f,
>  let me know if the issue persists.

When you call `prepare_fold()` the cursor is moved above it so you don't see 
it. But you can reproduce it with `cmd_close_fold_all()` which currently 
doesn't call `prepare_fold()` (but it should) and it doesn't collapse the fold 
where the cursor is placed - see the comment below.

It would be best if you rebased this PR on top of current geany-plugins master 
as there's a merge conflict in the Makefile.

> + * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 
USA.
+ */
+
+#include "cmds/fold.h"
+#include "utils.h"
+
+/* fold command does not depend on state of parents */
+#define FOLD_NONE  0
+/* fold command depend on state of parents */
+#define FOLD_PARENT1
+/* fold command depend on state of contracted parent if it exists */
+#define FOLD_CONTRACTED2

I was super-confused by the naming. I's suggest the following:
* `FOLD_NONE` -> `GOTO_NEAREST_PARENT`
* `FOLD_PARENT` -> `GOTO_TOPMOST_PARENT`
* `FOLD_CONTRACTED` -> `GOTO_CONTRACTED_PARENT`

plus the corresponding  comment changes.

> + * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 
USA.
+ */
+
+#include "cmds/fold.h"
+#include "utils.h"
+
+/* fold command does not depend on state of parents */
+#define FOLD_NONE  0
+/* fold command depend on state of parents */
+#define FOLD_PARENT1
+/* fold command depend on state of contracted parent if it exists */
+#define FOLD_CONTRACTED2
+
+static gint prepare_fold(CmdParams *p, gint filter)

Rename to `goto_above_fold()` and the `filter` parameter to `type`.

> +void cmd_close_fold_child(CmdContext *c, CmdParams *p)
+{
+   gint line = prepare_fold(p, FOLD_PARENT);
+   if (line != -1)
+   SSM(p->sci, SCI_FOLDCHILDREN, (uptr_t) line, 
SC_FOLDACTION_CONTRACT);
+}
+
+
+void cmd_open_fold_all(CmdContext *c, CmdParams *p)
+{
+   SSM(p->sci, SCI_FOLDALL, SC_FOLDACTION_EXPAND | 
SC_FOLDACTION_CONTRACT_EVERY_LEVEL, 0);
+}
+
+
+void cmd_close_fold_all(CmdContext *c, CmdParams *p)
+{

This will need `goto_above_fold(p, GOTO_TOPMOST_PARENT);` otherwise the fold 
where the cursor is won't get contracted because of what I mentioned before.

> + ;   /* this fold point is contracted and filter == 
> FOLD_CONTRACTED */
+   else if (filter != FOLD_NONE)
+   {
+   gint prev_line = line;
+   while (prev_line != -1)
+   {
+   prev_line = SSM(p->sci, SCI_GETFOLDPARENT, prev_line, 
0);
+   if (prev_line != -1)
+   {
+   line = prev_line;
+   if (filter == FOLD_CONTRACTED && ! SSM(p->sci, 
SCI_GETFOLDEXPANDED, line, 0))
+   break;
+   }
+   }
+   }
+

Remove extra empty line.

-- 
Reply to this email directly or view it on GitHub:
https://github.com/geany/geany-plugins/pull/1327#pullrequestreview-2072149642
You are receiving this because you are subscribed to this thread.

Message ID: 

[Github-comments] Re: [geany/geany-plugins] Vimode: Added folding support (PR #1327)

2024-05-22 Thread cresto sylvain via Github-comments
OK, I tried to make some changes to improve fold support and react more like 
vim.
With za/zo/zc we fold the current block as before.
With zA we change the fold depending on the state of the parent, if there is 
one that is contracted we expand it otherwise we contract it.
I was unable to reproduce the issue you are talking about with commit 33984ab, 
let me know if the issue persists.
And another thing, sorry but I'm not sure I did the right things with 
git/merge, let me know if I need to fix anything on this.
Thanks.

-- 
Reply to this email directly or view it on GitHub:
https://github.com/geany/geany-plugins/pull/1327#issuecomment-2124375531
You are receiving this because you are subscribed to this thread.

Message ID: 

[Github-comments] Re: [geany/geany-plugins] Vimode: Added folding support (PR #1327)

2024-05-22 Thread cresto sylvain via Github-comments
@scresto09 pushed 3 commits.

c5e4c30b9a8e2eef9bbc6a7ba9c3516e1b6b33a3  Move fold functions to fold.c/fold.h 
files
c9e04135595b28fc2390d156b9686621b2d6dd24  Merge branch 'vimode-fold-support' of 
https://github.com/scresto09/geany-plugins into vimode-fold-support
c902da4df5df85fcbcb2bd6a2d8048480635ebc7  vimode: try to improve fold support

-- 
View it on GitHub:
https://github.com/geany/geany-plugins/pull/1327/files/904ee74be16f74c9cd0173353c224497c87b861e..c902da4df5df85fcbcb2bd6a2d8048480635ebc7
You are receiving this because you are subscribed to this thread.

Message ID: 


[Github-comments] Re: [geany/geany-plugins] Vimode: Added folding support (PR #1327)

2024-05-22 Thread cresto sylvain via Github-comments
@scresto09 pushed 1 commit.

904ee74be16f74c9cd0173353c224497c87b861e  Merge branch 'geany:master' into 
vimode-fold-support

-- 
View it on GitHub:
https://github.com/geany/geany-plugins/pull/1327/files/cd00fbc84dc0480e6a7b9e3c8a934225057fc051..904ee74be16f74c9cd0173353c224497c87b861e
You are receiving this because you are subscribed to this thread.

Message ID: 


[Github-comments] Re: [geany/geany-plugins] Vimode: Added folding support (PR #1327)

2024-05-21 Thread Jiří Techet via Github-comments
If you are planning to continue working on this PR, there's one catch. Because 
of

https://github.com/geany/geany-plugins/commit/33984abc9bd24bbf03db3ac517eb45ca2c7e6b7f

you have to first move the cursor on the visible line before performing a fold 
- otherwise folding won't work because the above code will expand the fold (I 
experienced this problem myself when testing the code above and it took me a 
while to realize what was going on).

-- 
Reply to this email directly or view it on GitHub:
https://github.com/geany/geany-plugins/pull/1327#issuecomment-2123521903
You are receiving this because you are subscribed to this thread.

Message ID: 

[Github-comments] Re: [geany/geany-plugins] Vimode: Added folding support (PR #1327)

2024-04-25 Thread Jiří Techet via Github-comments
Looks good in general, but I think folding should work when the cursor is 
anywhere in the block, not just on the fold point (vim seems to work this way). 
I played with it a little and came up with something like this:
```C
static gint prepare_fold(CmdParams *p)
{
/* foldparent of the next line */
gint line = SSM(p->sci, SCI_GETFOLDPARENT, p->line + 1, 0);

if (p->line == line)
;  /* we are already on the fold point line */
else
{
/* foldparent of the current line */
line = SSM(p->sci, SCI_GETFOLDPARENT, p->line, 0);
}

if (line != -1)
{
/* move the cursor on the visible line before the fold */
gint pos = SSM(p->sci, SCI_POSITIONFROMLINE, line, 0);
SET_POS_NOX(p->sci, pos, TRUE);
}

return line;
}


void cmd_toggle_fold(CmdContext *c, CmdParams *p)
{
gint line = prepare_fold(p);
if (line != -1)
SSM(p->sci, SCI_FOLDLINE, (uptr_t) line, SC_FOLDACTION_TOGGLE);
}
```

If the code looks OK to you and works as expected, could you update all the 
folding functions similarly to `cmd_toggle_fold()` above?

In addition, these aren't exactly "edit" commands and should be placed in a 
separate file. Could you create `fold.c/h`, add them to `Makefile.am` and move 
all these commands there?

-- 
Reply to this email directly or view it on GitHub:
https://github.com/geany/geany-plugins/pull/1327#issuecomment-2077794940
You are receiving this because you are subscribed to this thread.

Message ID: