Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Vim Banshee - a command line wrapper for Banshee

Vim Banshee - a command line wrapper for Banshee

Based on Ben Klein's book The VimL Primer: Edit Like a Pro with Vim Plugins and Scripts I started to write this plugin and I want to go through it, explain it, what future plans he has and how it was tested.

Matthias Günther

July 27, 2015
Tweet

More Decks by Matthias Günther

Other Decks in Technology

Transcript

  1. vim-banshee

    View Slide

  2. Who Am I
    @wikimatze
    Running vimberlin.de
    Writing padrinobook.com

    View Slide

  3. Vimscript
    is called nowadays VimL
    is a dynamic imperative
    language: variables,
    expressions, control
    structures, built-in functions,
    user-defined functions, data
    structures, File I/O, regex
    pattern matching

    View Slide

  4. echom
    echo returns echo of
    expressions and saves them
    in message-history
    (:messages)
    good for debugging

    View Slide

  5. split
    :split … transforms string
    into a list (by default it takes
    whitespace but you can
    specifiy the second
    parameter as a own
    defined delimeter)

    View Slide

  6. split examples
    :echo split("Hello Vimmers at Vimberlin")
    :echo split("Hello Vimmers at Vimberlin", "m")

    View Slide

  7. system
    :system() … get the output
    of a shell command as a
    string

    View Slide

  8. system example
    let banshee = "banshee --query-album --query-artist"
    let playlist = split(system(banshee), '\n')
    echom string(playlist)

    View Slide

  9. append, line
    append(line, text) …
    appends the text to a buffer
    after a certain line in the file
    line(number) … takes the
    file position and returns the
    line number of that position
    in the current file

    View Slide

  10. list, for loop
    list: ordered sequence of
    items
    for loops: for item in list

    View Slide

  11. examples
    let playlist = ['Vim' , 'Berlin', 'rockt']
    for track in playlist
    call append(line('$'), track)
    endfor
    :echo line('w$')
    33G
    ma
    :echo line("'a")

    View Slide

  12. bufexists, bufnr
    bufexists({expr}) …
    result is a number, which is
    non-zero if the buffer exists
    bufnr({expr}) … result is
    the number of a buffer
    (displayed by the :ls
    command

    View Slide

  13. exec
    exec … takes a string and
    executes it as an Ex
    command

    View Slide

  14. custom filetypes
    put them into ftdetect
    directory for your custom
    file types

    View Slide

  15. examples filetype
    autocmd BufRead,BufNewFile *.playlist set filetype=playlist

    View Slide

  16. echohl
    echohl … use the highlight
    group for the following echo

    View Slide

  17. example echohl
    :echohl WarningMsg | echo "Don't panic!" | echohl None

    View Slide

  18. command
    command[!] [{attr}…]
    {cmd} {rep} … define a
    user command. The name
    of the command is {cmd}
    and its replacement text is
    {rep}. The ! can be used to
    overwrite any preexisting
    commands.

    View Slide

  19. command example
    if(!exists(':BansheeNext'))
    command! BansheeNext call banshee#PlayNextSong()
    endif

    View Slide

  20. Testing
    Using vimvader
    no dependencies
    easy to setup

    View Slide

  21. Create Test
    environment
    └── test
    ├── banshee.vader
    ├── run
    └── fixtures
    ├── crystals.mp3
    └── focus.mp3

    View Slide

  22. Isolated test
    environment
    #!/bin/bash
    banshee --play-enqued fixtures/crystals.mp3 fixtures/focus.mp3 &
    vim -Nu filetype off
    set rtp+=~/.vim/plugged/vader.vim
    set rtp+=~/.vim/plugged/vim-banshee
    filetype plugin indent on
    syntax enable
    EOF) +Vader*

    View Slide

  23. Test file
    Execute (BansheeInfo display title, artist and album):
    !banshee --play
    redir => test
    BansheeInfo
    redir END
    AssertEqual get(split(test), 0), 'Crystals'
    AssertEqual get(split(test), 2), 'Professor'
    AssertEqual get(split(test), 3), 'Kliq'
    AssertEqual get(split(test), 5), 'Curriculum'
    AssertEqual get(split(test), 6), 'Vitae'
    Execute (:BansheeNext play the next song):
    ...

    View Slide

  24. Run the tests
    :Vader
    or
    cd test && ./run

    View Slide

  25. Test results
    Starting Vader: 1 suite(s), 10 case(s)
    Starting Vader: /home/wm/.vim/plugged/vim-banshee/test/banshee.vader
    ( 1/10) [EXECUTE] BansheeInfo display title, artist and album
    ( 2/10) [EXECUTE] :BansheeNext play the next song
    ( 3/10) [EXECUTE] :BansheePrevious play the previous song
    ( 4/10) [EXECUTE] :BansheeRestart, :BansheePlay, :BansheeStop, :BansheeSetPosition, :BansheeDuration
    ( 5/10) [EXECUTE] :BansheePause stop playing the current song
    ( 6/10) [EXECUTE] :BansheeToggle pauses and plays a song
    ( 7/10) [EXECUTE] :BansheeStop stop playing a song and when it's played again, it will start from the beginning
    ( 8/10) [EXECUTE] :BansheeSetRating and :BansheeSetVolume
    ( 9/10) [EXECUTE] Existance of commands :BansheeShow, :BansheeFullscreen, :BansheeHide, :BansheeStopWhenFinished
    (10/10) [EXECUTE] Existance of dialog commands: :BansheeImportMedia, :BansheeOpenLocation, :BansheePreferences
    Success/Total: 10/10
    Success/Total: 10/10 (assertions: 26/26)
    Elapsed time: 17.128639 sec.

    View Slide

  26. The VimL Primer
    https://pragprog.com/book/
    bkviml/the-viml-primer

    View Slide

  27. Coupon Code
    Code is:
    zBOOKCLUBvimberlin
    It is good for a 35% discount
    off of The VimL Primer =>
    valid until the end of July,
    2015

    View Slide

  28. Thanks
    For being here and make
    Vimberlin happen! Next
    meetup in August.

    View Slide