<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>JugglerShu.Net &#187; shu</title>
	<atom:link href="http://programming.jugglershu.net/wp/?author=1&#038;feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://programming.jugglershu.net/wp</link>
	<description>Nothing But Programming</description>
	<lastBuildDate>Wed, 15 Apr 2020 08:11:15 +0000</lastBuildDate>
	<language>ja</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=3.9.40</generator>
	<item>
		<title>テストブログ</title>
		<link>http://programming.jugglershu.net/wp/?p=817</link>
		<comments>http://programming.jugglershu.net/wp/?p=817#comments</comments>
		<pubDate>Sun, 29 Nov 2015 04:07:21 +0000</pubDate>
		<dc:creator><![CDATA[shu]]></dc:creator>
				<category><![CDATA[未分類]]></category>

		<guid isPermaLink="false">http://programming.jugglershu.net/wp/?p=817</guid>
		<description><![CDATA[test teste]]></description>
				<content:encoded><![CDATA[<p>test teste</p>
]]></content:encoded>
			<wfw:commentRss>http://programming.jugglershu.net/wp/?feed=rss2&#038;p=817</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to draw thick and transparent insertion point in NSTextView</title>
		<link>http://programming.jugglershu.net/wp/?p=765</link>
		<comments>http://programming.jugglershu.net/wp/?p=765#comments</comments>
		<pubDate>Sat, 17 Aug 2013 07:16:35 +0000</pubDate>
		<dc:creator><![CDATA[shu]]></dc:creator>
				<category><![CDATA[未分類]]></category>
		<category><![CDATA[NSTextView]]></category>
		<category><![CDATA[Objective-C]]></category>

		<guid isPermaLink="false">http://programming.jugglershu.net/wp/?p=765</guid>
		<description><![CDATA[While I was working on drawing an insertion point in XVim project I had a really hard time to achieve my goal &#8220;drawing thick and transparent insertion point on a character&#8221;. This does not  <a class="more-link" href="http://programming.jugglershu.net/wp/?p=765">続きを読む <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>While I was working on drawing an insertion point in <a href="https://github.com/JugglerShu/XVim">XVim</a> project I had a really hard time to achieve my goal &#8220;drawing thick and transparent insertion point on a character&#8221;.</p>
<p>This does not look difficult since NSTextView has a method to override named &#8220;drawInsertionPointInRect:color:turnedOn:&#8221;. Actually just drawing &#8220;thick&#8221; insertion point  is not difficult. But just overriding the method results in strange behaviour and not beautiful at all. Here I show what I tried and how I achieve the transparent thick insertion point.</p>
<p>If you are just interested in &#8220;how&#8221;, skip the part explaining what I tried and see the section &#8220;Solution&#8221; at the end of this post. There is a code for it. I tested the code in OS X 10.8 and also I must note that the code uses NSTextView&#8217;s internal method to override. This means that you may not use the code if you want your app to be in AppStore.</p>
<h2>First attempt</h2>
<p>As everyone can think of I first tried to subclass NSTextView and override &#8220;drawInsertionPointInRect:color:turnedOn:&#8221; (will be referred as &#8220;drawIPR&#8221; in this post). The code looks like following.</p>
<pre class="brush: cpp; gutter: false">
-(void)drawInsertionPointInRect:(NSRect)rect color:(NSColor)color turnedOn:(BOOL)flag {
    // Calculate the rect of a character under the insertion point
    NSRange charRange = NSMakeRange(self.selectedRange.location, 1);
    NSRect glyphRect = [[self layoutManager] boundingRectForGlyphRange:charRange inTextContainer:[self textContainer]];
    if( glyphRect.size.width == 0 ||
       [[NSCharacterSet newlineCharacterSet] characterIsMember:[[self string] characterAtIndex:self.selectedRange.location]]){
        // This handles when the insertion point is at the end of line where we cannot find any character to cover by a caret.
        // We keep the original width (1.0)
        glyphRect = rect;
    }
    [super drawInsertionPointInRect:glyphRect color:color turnedOn:flag];
}
</pre>
<p>This works somehow. But there are unacceptable problems.</p>
<ol>
<li>No transparency. A caret completely fill the rect and we can not recognise the character under the caret.(Since the caret is blinking you still can see the character but not really beautiful)</li>
<li>When you move a cursor it draws thin(origina size) insertion point. You will see why this happens later.</li>
</ol>
<p><a href="http://programming.jugglershu.net/wp/wp-content/uploads/2013/08/Screen-Shot-2013-08-17-at-12.27.28-PM.png"><img class="aligncenter" alt="Screen Shot 2013-08-17 at 12.27.28 PM" src="http://programming.jugglershu.net/wp/wp-content/uploads/2013/08/Screen-Shot-2013-08-17-at-12.27.28-PM.png" width="498" height="326" /></a></p>
<p style="text-align: center;"><b>Character &#8216;p&#8217; is covered by a caret</b></p>
<p>OK. I have 2 problems. Solve them one by one.</p>
<h2>Transparent color</h2>
<p>So I tried to set the color&#8217;s alpha value. It&#8217;s like this.</p>
<pre class="brush: cpp; gutter: false">
-(void)drawInsertionPointInRect:(NSRect)rect color:(NSColor*)color turnedOn:(BOOL)flag {
    // Calculate the rect of a character under the insertion point
    NSRange charRange = NSMakeRange(self.selectedRange.location, 1);
    NSRect glyphRect = [[self layoutManager] boundingRectForGlyphRange:charRange inTextContainer:[self textContainer]];
    if( glyphRect.size.width == 0 ||
       [[NSCharacterSet newlineCharacterSet] characterIsMember:[[self string] characterAtIndex:self.selectedRange.location]]){
        // This handles when the insertion point is at the end of line where we cannot find any character to cover by a caret.
        // We keep the original width (1.0)
        glyphRect = rect;
    }
    // Set alpha of the color here.
    color = [color colorWithAlphaComponent:0.5]; // &lt;--- newly added.
    [super drawInsertionPointInRect:glyphRect color:color turnedOn:flag];
}
</pre>
<p>Unfortunately this does not change anything. The reason is that inside the &#8220;drawIPR&#8221; in NSTextView it use NSRectFill to draw the insertion point and the alpha value of the color is completely ignored.</p>
<h2>Drawing a caret by myself</h2>
<p>Since the implementation of the &#8220;drawIRP&#8221; in NSTextView draws a caret by NSRectFill we can not use it to draw transparent caret. OK. We can re-implement the whole of the method. To re-implement it we have to know how the method works. It takes 3 arguments &#8220;rect&#8221;,&#8221;color&#8221; and &#8220;turnedOn&#8221;. the &#8220;rect&#8221; and &#8220;color&#8221; are apparent. The &#8220;turnedOn&#8221; argument specifies whether we should draw insertion point or clear the insertion point. The method is called with the &#8220;turnedOn&#8221; arugument set to YES and NO by turns, which results in blinking a caret. So the implementation should be like following.</p>
<pre class="brush: cpp; gutter: false">
-(void)drawInsertionPointInRect:(NSRect)rect color:(NSColor*)color turnedOn:(BOOL)flag {
    NSRange charRange = NSMakeRange(self.selectedRange.location, 1);
    NSRect glyphRect = [[self layoutManager] boundingRectForGlyphRange:charRange inTextContainer:[self textContainer]];
    if( glyphRect.size.width == 0 ||
       [[NSCharacterSet newlineCharacterSet] characterIsMember:[[self string] characterAtIndex:self.selectedRange.location]]){
        glyphRect = rect;
    }
    
    if( flag ){
        // Draw a caret
        color = [color colorWithAlphaComponent:0.5];
        [color set];
        NSRectFillUsingOperation(glyphRect,  NSCompositeSourceOver);
    }
    else{
        // Clear a caret
        // We have to redraw the character under the caret.
        // We should use &quot;setNeedsDisplayInRect:&quot; if possible. But to do so we have to keep the rect we drew somewhere.
        // This kind of optimisation is off topic of this post so just update the whole rect.
        [self setNeedsDisplay:YES];
    }
}
</pre>
<p>Yes, this solves the problem No.1 but not No.2. ( I think NSTextView&#8217;s implementation should be changed as this code works perfectly because this is the official way to override drawing insertion point).</p>
<p>The code above draws/clears a caret(with thick and transparency) correctly but when you move a cursor you see a caret without the thickness. Why? The reason why this happens is because NSTextView uses internal method to draw a caret and it is called when you move a cursor to redraw the caret immediately. The internal method is named &#8220;_drawInsertionPointInRect:color:&#8221;. Note that it starts with &#8220;_&#8221; and does not have &#8220;turenedOn&#8221; argument. (will be referred as &#8220;_drawIPR&#8221; in this post). The code in NSTextView should be like following according to my observation of the behavior. ( This is really simplified to make the point clear though. )</p>
<pre class="brush: cpp; gutter: false">
// This is guessed code of NSTextView implementation

// Private method to draw a caret.
// Note that this method only does &quot;drawing&quot;. It does NOT have &quot;turnedOn&quot; flag.
-(void)_drawInsertionPointInRect:(NSRect)rect color:(NSColor*)color{
       [color set];
       NSRectFill(rect);
}

- (void)drawInsertionPointInRect:(NSRect)rect color:(NSColor*)color turnedOn:(BOOL)flag{
    if( flag ){
       // Call the internal method to draw insertion point 
       [_drawInsertionPointInRect:rect color:color]
    }else{
       [self setNeedsDisplayInRect:rect];
    }
}

// When you move a cursor, _drawRect (this is also an internal method) draws insertion point.
- (void)_drawRect:(NSRect)rect clip:(NSRect)clip{
    // At some point in this method...
    [self _drawInsertionPointInRect:NSMakeRect(x,y,1.0,height) color:_color];
}
</pre>
<p>The important points are</p>
<ul>
<li>&#8220;_drawIPR&#8221; is called from multiple methods (not only from &#8220;drawIPR&#8221; but also from _drawRect:clip:)</li>
<li>In _drawRect:clip: it calls &#8220;_drawIPR&#8221; with <b>hard coded width.</b></li>
</ul>
<h2>Overriding _drawInsertionPointInRect:color:</h2>
<p>OK. So NSTextView uses &#8220;_drawIPR&#8221; to draw insertion point anyway. How about just overriding &#8220;_drawIPR&#8221; instead of &#8220;drawIPR&#8221;. The code should be like&#8230;</p>
<pre class="brush: cpp; gutter: false">
-(void)_drawInsertionPointInRect:(NSRect)rect color:(NSColor*)color{
    NSRange charRange = NSMakeRange(self.selectedRange.location, 1);
    NSRect glyphRect = [[self layoutManager] boundingRectForGlyphRange:charRange inTextContainer:[self textContainer]];
    if( glyphRect.size.width == 0 ||
       [[NSCharacterSet newlineCharacterSet] characterIsMember:[[self string] characterAtIndex:self.selectedRange.location]]){
        glyphRect = rect;
    }
    color = [color colorWithAlphaComponent:0.5];
    [color set];
    NSRectFillUsingOperation(glyphRect, NSCompositeSourceOver);
    // We do not call super calls since the method in the super class uses NSRectFill and calling it results in filling the rect with the color without transparency.
}

</pre>
<p>Note that we are not overriding &#8220;drawIPR&#8221;. This results in drawing a thick and transparent caret whenever NSTextView draws a caret. Unfortunately this leads another problem. The code is only &#8220;drawing&#8221; a caret but not &#8220;clearing&#8221; a caret to blink a caret. So once the caret is drawn the caret stays there and there is no blinking. Furthermore if you move a caret, all the characters the caret passes will be covered by the drawing and stays there.</p>
<p><a href="http://programming.jugglershu.net/wp/wp-content/uploads/2013/08/Screen-Shot-2013-08-17-at-12.34.39-PM.png"><img class="alignnone size-full wp-image-780 aligncenter" alt="Screen Shot 2013-08-17 at 12.34.39 PM" src="http://programming.jugglershu.net/wp/wp-content/uploads/2013/08/Screen-Shot-2013-08-17-at-12.34.39-PM.png" width="495" height="326" /></a></p>
<p style="text-align: center;"><strong>Drawn carets are not cleared</strong></p>
<p>The reason why the caret is not cleared correctly is because NSTextView does not know the rect which should be cleared. NSTextView tries to clear the area NSTextView draws a caret (which is a thin caret).</p>
<h2>Clearing thick caret</h2>
<p>Now the problem is clearing caret. The clearing a caret is done in &#8220;drawIPR&#8221; when the &#8220;turnedOn&#8221; argument is NO. We can tell NSTextView to redraw the view by calling &#8220;setNeedsDisplay&#8221; as we already saw.</p>
<h2>Solution</h2>
<p>The following code works well.</p>
<pre class="brush: cpp; gutter: false">
-(void)_drawInsertionPointInRect:(NSRect)rect color:(NSColor*)color{
    NSRange charRange = NSMakeRange(self.selectedRange.location, 1);
    NSRect glyphRect = [[self layoutManager] boundingRectForGlyphRange:charRange inTextContainer:[self textContainer]];
    if( glyphRect.size.width == 0 ||
       [[NSCharacterSet newlineCharacterSet] characterIsMember:[[self string] characterAtIndex:self.selectedRange.location]] ){
        glyphRect = rect;
    }
    color = [color colorWithAlphaComponent:0.5];
    [color set];
    NSRectFillUsingOperation(glyphRect, NSCompositeSourceOver);
    // We do not call super calls since the method in the super class uses NSRectFill and calling it results in filling the rect with the color without transparency.
}

- (void)drawInsertionPointInRect:(NSRect)rect color:(NSColor *)color turnedOn:(BOOL)flag{
    // Call super class first.
    [super drawInsertionPointInRect:rect color:color turnedOn:flag];
    // Then tell the view to redraw to clear a caret.
    if( !flag ){
        [self setNeedsDisplay:YES];
    }
}
</pre>
<p>The problem I can think of is that &#8220;setNeedsDisplay:YES&#8221; is not really optimised way to redraw the view since we are just interested in clearing the rect of a caret but not entire view. What we have to do for it is  to keep the rect of a caret in a instance variable (by adding to the class) and call &#8220;setNeedsDisplayInRect:&#8221; to redraw that area.</p>
<h2>(Appendix)Further investigation</h2>
<p>I also did some further investigation for NSTextView internal.<br />
The root of the problem of not clearing a caret is that NSTextView keeps the rect of a caret rect in an internal variable and use it to clear the caret. If we can update it by ourselves the problem should be solved. By using some Objective-C runtime functions I reverse engineered NSTextView class and I found the followings.</p>
<ul>
<li>NSTextView has a private variable named &#8220;_ivars&#8221;</li>
<li>&#8220;_ivars&#8221; is a instence of NSTextViewIvars .</li>
<li>NSTextViewIvars has several variables (maybe 12 variables).</li>
<li>One of them is named &#8220;_insertionPointRect&#8221;<br />
(I found &#8220;_insertionPointRectCache&#8221; too but do not know how this is used)</li>
</ul>
<p>And also I found that after calling &#8220;_drawIPR&#8221; of NSTextView the value of the &#8220;_insertionPointRect&#8221; is updated. </p>
<h2>Another solution (not recommended)</h2>
<p>(If you are coming from top to get the code which works, use the code in &#8220;Solution&#8221; section.)<br />
So what we should do is</p>
<ul>
<li>Override &#8220;_drawIPR&#8221;</li>
<li>In &#8220;_drawIPR&#8221;, draw thick/transparent caret.</li>
<li>In &#8220;_drawIPR&#8221;, update &#8220;_insertionPointRect&#8221; to remember the rect of our caret.</li>
</ul>
<p>So the code I got to achieve from this investigation is&#8230; </p>
<pre class="brush: cpp; gutter: false">
-(void)_drawInsertionPointInRect:(NSRect)rect color:(NSColor*)color{
    NSRange charRange = NSMakeRange(self.selectedRange.location, 1);
    NSRect glyphRect = [[self layoutManager] boundingRectForGlyphRange:charRange inTextContainer:[self textContainer]];
    if( glyphRect.size.width == 0 ||
       [[NSCharacterSet newlineCharacterSet] characterIsMember:[[self string] characterAtIndex:self.selectedRange.location]] ){
        glyphRect = rect;
    }
    color = [color colorWithAlphaComponent:0.5];
    [color set];
    NSRectFillUsingOperation(glyphRect, NSCompositeSourceOver);
    // Update internal variables (_insertionPointRect) in NSTextView
    id nsTextViewIvars;
    object_getInstanceVariable(self, &quot;_ivars&quot;, (void**)&amp;nsTextViewIvars);
    [nsTextViewIvars setValue:[NSValue valueWithRect:glyphRect] forKey:@&quot;_insertionPointRect&quot;];
}
// And you do not need to override &quot;drawIPR&quot; since NSTextView automatically clears a caret.
</pre>
<p>Yes. This clears a caret we draw correctly. But I sometimes see a caret draws several times at one time when you move a caret. Not too bad but not as beautiful as the code in &#8220;Solution&#8221; section.</p>
<p>Thank you for reading and I hope this helps you.</p>
]]></content:encoded>
			<wfw:commentRss>http://programming.jugglershu.net/wp/?feed=rss2&#038;p=765</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>XVimの紹介</title>
		<link>http://programming.jugglershu.net/wp/?p=547</link>
		<comments>http://programming.jugglershu.net/wp/?p=547#comments</comments>
		<pubDate>Wed, 26 Dec 2012 17:56:00 +0000</pubDate>
		<dc:creator><![CDATA[shu]]></dc:creator>
				<category><![CDATA[未分類]]></category>

		<guid isPermaLink="false">http://programming.jugglershu.net/wp/?p=547</guid>
		<description><![CDATA[Vim Advent Calendar 2012 27日目の記事です。 XcodeでのVimキーバインドを実現するXVimの開発経緯と使い方をご紹介したいと思います。まず初めにURLだけ貼っておきます。 https://github.com/Jugglershu/XVim さて、本題。ちょうど今から1年前、僕は友達ともにiOS向けアプリの作成を趣味で行っていました。当時僕はMacはあまり使ったこと <a class="more-link" href="http://programming.jugglershu.net/wp/?p=547">続きを読む <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p><a href="http://atnd.org/events/33746">Vim Advent Calendar 2012</a> 27日目の記事です。</p>
<p>XcodeでのVimキーバインドを実現するXVimの開発経緯と使い方をご紹介したいと思います。まず初めにURLだけ貼っておきます。<br />
<a href="https://github.com/Jugglershu/XVim">https://github.com/Jugglershu/XVim</a></p>
<p>さて、本題。ちょうど今から1年前、僕は友達ともにiOS向けアプリの作成を趣味で行っていました。当時僕はMacはあまり使ったことがなく、Objective-Cの個性あふれるシンタックスに苦しんでおりました。iOSアプリの開発なので、当然Xcodeを使うわけですが、シンタックスに苦しんでいるところへXcodeではデフォルトだとVimのキーバインドではなくEmacsのそれとなっており、そのままだと使い物になりません。</p>
<p>Vimのキーバインドにするにはどうしたらいいのか友人に聞いたら、「ない」との答え・・・またまた〜、そんなことないでしょ〜。まあきっとどこかの誰かがそういうの作ってくれてるよと、軽い気持ちでググり、いまどきVimキーバインドがないなんて、そんなわけが・・・「ほんまや！」</p>
<p>というわけで、ないわけです。とても不思議です。世界中のVimプログラマはどうやってiOSアプリを書いているのでしょうか。確かにVimオンリーで書くという選択肢もありそうです。実際、Cocoa.vimなるプラグインもあった（いまも動く？）ようですが、ちょっと使ってみた感じだとあまりうまく動きませんでした。なにより、Xcodeの補完機能や、その場でエラー・ワーニングチェックなどiOSアプリを書く上では非常に有効な機能を捨ててしまうのはあまりにも惜しいです。</p>
<p>しかし、なぜXcode向けのVimキーバインド（プラグイン）が存在しないのか。もしかするとXcodeがプラグインに正式に対応していないというのが大きな理由かもしれません。実際プラグインの作り方に関するドキュメントなどはどこにもありません。幸い、これまでWindowsでAPIフックなどのプログラムを書いてきたこともあり、自分で作ったライブラリさえXcodeプロセスに読み込ませられれば、あとはなんとかできる自信があったため、とにかくその方法を探しました。実はXcodeは内部的にはプラグインのサポートがされているようで、その機能を使うことでXcodeのプラグインを読み込ませることができることがわかりました。</p>
<p>ただし、分かっているのは作ったプラグインがロードされ、初期化時に特定のメソッドが呼び出されることだけです。ここからはひたすら試行錯誤。幸いObjective-Cは動的バインド言語であり、Xcodeのクラスやメソッドの名前などはすべて確認することができ、またどのようなメソッドが呼び出されているかも簡単なコードを追加するだけで確認できます。また、特定のクラスのメソッドのフックもバイナリを直接編集することなくObjective-Cのライタイムを頼って実現することができます。</p>
<p>そこから2週間ほどかけてとりあえず動くものを作りました。うれしいことに、テキスト編集自体の機能はNSTextViewやXcodeが内部的に使っているDVTSourceTextViewクラスに実装されており、キーイベントに対応させてそれらを呼び出すことで基本的な編集機能は実装できました。</p>
<p>それからいろいろな方の協力もあり、現在は以下の様にステータスバーがあったり、太いカーソルになったりと見た目も良くなっております。</p>
<div><a href="http://4.bp.blogspot.com/-svPhJOLJbGI/UNs6CF0CcxI/AAAAAAAAANE/CiZd2PLc-VI/s1600/Screen%2BShot%2B2012-12-27%2Bat%2B2.53.00%2BAM.png"><img alt="" src="http://4.bp.blogspot.com/-svPhJOLJbGI/UNs6CF0CcxI/AAAAAAAAANE/CiZd2PLc-VI/s400/Screen%2BShot%2B2012-12-27%2Bat%2B2.53.00%2BAM.png" width="400" height="329" border="0" /></a></div>
<p>だいぶ、Vimの話からずれてしまいました。ここからはXVimの便利な機能をご紹介したいと思います。XVimはVimのキーバインドを実現するためのものなので、Xcode上でVimのキーバインドで編集できることはごく標準的な機能です（まだまだ対応していないバインドはありますが）。一方でXcode特有の機能を使うために実装したXVim特有のコマンドもあります。</p>
<p>最も個人的に使う頻度が高いのが、メニューの特定のコマンドを呼び出すコマンド</p>
<pre>:xccmd</pre>
<p>です。Cocoaアプリではメニュー内の各項目にはAction名が割り振られているため、そのアクション名を指定することでメニュー上にあるコマンドはすべて実行することができます。たとえば、</p>
<pre>:xccmd jumpToNextCounterpart</pre>
<p>と入力した場合、.hと.mファイルの切り替えを行います。切り替えのためだけにこれを打ち込むのはばかばかしいので、XVimの.vimrcにあたる、.xvimrcファイルを作成し</p>
<pre>nmap &lt;c-n&gt; :xccmd jumpToNextCounterpart&lt;CR&gt;</pre>
<p>と書いておきます。これでによって、この機能を呼び出すことができるのです。<br />
xccmdの引数部分は<a href="https://github.com/JugglerShu/XVim/blob/master/Documents/Developers/MenuActionList.txt">https://github.com/JugglerShu/XVim/blob/master/Documents/Developers/MenuActionList.txt</a><br />
に一覧があります。</p>
<p>ほかには、開発時によく行うビルドと実行はそれぞれ</p>
<pre>:make&lt;br&gt;:run&lt;br&gt;</pre>
<p>で起動できるようになっています。もちろん上に書いたように自分の好きなキーを割り当ててもよいです。メニューのショートカットについてはXcode自体に設定があるのでそれを利用しても良いですが、XVimで設定するとnmap, imapなどに対応している点が良い点だと思います（と言いつつ、個人的にはこれら違いによるショートカットを使っていなかったりしますが。）</p>
<p>もう一つ有効な機能として、</p>
<pre>:xhelp</pre>
<p>コマンドがあります。これはクイックヘルプを呼び出すために実装してあるコマンドです（:xccmdコマンドでも実行できます。）これは現在のカーソル位置にあるメソッドやクラスのヘルプをその場に表示してくれるというもので、引数の意味などを確認するのにとても便利です。</p>
<p>一部のキーバインドは、Vimの定義ではなくXcodeの機能で置き換えれています。&#8221;gd&#8221;が、典型的な例で、Vimでは&#8221;Goto locfal Declaration.&#8221;ということで、宣言へのジャンプとなっていますが、これはXVimではXcodeの&#8221;Jump to Definition&#8221;を呼び出すようになっています。そのため、定義部分で入力すれば、宣言部分にジャンプしますし、宣言部分で入力すれば定義部分にジャンプします。またカーソル下のファイル名のオープンはVimではgfですが、Xcodeではこの&#8221;Jump to Definition”でジャンプできるため、ファイル名上にカーソルを置いて、&#8221;gd&#8221;コマンドでヘッダファイルのオープンなどができます。</p>
<p>このように、Vimキーバインドプラグインですが、Xcodeとうまく連携するようにということを意識して作成しています。現在の機能一覧は以下を参照してください。<br />
<a href="https://github.com/JugglerShu/XVim/blob/master/Documents/Users/FeatureList.md">FeatureList</a></p>
<p>さて、XVimの開発状況なのですが、最近ちょっと滞っております。というのもこれ以上機能を追加しようとすると少しバグが多く発生するような状況になってきており、少し根本的な設計見直しが必要と判断しているためです。現在github上の別ブランチにて作業をしておりmasterはあまり更新されておりません。ただし、比較的安定しているはずですので、しばらくはそちらを利用していただくのが良いと思います。</p>
<p>今後開発予定の機能としては、矩形選択、検索・置換機能の強化が大きなところとなりそうです。対応コマンドの充実などやりたいことはたくさんあるのですが、なかなか前に進めない状況だったりもします。</p>
<p>なお、XcodeのVimキーバインドとして、最近ライバルが出現しました。<a href="http://viciousapp.com/">http://viciousapp.com/</a>がそれです。ちなみに20ドルだそうです。負けないように頑張りたいと思います。</p>
<p>Vim Advent Calendar 2012 明日は@sonotsさんです。</p>
]]></content:encoded>
			<wfw:commentRss>http://programming.jugglershu.net/wp/?feed=rss2&#038;p=547</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WordPressに</title>
		<link>http://programming.jugglershu.net/wp/?p=548</link>
		<comments>http://programming.jugglershu.net/wp/?p=548#comments</comments>
		<pubDate>Thu, 15 Dec 2011 04:05:00 +0000</pubDate>
		<dc:creator><![CDATA[shu]]></dc:creator>
				<category><![CDATA[未分類]]></category>

		<guid isPermaLink="false">http://programming.jugglershu.net/wp/?p=548</guid>
		<description><![CDATA[WordPressにこのwebサイト全体を移行しようかと考え中。もう、最近HTMLとか自分で編集するの面倒になってきた。]]></description>
				<content:encoded><![CDATA[<p>WordPressにこのwebサイト全体を移行しようかと考え中。<br />もう、最近HTMLとか自分で編集するの面倒になってきた。</p>
]]></content:encoded>
			<wfw:commentRss>http://programming.jugglershu.net/wp/?feed=rss2&#038;p=548</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>KeyRemap4MacBookProとControl,CommandキーとMacVimと</title>
		<link>http://programming.jugglershu.net/wp/?p=549</link>
		<comments>http://programming.jugglershu.net/wp/?p=549#comments</comments>
		<pubDate>Sat, 29 Oct 2011 04:12:00 +0000</pubDate>
		<dc:creator><![CDATA[shu]]></dc:creator>
				<category><![CDATA[未分類]]></category>

		<guid isPermaLink="false">http://programming.jugglershu.net/wp/?p=549</guid>
		<description><![CDATA[数ヶ月前からMacBookAirを使い始めて、Commandキーでいろいろな操作ができるショートカットがいまいち気に入らず、今まで通りControlキー（左手の小指）でショートカットを利用したいと思い、ControlとCommandキーを入れ替えることにした。 方法は簡単でKeyRemap4MacBookProをインストールして、あとは設定で”Change Control_L Key&#8221; <a class="more-link" href="http://programming.jugglershu.net/wp/?p=549">続きを読む <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>数ヶ月前からMacBookAirを使い始めて、Commandキーでいろいろな操作ができるショートカットがいまいち<br />気に入らず、今まで通りControlキー（左手の小指）でショートカットを利用したいと思い、<br />ControlとCommandキーを入れ替えることにした。</p>
<p>方法は簡単でKeyRemap4MacBookProをインストールして、あとは設定で<br />”Change Control_L Key&#8221;の中から、Command_Lと入れ替えるものにチェックを入れれれば良い。</p>
<p>でも、いろいろオプションがあって、たとえば、&#8221;Emacs以外は入れ替え&#8221;とか、&#8221;TerminalとChromeとRemoteDesctop以外は入れ替え&#8221;とかがある。</p>
<p>僕はTerminalとかはそのままControlキーはControlキーとして使いたかったので<br />&#8220;except Terminal,Virtual Machine, RDC&#8221;<br />のものを選択した。</p>
<p>これでほとんどの場合には満足できたのだけれど、１つだけ満足できない所が。<br />MacVimでControlとCommandが入れ替わってしまう。<br />Terminal上で操作するVimは上記設定で問題なくControlキーはそのままになるのだけれど、<br />MacVimはそうなってくれない。</p>
<p>調べてみると自分で設定を書けるらしい。いろいろ戸惑ったものの、結果以下のようなXMLをprivate.xmlとして保存しておけば大丈夫ということがわかった。これを読み込むとMyKeyMapという項目が追加されるのでそれにチェックすればOK<br />（この場合、規定で入っているChange Control_L Keyは使わず自分の設定のものだけにチェックつける)</p>
<pre>&lt;code&gt;&lt;br&gt;&lt;?xml version=&quot;1.0&quot;?&gt;&lt;br&gt;&lt;item&gt;&lt;br&gt; &lt;name&gt;KeyRemap4MacBook Developer&lt;/name&gt;&lt;br&gt; &lt;list&gt;&lt;br&gt;  &lt;item&gt;&lt;br&gt;   &lt;name&gt;MyKeyMap&lt;/name&gt;&lt;br&gt;   &lt;list&gt;&lt;br&gt;    &lt;item&gt;&lt;br&gt;     &lt;name&gt;Control_L to Command_L (except VI, Terminal, Virtual Machine, RDC)&lt;/name&gt;&lt;br&gt;     &lt;identifier&gt;remap.MycontrolL2commandL_extermvm&lt;/identifier&gt;&lt;br&gt;     &lt;not&gt;VI, TERMINAL, VIRTUALMACHINE, REMOTEDESKTOPCONNECTION&lt;/not&gt;&lt;br&gt;     &lt;autogen&gt;--KeyToKey-- KeyCode::CONTROL_L, KeyCode::COMMAND_L&lt;/autogen&gt;&lt;br&gt;    &lt;/item&gt;&lt;br&gt;   &lt;/list&gt;&lt;br&gt;  &lt;/item&gt;&lt;br&gt; &lt;/list&gt;&lt;br&gt;&lt;/item&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;/code&gt;</pre>
]]></content:encoded>
			<wfw:commentRss>http://programming.jugglershu.net/wp/?feed=rss2&#038;p=549</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>HeapSort (C++ Template関数実装)</title>
		<link>http://programming.jugglershu.net/wp/?p=550</link>
		<comments>http://programming.jugglershu.net/wp/?p=550#comments</comments>
		<pubDate>Tue, 16 Aug 2011 16:42:00 +0000</pubDate>
		<dc:creator><![CDATA[shu]]></dc:creator>
				<category><![CDATA[Algorithm]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[HeapSort]]></category>

		<guid isPermaLink="false">http://programming.jugglershu.net/wp/?p=550</guid>
		<description><![CDATA[久しぶりに、プログラミング。今日はいままで自分で書いたことなかったヒープソート。 &#60;code&#62; &#60;br&#62;#ifndef __HEAPSORT_H__ &#60;br&#62;#define __HEAPSORT_H__ &#60;br&#62;&#60;br&#62;template &#60;typename t&#62;&#60;br&#62;void MaxHeapify( T* tar <a class="more-link" href="http://programming.jugglershu.net/wp/?p=550">続きを読む <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>久しぶりに、プログラミング。<br />今日はいままで自分で書いたことなかったヒープソート。</p>
<pre>&lt;code&gt;
&lt;br&gt;#ifndef __HEAPSORT_H__
&lt;br&gt;#define __HEAPSORT_H__
&lt;br&gt;&lt;br&gt;template &lt;typename t&gt;&lt;br&gt;void MaxHeapify( T* target, unsigned int index , unsigned int length) {
&lt;br&gt;	unsigned int l = index	unsigned int r = (index	unsigned int max = index;
&lt;br&gt;	if( l 		max = l;
&lt;br&gt;	}
&lt;br&gt;	if( r 		max = r;
&lt;br&gt;	}
&lt;br&gt;	if( index != max ){
&lt;br&gt;		T tmp = target[index];
&lt;br&gt;		target[index] = target[max];
&lt;br&gt;		target[max] = tmp;
&lt;br&gt;		MaxHeapify( target, max, length );	
&lt;br&gt;	}
&lt;br&gt;&lt;br&gt;	return;
&lt;br&gt;}
&lt;br&gt;&lt;br&gt;template &lt;typename t&gt;&lt;br&gt;void BuildMaxHeap( T* target, unsigned int length ){
&lt;br&gt;	for( unsigned int i = (length-1)/2; true ; i-- ){
&lt;br&gt;		MaxHeapify( target, i, length );
&lt;br&gt;		if( 0 == i ){
&lt;br&gt;			break;
&lt;br&gt;		}
&lt;br&gt;	}
&lt;br&gt;}
&lt;br&gt;&lt;br&gt;&lt;br&gt;template &lt;typename t&gt;&lt;br&gt;void HeapSort( T* target, unsigned int length){
&lt;br&gt;	BuildMaxHeap( target , length );
&lt;br&gt;	while(length != 0 ){
&lt;br&gt;		T tmp = target[length-1]; 
&lt;br&gt;		target[length-1] = target[0];
&lt;br&gt;		target[0] = tmp;
&lt;br&gt;		length--;
&lt;br&gt;		MaxHeapify(target, 0, length );
&lt;br&gt;	}
&lt;br&gt;}
&lt;br&gt;&lt;br&gt;#endif
&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;/typename&gt;&lt;/typename&gt;&lt;/typename&gt;&lt;/code&gt;</pre>
<p>includeしてから次ように使う。</p>
<pre>&lt;code&gt;
&lt;br&gt;unsigned char buf[] = {5,7,10,8,11};
&lt;br&gt;HeapSort( buf, 5 );
&lt;br&gt;//ここでbuf内はソート済み。
&lt;br&gt;&lt;/code&gt;</pre>
]]></content:encoded>
			<wfw:commentRss>http://programming.jugglershu.net/wp/?feed=rss2&#038;p=550</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>歩調がね</title>
		<link>http://programming.jugglershu.net/wp/?p=552</link>
		<comments>http://programming.jugglershu.net/wp/?p=552#comments</comments>
		<pubDate>Wed, 25 May 2011 17:43:00 +0000</pubDate>
		<dc:creator><![CDATA[shu]]></dc:creator>
				<category><![CDATA[未分類]]></category>

		<guid isPermaLink="false">http://programming.jugglershu.net/wp/?p=552</guid>
		<description><![CDATA[昔からなんとなく周りと歩調が合わないと感じる。みんなそういうのって気になっているのだろうか。何か、物事に対する結論の出し方と、それに従って行動するパターンがなにか違ってしまって、気がつくと自分だけ違うことしてる。 早すぎたり遅すぎたり。気にしすぎなのもしれないけど。 今日、だれかのつぶやきで、&#8212;&#8211;「決まってるから」「みんなそうだから」「いつもそうだから」じゃなくて、ちゃんと <a class="more-link" href="http://programming.jugglershu.net/wp/?p=552">続きを読む <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>昔からなんとなく周りと歩調が合わないと感じる。<br />みんなそういうのって気になっているのだろうか。<br />何か、物事に対する結論の出し方と、それに従って行動するパターンが<br />なにか違ってしまって、気がつくと自分だけ違うことしてる。</p>
<p>早すぎたり遅すぎたり。気にしすぎなのもしれないけど。</p>
<p>今日、だれかのつぶやきで、<br />&#8212;&#8211;<br />「決まってるから」「みんなそうだから」「いつもそうだから」じゃなくて、ちゃんと自分の頭で考えるっていうのを、みんなでもう一度取り戻した方がいいよね。<br />&#8212;&#8211;<br />というのが、あったのだけれど、どちらかというと僕はそれをやってないというより、できない。<br />周りの人たちが何を考えているかを察する能力が異常に低いのだと思う。</p>
<p>プログラマとかやっている人たちの中にはそういう人が多かったりする。</p>
]]></content:encoded>
			<wfw:commentRss>http://programming.jugglershu.net/wp/?feed=rss2&#038;p=552</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>実装時の設計確認</title>
		<link>http://programming.jugglershu.net/wp/?p=553</link>
		<comments>http://programming.jugglershu.net/wp/?p=553#comments</comments>
		<pubDate>Mon, 23 May 2011 05:28:00 +0000</pubDate>
		<dc:creator><![CDATA[shu]]></dc:creator>
				<category><![CDATA[未分類]]></category>

		<guid isPermaLink="false">http://programming.jugglershu.net/wp/?p=553</guid>
		<description><![CDATA[これは個人的なTIPSとして、プログラムを書くときに、詳細設計がきちんとできていて、将来に渡ってメンテナンスしやすいかどうかの判断基準として、気を付けていることのメモ。 二つあって、どちらも同じような目的のために確認している。 １つ目は、後からテストコードを書く場合は、テストコードがどのように実行できるかを想像しながら実装する。すると、テストしたい部分を自然に切り離しながら実装したくなる。自動的に <a class="more-link" href="http://programming.jugglershu.net/wp/?p=553">続きを読む <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>これは個人的なTIPSとして、プログラムを書くときに、詳細設計がきちんとできていて、将来に渡ってメンテナンスしやすいかどうかの判断基準として、気を付けていることのメモ。</p>
<p>二つあって、どちらも同じような目的のために確認している。</p>
<p>１つ目は、後からテストコードを書く場合は、テストコードがどのように実行できるかを想像しながら実装する。すると、テストしたい部分を自然に切り離しながら実装したくなる。自動的にテストしにくい部分がどんどん一か所にまとめられていって、結果として後からいろいろ変更したり、機能追加がしやすくなる。</p>
<p>２つ目は、今追加しようとしている機能をOFFにしようとしたとき、どれくらいの場所を修正しなくてはいけないかを考える。１行コメントアウトするだけでそれができるのがベスト。できなくても、１ファイルの１ブロック（画面内で確認できる範囲）を修正すれば機能をOFFにできればまあ、問題ないレベル。<br />１ファイルの複数個所、という場合には、まず設計を見直す。OSの仕組みなどにより、どうしてもそうせざる負えない場合には、よくコメントを書いておくなりドキュメントしておくなりしないといけない。<br />複数ファイルを直さなきゃいけない場合は、１度よく設計を考え直した方がいいかもしれない。もうそれしか方法がないときだけ、コメントを付けて、どことどこに対応関係があるかを書いておく。<br />複数ファイルの複数個所を直さないと機能をOFFにできないとか、こういう状況になったら、そもそも何かがおかしいと思った方がいい。だいたい１つのファイルに複数の機能が同時に実装されていたり、２つのファイル（モジュール）が互いに依存しあっていたり、機能の定義があいまいだったりするのが原因で、その後その上にいろいろ機能を追加していけばしていくほど、バグは多くなる。</p>
]]></content:encoded>
			<wfw:commentRss>http://programming.jugglershu.net/wp/?feed=rss2&#038;p=553</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>RTX1000の設定 &#8211; シリアル接続がない場合</title>
		<link>http://programming.jugglershu.net/wp/?p=554</link>
		<comments>http://programming.jugglershu.net/wp/?p=554#comments</comments>
		<pubDate>Tue, 29 Mar 2011 21:53:00 +0000</pubDate>
		<dc:creator><![CDATA[shu]]></dc:creator>
				<category><![CDATA[RARPD]]></category>
		<category><![CDATA[RTX1000]]></category>

		<guid isPermaLink="false">http://programming.jugglershu.net/wp/?p=554</guid>
		<description><![CDATA[自宅でYAMAHAのルータ RTX1000を使っている。このルータ、業務用だけあってユーザフレンドリでは全くない。設定はコマンドラインで行うことになっているし、コマンドも技術的なことが分かってないと何もできないぐらい難しい。 さて、このルータ、初期状態だとIPアドレスが振られていない。つまり自宅のネットワークに繋いでも、そこにIP層レベルのアクセスはできない。じゃあ、どうやってIPアドレスを振るの <a class="more-link" href="http://programming.jugglershu.net/wp/?p=554">続きを読む <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>自宅でYAMAHAのルータ RTX1000を使っている。<br />このルータ、業務用だけあってユーザフレンドリでは全くない。<br />設定はコマンドラインで行うことになっているし、コマンドも技術的なことが分かってないと何もできないぐらい難しい。</p>
<p>さて、このルータ、初期状態だとIPアドレスが振られていない。つまり自宅のネットワークに繋いでも、そこにIP層レベルのアクセスはできない。<br />じゃあ、どうやってIPアドレスを振るのかといえば、基本的にはシリアルケーブルを繋いで、terminal経由で設定する。<br />ただ、いまどきシリアル端子なんて持ってるPCの方が少ない。僕の使ってるPCも例外ではなくそんなものはもってない。</p>
<p>以前に設定したときは、USBとシリアルの変換コネクタとケーブルを買ってきて設定した。<br />今回、もう一つ新しくRTX1000を買って、実家とのVPN接続をさせておこうと考え、設定しようとしたのだが、昔買ったはずのケーブルが見つからない。</p>
<p>で、そういう場合にRARPDを用いてIPアドレスを振る方法があるということを知り、今回やってみた。</p>
<p>基本的には以下のページの通り。<br /><a href="http://www.inohome.net/kuma/blog/archives/2006/12/post_606.html">http://www.inohome.net/kuma/blog/archives/2006/12/post_606.html</a></p>
<p>ただし、1つはまったところがあったのでメモ。<br />ここで使っているRARPDというソフトウェアが「No unique Registry key for TCP/IP over LAN」というエラーを出して終了してしまう。<br />レジストリキーが複数あるってことなんだろうけど、よく分からない。<br />うれしいことに、RAPRDにはソースコードが付いてくる。というわけで見てみると、どうやらEthernetのインターフェースをレジストリから探していて、それが複数見つかった場合にはエラーを出すらしいと言うことが分かった。</p>
<p>確かに、僕のPCにはEthernetアダプタが2つついている。VMWareの仮想デバイスとかもあるから、その辺りも関係しているかもしれない。</p>
<p>ということで、メインのネットワーク以外はすべて無効にした。</p>
<div><a href="http://3.bp.blogspot.com/-W135ViMJ0k4/TZJUeCMaziI/AAAAAAAAAHo/IMwOP9XCwck/s1600/net.PNG" imageanchor="1"><img border="0" height="178" src="http://3.bp.blogspot.com/-W135ViMJ0k4/TZJUeCMaziI/AAAAAAAAAHo/IMwOP9XCwck/s320/net.PNG" width="320"></a></div>
<p>こんな感じで。それで起動したらちゃんと動いて、みごとにRTX1000にIPアドレスを振ることができた。</p>
<p>これができればRTX1000を設定するのにシリアル端子は必要ないってことだ。</p>
]]></content:encoded>
			<wfw:commentRss>http://programming.jugglershu.net/wp/?feed=rss2&#038;p=554</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>東北太平洋沖地震</title>
		<link>http://programming.jugglershu.net/wp/?p=555</link>
		<comments>http://programming.jugglershu.net/wp/?p=555#comments</comments>
		<pubDate>Mon, 14 Mar 2011 05:18:00 +0000</pubDate>
		<dc:creator><![CDATA[shu]]></dc:creator>
				<category><![CDATA[未分類]]></category>

		<guid isPermaLink="false">http://programming.jugglershu.net/wp/?p=555</guid>
		<description><![CDATA[被災状況をテレビで見るのが辛い。親を亡くした子供、目の前で自分の奥さんが流されてしまった人、自分の娘が流されてしまった人、そんな辛い状況がどこにあるだろうか。見ていられないぐらいに悲しい。 今回は、東京にいながら、その恐怖を感じたせいか、その悲しさがものすごく大きい。今回もある意味では、僕が感じられることは人ごとレベルでしかないのだろう。結局東京ではその悲惨さはわからないかもしれない。それでも今ま <a class="more-link" href="http://programming.jugglershu.net/wp/?p=555">続きを読む <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>被災状況をテレビで見るのが辛い。<br />親を亡くした子供、目の前で自分の奥さんが流されてしまった人、自分の娘が流されてしまった人、そんな辛い状況がどこにあるだろうか。見ていられないぐらいに悲しい。</p>
<p>今回は、東京にいながら、その恐怖を感じたせいか、その悲しさがものすごく大きい。<br />今回もある意味では、僕が感じられることは人ごとレベルでしかないのだろう。<br />結局東京ではその悲惨さはわからないかもしれない。それでも今まで感じたものよりずっと大きな感情的な動きがある。</p>
<p>一人でも多くの人が助かってほしいと思う。</p>
<p>こういうことを目の当たりにすると、僕たちが普段考えている幸せや、生きていく上で大切なことが何なのかということを考えさせられる。<br />人が、その人の一生を豊かに、幸せに生きていくと言うことと、自分が今毎日の生活の中で行っていることの間に大きな忘れ去られた空間が広がっているのではないだろうかと感じた。<br />忘れてしまうのだと思う。</p>
<p>家族とともに、いろんな困難を乗り越えて毎日生きていくこと、生きていけること。それが何より重要なことであり、それがすべてなのだと思った。それ以外のことは、おまけみたいなものなんだ。</p>
]]></content:encoded>
			<wfw:commentRss>http://programming.jugglershu.net/wp/?feed=rss2&#038;p=555</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
