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

Handle the offset for the end of a three-piece comment ignored #2

Open
GoogleCodeExporter opened this issue Aug 18, 2015 · 14 comments
Open

Comments

@GoogleCodeExporter
Copy link

:help format-comments mentions that it is possible to specify an offset for the 
end of a three-piece comment:

  {digits}
    When together with 's' or 'e': add {digit} amount of offset to an
    automatically inserted middle or end comment leader. The offset begins
    from a left alignment. See below for more details.

  -{digits}
    Like {digits} but reduce the indent.  This only works when there is
    some indent for the start or end part that can be removed.




This seems to have never been implemented. If you are interested in 
implementing the feature, I made a small first step: I modified insertchar() in 
edit.c so that the closing part is correctly indented (with the offset) when 
the auto-close comment functionality is triggered but:
• my solution uses spaces – it does not take into account the value of
  'et', 'ts', etc.,
• get_c_indent() does not handle the offset setting.

If you decide to implement this, at least the settings mentioned above will 
have to be considered (perhaps other as well).

You might have a look at the attached patch (against Vim 7.3.189) if you'd like 
a pointer to where to start. Also have a look at open_line().

Original issue reported on code.google.com by lech.lor...@gmail.com on 15 May 2011 at 10:34

Attachments:

@GoogleCodeExporter
Copy link
Author

Original comment by chrisbr...@googlemail.com on 9 Jan 2015 at 12:09

  • Added labels: patch

zdohnal referenced this issue in zdohnal/vim Feb 6, 2017
@ckyoog
Copy link

ckyoog commented Apr 19, 2022

I appear to run into this issue. :set comments=sr:/***,m:**,ex-2:******/, an example from vim's own help, doesn't work as the help shows what it is supposed to do. Wondering if this issue is fixed and just not closed? or it is still there.

@chrisbra
Copy link
Member

I had to search the help to find this. It appears to be at :h format-comments and scroll down by a page.

However, as you say, this doesn't seem to work as documented, so this issue shouldn't be closed I guess?

@chrisbra
Copy link
Member

Oh wait, I was just testing using vim --clean -c ':set comments=sr:/***,m:**,ex-2:******/' foobar.c (tested with a C file so that indenting and formatting options are set from the filetype plugin)

And it seems to work as expected. So perhaps we can actually close this?

@ckyoog
Copy link

ckyoog commented Apr 19, 2022

Sad, it doesn't work for me with your command.

Some other thoughts. Even we can prove it is fixed. I still think it is an issue. This thing, the offset for the end comment string, is pretty tricky. I don't think the --clean is an option for daily use. Does it mean it will hardly work once user applies any personal config? If it is true, if it doesn't work for most of times, then what's the point of this thing to exist?

@chrisbra
Copy link
Member

no --clean is simply there to reproduce this with minimal vimrc settings. To allow us to track down problems, rule out custom vimrc settings and write easier tests.

@ckyoog
Copy link

ckyoog commented Apr 19, 2022

Yes, I know what the --clean does. What I am saying is, apparently, you got different results, with and without the --clean. We might not be good just because it works with --clean option. We wants it to work without --clean option.

@chrisbra
Copy link
Member

chrisbra commented Apr 20, 2022

yes, it may depend on the what other files are sourced. You did not mention what version of vim you used. Perhaps it did not source those filetype plugins for c files? Check the output of :scriptnames that could make a difference

@ckyoog
Copy link

ckyoog commented Apr 20, 2022

I tried your command one more time on three different distributions, in case that different distro has different default config for vim. None worked.

Here are their version info and the result of :scriptnames

