Code Monkey home page Code Monkey logo

Comments (6)

lfilho avatar lfilho commented on July 24, 2024

Hey John, could you elaborate a bit more?

You mean a toggle where its sole responsibility would be to:

  1. take the last char at the end of the line
  2. Check if it is , or ;
  3. Remove it.
  4. And then on hitting the toggle again it would re-insert it?

or just a toggle for toggling the plugin on and off?

from cosco.vim.

jchain avatar jchain commented on July 24, 2024

Your first understanding is what I meant. I asked this because it is needed for Matlab code. Adding ';' at the end is used to disable the print of the value of current line. Removing ';' at the end will enable it. It is very common for Matlab/Octave users. Would you please consider it? Thanks.

This is what I have in my .vimrc. It can toggle the trailing ';'. But your plugin is cooler that can automatically inserts ',' or ';'

" If there isn't one, append a semicolon to the end of the current line and vice versa
function! s:ToggleTrailingSemiColon()
  if getline('.') !~ ';$'
    let original_cursor_position = getpos('.')
    exec("s/$/;/")
    call setpos('.', original_cursor_position)
  else
   " Useful for Octave/Matlab
    let original_cursor_position = getpos('.')
    exec("s/;$//")
    call setpos('.', original_cursor_position)
  endif
endfunction

" For programming languages using a semi colon at the end of statement.
autocmd FileType c,cpp,css,java,javascript,perl,php,jade,octave,tex nmap <silent> ;; :call <SID>ToggleTrailingSemiColon()<CR>
autocmd FileType c,cpp,css,java,javascript,perl,php,jade,octave,tex inoremap <silent> ;; <ESC>:call <SID>ToggleTrailingSemiColon()<CR>

from cosco.vim.

lfilho avatar lfilho commented on July 24, 2024

Right, interesting. Made me reminisce of my university days coding in matlab and octave :D

I can consider this, sure. Sounds like a nice thing to have. But I would ask more help of you, since I don't remember Matlab anymore:

  1. In matlab, can we use commas at the end of the lines at any moment? I mean, do I have to worry about inserting commas? If not, even better!! 😄
  2. Are there exceptions? For instance, in javascript, we would never want a line like this: function myFunction() {;, so Cosco will never try to insert either a comma or semicolon right after a {. So, I need all of this rules...
  3. What is the filetype for matlab and octave files? (type :set ft in vim to find out)

You could also have a look in the source code and issue a Pull Request for us -- you'll see it is not hard to understand. Have a look at the CSS filetype extension mechanism, we'd probably have to create one like this for the matlab/octave files.

This is definitely a nice thing to have, but first we need all these details above. And also, I need to go through the TODO list in the README first, making the plugin more stable and mature first, before diving into new features.

Thank you

from cosco.vim.

jchain avatar jchain commented on July 24, 2024
  1. Don't consider the trailing ',' at the moment for Matlab/Octave.
  2. There is exception in Matlab/Octave. But I have never used that.
  3. ft=matlab, ft=octave

Yes. You take your time.

from cosco.vim.

lfilho avatar lfilho commented on July 24, 2024

Thanks for the info.

Could elaborate more on the exception, although you've never used it? (Maybe some other users have/do).

Alright, don't forget you can always contribute trying to do it yourself and submitting a PR here 👍

Thanks, John. Say hy to those .m files for me 😄

from cosco.vim.

lfilho avatar lfilho commented on July 24, 2024

Hey there. Sorry for the long delay. I had forgotten about this (actually, was also waiting on your reply for my last comment).

But I did it. Please test it and see if that's what you were wishing for.

It won't put a ; in a function declaration line, nor in a end line, nor in a comment line (%). Any other lines it will toggle the ;. Sounds good to you? Any other possible handlings, feel free to suggest it or issue a PR: should be easy enough for anyone to implement it, just look the matlab.vim file.

Cheers

from cosco.vim.

Related Issues (18)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.