Blogged by Ujihisa. Standard methods of programming and thoughts including Clojure, Vim, LLVM, Haskell, Ruby and Mathematics written by a Japanese programmer. github/ujihisa

Sunday, October 31, 2010

List of Vim plugins this computer has

Most of Vim plugins I'm using is controlled under pathogen until the day VimJolts will be released.

  • ColorSamplerPack
    • A collection of colorschemes. I use zenburn in this collection or mrkn256 not in this collection.
  • IndentAnything
    • Only for JavaScript indentation Support.
  • blogger.vim
    • For blogging. Written by me.
  • camelcasemotion
    • ,w as "go to the next capital character."
  • ghc_complete
    • A neocomplcache plugin for ghc.
  • gist-vim
    • To post the current buffer to gist.
  • git-vim
    • To commit the current file or to view git diff.
  • hootsuite
    • For HootSuite development.
  • indent-haskell.vim
    • An indent file for Haskell.
  • neocomplcache
    • The ultimate auto complete tool.
  • quickrun
    • The ultimate quick running tool.
  • repl.vim
    • To start repl in Ruby, Erlang and Haskell. Written by me.
  • shadow.vim
    • The ultimate file-shadowing tool.
  • stickykey.vim
  • thinca-poslist
    • <C-o> can go back at any movements including j.
  • uj-textile
    • ftdetect, ftplugin and syntax file for textile.
    • I suppose this plugin is written by someone. I wonder why this dir name contains uj prefix...
  • unite.vim
    • Anything.el
  • vim-altercmd
    • Automatically capitalize a Vim command in cmdwin
  • vim-coffee-script
    • ftdetect, ftplugin, indent and syntax file for CoffeeScript.
  • vim-markdown
    • ftdetect, ftplugin and syntax file for Markdown.
  • vim-smartchr-0.1.0
    • My mappings in vimrc is full of the flavor of smartchr.
    • My favorite plugin.
  • vim-smartword-0.0.2
    • An extention of w or e.
  • vim-surround
    • cs([ changes the parenthes into brackets.
  • vim-textobj-indent-0.0.3
    • You can select by indentation.
  • vim-textobj-user-0.3.8
    • You can define your own textobj easily.
  • vimclojure-2.1.2
    • A lot of supports for clojure including ftdetect, ftplugin, index and syntax.
    • This has repl support but I've never used it so far.
  • vimproc
    • The :!, :r! and system() substitutor.
    • This is used by quickrun, repl.vim, vimshell and .vimrc
  • vimshell
    • A shell for vim.

Syntax files

  • gas
    • for Gnu Assembly language.
  • haskell.vim
  • rdoc.vim
    • obviously

Obsolete files

This blog post helped me finding some obsolete plugins that I should throw away.

  • shim
    • An interactive Haskell shell in Vim.
    • repl.vim is a superset of this plugin.
  • hints_man2
    • ?

Wednesday, October 27, 2010

Is Hash Comment in SQL?

A "#" is not the character to start a comment in SQL, but "--" is.

A "#" is the character to the end of the line in MySQL.

If you are a Vimmer and only use MySQL when you edit .sql files, you may want to regard the characters after #. .sql files are regarded as just SQL in Vim, but you can specify them as MySQL. Just to write the following one line on ~/.vim/ftdetect/mysql.vim.

autocmd BufRead,BufNewFile *.sql set filetype=mysql

Thursday, October 21, 2010

Reading Git Log In Kindle

I bought a kindle last week and realized how awesome it was.

By the way most programmers' work begins with reading git-log before they start writing great codes. If you can read it with your kindle, having fantastic coffee, it should be amazing experience.

How to do that

The git log after you git pull with time ascending order is available with the following command (*1).

$ git log HEAD@{1}..HEAD --reverse

You can read the diffs as well, with -u option.

About coloring. Vim has diff syntax coloring system and can generate an html file with the color.

$ git log -u HEAD@{1}..HEAD --reverse | vim - -c 'TOhtml' -c 'w | qa!'

This generates Untitled.html.

$ open ./Untitled.html

And

  1. Open Print dialog in your safari
  2. Save PDF
  3. Send the file to Kindle

That's it. Enjoy!

References

Wednesday, October 13, 2010

A Java Library Looks Like A JRuby Library

Problem

In the article I wrote, Introduction to JRuby - Bidirectional Communication, I described how to define a class in Java and call it in JRuby. The class written in Java is called by JRuby in a different way to a library written in pure ruby.

For example, assuming now you are making a Ruby library that has a class and a singleton method Hamburger.arrayze. If it's in Ruby you can write a single rb file hamburger.rb and write the following code.

hamburger.rb:

class Hamburger
  def self.arrayze(x)
    ['begin', x, 'end']
  end
end

and call it from another rb file:

require 'hamburger'
p Hamburger.arrayze('hello')
#=> ["begin", "hello", "end"]

You also can implement Hamburger class in pure Java.

Hamburger.java:

class Hamburger {
  static public String[] arrayze(String x) {
    String[] memo = {"begin", x, "end"};
    return memo;
  }
}

Compile it into a jar file.

$ javac Hamburger.java
$ jar cf hamburger.jar Hamburger.class

Then call the library from an rb file.

require 'hamburger.jar'
include_class Java::Hamburger

p Hamburger.arrayze('hello').to_a
#=> ["begin", "hello", "end"]

The result ran on JRuby is exactly same to the previous one, but the code is very different. You cannot delete .jar extension in require method, abbreviate the include_class declaration, or .to_a to convert Java class Object to Ruby Array of String.

Solution 1

First we should not to return a Java object but to return a Ruby array.

Git-SVN Low-Risk Practice

Assumptions

  • You are supposed to work on a svn branch topic.
  • You hate svn.
  • You want to follow changes of svn trunk.
  • You hate the merging in svn.
  • You already checked out the svn repository with git-svn-clone with stdlayout option.

Wrong way

First you make a local git branch topic that'll sync with svn branch topic.

$ git checkout -b topic topic

Then you work on the branch, including git-commit a lot. Before you go home you push the changes into the main svn repository by git-svn-dcommit.

You sometimes have to see the changes in trunk.

$ git checkout master
$ git svn rebase

And merges the changes into your topic branch.

$ git checkout topic
$ git merge --no-ff master

You know that merge without --no-ff option breaks git-svn system so you did --no-ff.

Finally you finished all your work on the topic branch and tried to merge the changes into trunk.

$ git checkout master
$ git merge --no-ff topic

That causes a lot of conflicts that you have to resolve manually.

Right way

The "Wrong way" example had two failures.

  • ambiguous name of topic
  • merge from trunk to topic

The first one is not fatal but annoying. Every time you run a git command with specifying a branch name shows a warning message that your local git branch name is ambiguous. You should have make a local git branch in which name is different to the svn branch.

$ git checkout -b tpc topic

Next. You are not supposed to merge changes in trunk to topic branch that will be merged to trunk. That causes a lot of conflicts.

The solution is that you create another local git branch that doesn't sync svn branch directly.

$ git checkout -b t tpc

Instead of trying to merge from master to t, try to rebase from master to t. Regard the tpc branch for very temporary one.

$ git checkout master
$ git svn rebase
$ git checkout t
$ git rebase master

$ git checkout tpc
$ git svn dcommit
$ svn delete `git svn info --url`
$ git checkout t
$ git branch -d -r topic
$ git branch -D tpc
$ git svn branch topic
$ git checkout -b tpc topic

figure 1

Note that this approach make the svn repository log messy. Be resigned; that's the subversion.

Followers