$ vim --version
VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Oct 12 2021 05:55:28)
Included patches: 1-3428
Modified by Gentoo-8.2.3428-r1
Compiled by ...@localhost
Huge version without GUI.  Features included (+) or not (-):
+acl               +file_in_path      +mouse_urxvt       -tag_any_white
+arabic            +find_in_path      +mouse_xterm       -tcl
+autocmd           +float             +multi_byte        +termguicolors
+autochdir         +folding           +multi_lang        +terminal
-autoservername    -footer            -mzscheme          +terminfo
-balloon_eval      +fork()            +netbeans_intg     +termresponse
+balloon_eval_term +gettext           +num64             +textobjects
-browse            -hangul_input      +packages          +textprop
++builtin_terms    +iconv             +path_extra        +timers
+byte_offset       +insert_expand     -perl              +title
+channel           +ipv6              +persistent_undo   -toolbar
+cindent           +job               +popupwin          +user_commands
-clientserver      +jumplist          +postscript        +vartabs
-clipboard         +keymap            +printer           +vertsplit
+cmdline_compl     +lambda            +profile           +virtualedit
+cmdline_hist      +langmap           -python            +visual
+cmdline_info      +libcall           -python3           +visualextra
+comments          +linebreak         +quickfix          +viminfo
+conceal           +lispindent        +reltime           +vreplace
+cryptv            +listcmds          +rightleft         +wildignore
+cscope            +localmap          -ruby              +wildmenu
+cursorbind        +lua               +scrollbind        +windows
+cursorshape       +menu              +signs             +writebackup
+dialog_con        +mksession         +smartindent       -X11
+diff              +modify_fname      +sodium            -xfontset
+digraphs          +mouse             -sound             -xim
-dnd               -mouseshape        +spell             -xpm
-ebcdic            +mouse_dec         +startuptime       -xsmp
+emacs_tags        +mouse_gpm         +statusline        -xterm_clipboard
+eval              -mouse_jsbterm     -sun_workshop      -xterm_save
+ex_extra          +mouse_netterm     +syntax
+extra_search      +mouse_sgr         +tag_binary
-farsi             -mouse_sysmouse    -tag_old_static
   system vimrc file: "/etc/vim/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
       defaults file: "$VIMRUNTIME/defaults.vim"
  fall-back for $VIM: "/usr/share/vim"
Compilation: x86_64-pc-linux-gnu-gcc -c -I. -Iproto -DHAVE_CONFIG_H -march=core2 -msse3 -mfpmath=sse -O2 -pipe -D_REENTRANT -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
Linking: x86_64-pc-linux-gnu-gcc -Wl,-O1 -Wl,--as-needed -L/usr/local/lib -o vim -lm -ltinfo -lelf -lsodium -lacl -lattr -lgpm -ldl -L/usr/lib -llua5.1

$ vim --clean a.c
:scriptnames
  1: /usr/share/vim/vim82/defaults.vim
  2: /usr/share/vim/vim82/filetype.vim
  3: /usr/share/vim/vimfiles/ftdetect/cmake.vim
  4: /usr/share/vim/vimfiles/ftdetect/gentoo.vim
  5: /usr/share/vim/vimfiles/ftdetect/llvm-lit.vim
  6: /usr/share/vim/vimfiles/ftdetect/llvm.vim
  7: /usr/share/vim/vimfiles/ftdetect/meson.vim
  8: /usr/share/vim/vimfiles/ftdetect/mir.vim
  9: /usr/share/vim/vimfiles/ftdetect/proto.vim
 10: /usr/share/vim/vimfiles/ftdetect/tablegen.vim
 11: /usr/share/vim/vimfiles/ftdetect/udev.vim
 12: /usr/share/vim/vim82/ftplugin.vim
 13: /usr/share/vim/vim82/indent.vim
 14: /usr/share/vim/vim82/syntax/syntax.vim
 15: /usr/share/vim/vim82/syntax/synload.vim
 16: /usr/share/vim/vim82/syntax/syncolor.vim
 17: /usr/share/vim/vim82/autoload/dist/ft.vim
 18: /usr/share/vim/vim82/ftplugin/c.vim
 19: /usr/share/vim/vimfiles/after/ftplugin/c.vim
 20: /usr/share/vim/vimfiles/autoload/omni/cpp/complete.vim
 21: /usr/share/vim/vimfiles/autoload/omni/cpp/settings.vim
 22: /usr/share/vim/vim82/indent/c.vim
 23: /usr/share/vim/vim82/syntax/c.vim
 24: /usr/share/vim/vimfiles/after/syntax/c.vim
 25: /usr/share/vim/vimfiles/syntax/atk.vim
 26: /usr/share/vim/vimfiles/syntax/atspi.vim
 27: /usr/share/vim/vimfiles/syntax/cairo.vim
 28: /usr/share/vim/vimfiles/syntax/clutter.vim
 29: /usr/share/vim/vimfiles/syntax/colord.vim
 30: /usr/share/vim/vimfiles/syntax/dbusglib.vim
 31: /usr/share/vim/vimfiles/syntax/evince.vim
 32: /usr/share/vim/vimfiles/syntax/fftw3.vim
 33: /usr/share/vim/vimfiles/syntax/gdkpixbuf.vim
 34: /usr/share/vim/vimfiles/syntax/gimp.vim
 35: /usr/share/vim/vimfiles/syntax/glib.vim
 36: /usr/share/vim/vimfiles/syntax/gnomedesktop.vim
 37: /usr/share/vim/vimfiles/syntax/gobjectintrospection.vim
 38: /usr/share/vim/vimfiles/syntax/gstreamer.vim
 39: /usr/share/vim/vimfiles/syntax/gtk2.vim
 40: /usr/share/vim/vimfiles/syntax/gtk3.vim
 41: /usr/share/vim/vimfiles/syntax/gtkglext.vim
 42: /usr/share/vim/vimfiles/syntax/gtksourceview.vim
 43: /usr/share/vim/vimfiles/syntax/gudev.vim
 44: /usr/share/vim/vimfiles/syntax/gusb.vim
 45: /usr/share/vim/vimfiles/syntax/jsonglib.vim
 46: /usr/share/vim/vimfiles/syntax/libgsf.vim
 47: /usr/share/vim/vimfiles/syntax/libnotify.vim
 48: /usr/share/vim/vimfiles/syntax/librsvg.vim
 49: /usr/share/vim/vimfiles/syntax/libsoup.vim
 50: /usr/share/vim/vimfiles/syntax/libunique.vim
 51: /usr/share/vim/vimfiles/syntax/libwnck.vim
 52: /usr/share/vim/vimfiles/syntax/pango.vim
 53: /usr/share/vim/vimfiles/syntax/poppler.vim
 54: /usr/share/vim/vimfiles/syntax/vte.vim
 55: /usr/share/vim/vimfiles/syntax/xlib.vim
# vim --version
VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Apr 08 2022 07:37:41)
Included patches: 1-4708
Compiled by Alpine Linux
Huge version without GUI.  Features included (+) or not (-):
+acl               +file_in_path      +mouse_urxvt       -tag_any_white
+arabic            +find_in_path      +mouse_xterm       -tcl
+autocmd           +float             +multi_byte        +termguicolors
+autochdir         +folding           +multi_lang        +terminal
-autoservername    -footer            -mzscheme          +terminfo
-balloon_eval      +fork()            +netbeans_intg     +termresponse
+balloon_eval_term -gettext           +num64             +textobjects
-browse            -hangul_input      +packages          +textprop
++builtin_terms    +iconv             +path_extra        +timers
+byte_offset       +insert_expand     -perl              +title
+channel           +ipv6              +persistent_undo   -toolbar
+cindent           +job               +popupwin          +user_commands
-clientserver      +jumplist          +postscript        +vartabs
-clipboard         +keymap            +printer           +vertsplit
+cmdline_compl     +lambda            +profile           +vim9script
+cmdline_hist      +langmap           -python            +viminfo
+cmdline_info      +libcall           +python3/dyn       +virtualedit
+comments          +linebreak         +quickfix          +visual
+conceal           +lispindent        +reltime           +visualextra
+cryptv            +listcmds          +rightleft         +vreplace
+cscope            +localmap          -ruby              +wildignore
+cursorbind        +lua               +scrollbind        +wildmenu
+cursorshape       +menu              +signs             +windows
+dialog_con        +mksession         +smartindent       +writebackup
+diff              +modify_fname      -sodium            -X11
+digraphs          +mouse             -sound             -xfontset
-dnd               -mouseshape        +spell             -xim
-ebcdic            +mouse_dec         +startuptime       -xpm
+emacs_tags        -mouse_gpm         +statusline        -xsmp
+eval              -mouse_jsbterm     -sun_workshop      -xterm_clipboard
+ex_extra          +mouse_netterm     +syntax            -xterm_save
+extra_search      +mouse_sgr         +tag_binary
-farsi             -mouse_sysmouse    -tag_old_static
   system vimrc file: "/etc/vim/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
       defaults file: "$VIMRUNTIME/defaults.vim"
  fall-back for $VIM: "/usr/share/vim"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H -Os -fomit-frame-pointer -Os -fomit-frame-pointer -D_REENTRANT -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
Linking: gcc -L/usr/local/lib -Wl,--as-needed -o vim -lm -lncurses -L/usr/lua5.3/lib -llua

# vim --clean a.c
:scriptnames
  1: /usr/share/vim/vim82/defaults.vim
  2: /usr/share/vim/vim82/filetype.vim
  3: /usr/share/vim/vim82/ftplugin.vim
  4: /usr/share/vim/vim82/indent.vim
  5: /usr/share/vim/vim82/autoload/dist/ft.vim
  6: /usr/share/vim/vim82/ftplugin/c.vim
  7: /usr/share/vim/vim82/indent/c.vim
$ vim --version
VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Dec 25 2021 11:17:40)
Included patches: 1-3890
Compiled by Arch Linux
Huge version without GUI.  Features included (+) or not (-):
+acl               +file_in_path      +mouse_urxvt       -tag_any_white
+arabic            +find_in_path      +mouse_xterm       +tcl/dyn
+autocmd           +float             +multi_byte        +termguicolors
+autochdir         +folding           +multi_lang        +terminal
-autoservername    -footer            -mzscheme          +terminfo
-balloon_eval      +fork()            +netbeans_intg     +termresponse
+balloon_eval_term +gettext           +num64             +textobjects
-browse            -hangul_input      +packages          +textprop
++builtin_terms    +iconv             +path_extra        +timers
+byte_offset       +insert_expand     +perl/dyn          +title
+channel           +ipv6              +persistent_undo   -toolbar
+cindent           +job               +popupwin          +user_commands
-clientserver      +jumplist          +postscript        +vartabs
-clipboard         +keymap            +printer           +vertsplit
+cmdline_compl     +lambda            +profile           +virtualedit
+cmdline_hist      +langmap           +python/dyn        +visual
+cmdline_info      +libcall           +python3/dyn       +visualextra
+comments          +linebreak         +quickfix          +viminfo
+conceal           +lispindent        +reltime           +vreplace
+cryptv            +listcmds          +rightleft         +wildignore
+cscope            +localmap          +ruby/dyn          +wildmenu
+cursorbind        +lua/dyn           +scrollbind        +windows
+cursorshape       +menu              +signs             +writebackup
+dialog_con        +mksession         +smartindent       -X11
+diff              +modify_fname      -sodium            -xfontset
+digraphs          +mouse             -sound             -xim
-dnd               -mouseshape        +spell             -xpm
-ebcdic            +mouse_dec         +startuptime       -xsmp
+emacs_tags        +mouse_gpm         +statusline        -xterm_clipboard
+eval              -mouse_jsbterm     -sun_workshop      -xterm_save
+ex_extra          +mouse_netterm     +syntax
+extra_search      +mouse_sgr         +tag_binary
-farsi             -mouse_sysmouse    -tag_old_static
   system vimrc file: "/etc/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
       defaults file: "$VIMRUNTIME/defaults.vim"
  fall-back for $VIM: "/usr/share/vim"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H -march=x86-64 -mtune=generic -O2 -pipe -fno-plt -fexceptions -Wformat -Werror=format-security -fstack-clash-protection -fcf-protection -flto -D_REENTRANT -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
Linking: gcc -L. -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now -fstack-protector-strong -rdynamic -Wl,-export-dynamic -Wl,-E -Wl,-rpath,/usr/lib/perl5/5.34/core_perl/CORE -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now -L/usr/local/lib -o vim -lm -ltinfo -lelf -lacl -lattr -lgpm -ldl -Wl,-E -Wl,-rpath,/usr/lib/perl5/5.34/core_perl/CORE -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now -fstack-protector-strong -L/usr/local/lib -L/usr/lib/perl5/5.34/core_perl/CORE -lperl -lpthread -ldl -lm -lcrypt -lutil -lc -L/usr/lib -ltclstub8.6 -ldl -lz -lpthread -lm

$ vim --clean a.c
:scriptnames
  1: /usr/share/vim/vim82/defaults.vim
  2: /usr/share/vim/vim82/filetype.vim
  3: /usr/share/vim/vimfiles/ftdetect/PKGBUILD.vim
  4: /usr/share/vim/vimfiles/ftdetect/espeakfiletype.vim
  5: /usr/share/vim/vimfiles/ftdetect/meson.vim
  6: /usr/share/vim/vimfiles/ftdetect/nginx.vim
  7: /usr/share/vim/vimfiles/ftdetect/vagrantfile.vim
  8: /usr/share/vim/vim82/ftplugin.vim
  9: /usr/share/vim/vim82/indent.vim
 10: /usr/share/vim/vim82/syntax/syntax.vim
 11: /usr/share/vim/vim82/syntax/synload.vim
 12: /usr/share/vim/vim82/syntax/syncolor.vim
 13: /usr/share/vim/vim82/colors/lists/default.vim
 14: /usr/share/vim/vim82/autoload/dist/ft.vim
 15: /usr/share/vim/vim82/ftplugin/c.vim
 16: /usr/share/vim/vim82/indent/c.vim
 17: /usr/share/vim/vim82/syntax/c.vim

@chrisbra
Copy link
Member

Okay here is a screen recording I did:

putty_4rIxrSoOme.mp4

That is basically following what has been documented at :h format-comments

Here is an example of alignment flags at work to make a comment stand out
(kind of looks like a 1 too). Consider comment string:

         :set comments=sr:[/](https://vimhelp.org/pattern.txt.html#%2F)***,m:**,ex-2:******/
 
                                    /*** 
                                      **<--right aligned from "r" flag 
                                      ** 
 offset 2 spaces for the "-2" flag--->** 
                                    ******/ 

In this case, the first comment was typed, then return was pressed 4 times,
then "/" was pressed to end the comment.

However I just noticed the end-of-comment part was not un-indented. Perhaps this is actually the issue?

@ckyoog
Copy link

ckyoog commented Apr 21, 2022

Yes, that is the issue, otherwise what issue were you talking about? That is the very issue I was talking about. Just like the title says "the offset for the end of a three-piece comment".

I was confused when I was watching your screen recording. Because you said it's working, but the video shows the same thing as what I see on my side, that is

/***
  **
  **
  ******/

Now as you noticed, the expected result should be like this, because of ex-2:*/, there is an offset -2 in it.

/***
  **
  **
******/

Additionally, a positive offset doesn't work either, like ex2:*/ won't make it like this

/***
  **
  **
    ******/

@chrisbra
Copy link
Member

so the issue is still there. Why did you initially say this has been solved then?

Wondering if this issue is fixed and just not closed

@ckyoog
Copy link

ckyoog commented Apr 21, 2022

Wondering if this issue is fixed and just not closed? or it is still there.

I was asking. I just want to confirm if it is my fault (conflict settings?) or vim's fault.

@chrisbra
Copy link
Member

I was asking. I just want to confirm if it is my fault (conflict settings?) or vim's fault.

fair enough. I wasn't really aware of the complexity of the comments options and it looks like no-one was interested in fixing this for at least 7 years. So that explains why it is still open.

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