aboutsummaryrefslogtreecommitdiffhomepage
path: root/public/posts/2021-10-02
diff options
context:
space:
mode:
Diffstat (limited to 'public/posts/2021-10-02')
-rw-r--r--public/posts/2021-10-02/cpp-you-can-use-keywords-in-attributes/index.html12
-rw-r--r--public/posts/2021-10-02/python-unbound-local-error/index.html18
-rw-r--r--public/posts/2021-10-02/ruby-detect-running-implementation/index.html12
-rw-r--r--public/posts/2021-10-02/ruby-then-keyword-and-case-in/index.html68
-rw-r--r--public/posts/2021-10-02/rust-where-are-primitive-types-from/index.html36
-rw-r--r--public/posts/2021-10-02/vim-difference-between-autocmd-bufwrite-and-bufwritepre/index.html30
-rw-r--r--public/posts/2021-10-02/vim-swap-order-of-selected-lines/index.html24
7 files changed, 66 insertions, 134 deletions
diff --git a/public/posts/2021-10-02/cpp-you-can-use-keywords-in-attributes/index.html b/public/posts/2021-10-02/cpp-you-can-use-keywords-in-attributes/index.html
index ae44da9..ed91b45 100644
--- a/public/posts/2021-10-02/cpp-you-can-use-keywords-in-attributes/index.html
+++ b/public/posts/2021-10-02/cpp-you-can-use-keywords-in-attributes/index.html
@@ -56,8 +56,7 @@
タイトル落ち。まずはこのコードを見て欲しい。
</p>
- <pre class="highlight" language="cpp" linenumbering="unnumbered">
- <code>#include &lt;iostream&gt;
+ <pre class="highlight" language="cpp" linenumbering="unnumbered"><code>#include &lt;iostream&gt;
[[alignas]] [[alignof]] [[and]] [[and_eq]] [[asm]] [[auto]] [[bitand]]
[[bitor]] [[bool]] [[break]] [[case]] [[catch]] [[char]] [[char16_t]]
@@ -75,8 +74,7 @@
// [[using]]
int main() {
std::cout &lt;&lt; &quot;Hello, World!&quot; &lt;&lt; std::endl;
-}</code>
- </pre>
+}</code></pre>
<blockquote>
<p>
@@ -126,10 +124,8 @@ std::cout &lt;&lt; &quot;Hello, World!&quot; &lt;&lt; std::endl;
上のコードでは<code>[[using]]</code>をコメントアウトしているが、これは<code>using</code>キーワードのみ属性構文の中で意味を持つからであり、このコメントアウトを外すとコンパイルに失敗する。
</p>
- <pre class="highlight" language="cpp" linenumbering="unnumbered">
- <code>// using の例
-[[using foo: attr1, attr2]] int x; // [[foo::attr1, foo::attr2]] の糖衣構文</code>
- </pre>
+ <pre class="highlight" language="cpp" linenumbering="unnumbered"><code>// using の例
+[[using foo: attr1, attr2]] int x; // [[foo::attr1, foo::attr2]] の糖衣構文</code></pre>
<p>
C++17 の仕様も見てみる (正確には標準化前のドラフト)。
diff --git a/public/posts/2021-10-02/python-unbound-local-error/index.html b/public/posts/2021-10-02/python-unbound-local-error/index.html
index 27c2d05..0516d6f 100644
--- a/public/posts/2021-10-02/python-unbound-local-error/index.html
+++ b/public/posts/2021-10-02/python-unbound-local-error/index.html
@@ -60,15 +60,13 @@
Python でクロージャを作ろうと、次のようなコードを書いた。
</p>
- <pre class="highlight" language="python" linenumbering="unnumbered">
- <code>def f():
+ <pre class="highlight" language="python" linenumbering="unnumbered"><code>def f():
x = 0
def g():
x += 1
g()
-f()</code>
- </pre>
+f()</code></pre>
<p>
関数<code>g</code>から 関数<code>f</code>のスコープ内で定義された変数<code>x</code>を参照し、それに 1 を足そうとしている。 これを実行すると<code>x += 1</code>の箇所でエラーが発生する。
@@ -84,8 +82,7 @@ f()</code>
local変数<code>x</code>が代入前に参照された、とある。これは、<code>f</code>の<code>x</code>を参照するのではなく、新しく別の変数を<code>g</code>内に作ってしまっているため。 前述のコードを宣言と代入を便宜上分けて書き直すと次のようになる。<code>var</code>を変数宣言のための構文として擬似的に利用している。
</p>
- <pre class="highlight" language="python" linenumbering="unnumbered">
- <code># 注: var は正しい Python の文法ではない。上記参照のこと
+ <pre class="highlight" language="python" linenumbering="unnumbered"><code># 注: var は正しい Python の文法ではない。上記参照のこと
def f():
var x # f の local変数 &apos;x&apos; を宣言
x = 0 # x に 0 を代入
@@ -94,21 +91,18 @@ var x # g の local変数 &apos;x&apos; を宣言
# たまたま f にも同じ名前の変数があるが、それとは別の変数
x += 1 # x に 1 を加算 (x = x + 1 の糖衣構文)
# 加算する前の値を参照しようとするが、まだ代入されていないためエラー
-g()</code>
- </pre>
+g()</code></pre>
<p>
当初の意図を表現するには、次のように書けばよい。
</p>
- <pre class="highlight" language="python" linenumbering="unnumbered">
- <code>def f():
+ <pre class="highlight" language="python" linenumbering="unnumbered"><code>def f():
x = 0
def g():
nonlocal x ## (*)
x += 1
-g()</code>
- </pre>
+g()</code></pre>
<p>
<code>(*)</code>のように、<code>nonlocal</code>を追加する。これにより一つ外側のスコープ (<code>g</code>の一つ外側 =<code>f</code>) で定義されている<code>x</code>を探しに行くようになる。
diff --git a/public/posts/2021-10-02/ruby-detect-running-implementation/index.html b/public/posts/2021-10-02/ruby-detect-running-implementation/index.html
index ed7ccd5..1163674 100644
--- a/public/posts/2021-10-02/ruby-detect-running-implementation/index.html
+++ b/public/posts/2021-10-02/ruby-detect-running-implementation/index.html
@@ -65,14 +65,12 @@
上記ページの例から引用する:
</p>
- <pre class="highlight" language="shell-session" linenumbering="unnumbered">
- <code>$ ruby-1.9.1 -ve &apos;p RUBY_ENGINE&apos;
+ <pre class="highlight" language="shell-session" linenumbering="unnumbered"><code>$ ruby-1.9.1 -ve &apos;p RUBY_ENGINE&apos;
ruby 1.9.1p0 (2009-03-04 revision 22762) [x86_64-linux]
&quot;ruby&quot;
$ jruby -ve &apos;p RUBY_ENGINE&apos;
jruby 1.2.0 (ruby 1.8.6 patchlevel 287) (2009-03-16 rev 9419) [i386-java]
-&quot;jruby&quot;</code>
- </pre>
+&quot;jruby&quot;</code></pre>
<p>
それぞれの処理系がどのような値を返すかだが、stack overflow に良い質問と回答があった。
@@ -192,12 +190,10 @@ jruby 1.2.0 (ruby 1.8.6 patchlevel 287) (2009-03-16 rev 9419) [i386-java]
<a href="https://github.com/mruby/mruby/blob/ed29d74bfd95362eaeb946fcf7e865d80346b62b/include/mruby/version.h#L32-L35">mruby 該当部分のソース</a>より引用:
</p>
- <pre class="highlight" language="c" linenumbering="unnumbered">
- <code>/*
+ <pre class="highlight" language="c" linenumbering="unnumbered"><code>/*
* Ruby engine.
*/
-#define MRUBY_RUBY_ENGINE &quot;mruby&quot;</code>
- </pre>
+#define MRUBY_RUBY_ENGINE &quot;mruby&quot;</code></pre>
</div>
</article>
</main>
diff --git a/public/posts/2021-10-02/ruby-then-keyword-and-case-in/index.html b/public/posts/2021-10-02/ruby-then-keyword-and-case-in/index.html
index 9b1df47..ed8d9e8 100644
--- a/public/posts/2021-10-02/ruby-then-keyword-and-case-in/index.html
+++ b/public/posts/2021-10-02/ruby-then-keyword-and-case-in/index.html
@@ -65,20 +65,17 @@
使われることは稀だが、Ruby では<code>then</code>がキーワードになっている。次のように使う:
</p>
- <pre class="highlight" language="ruby" linenumbering="unnumbered">
- <code>if cond then
+ <pre class="highlight" language="ruby" linenumbering="unnumbered"><code>if cond then
puts &quot;Y&quot;
else
puts &quot;N&quot;
- end</code>
- </pre>
+ end</code></pre>
<p>
このキーワードが現れうる場所はいくつかあり、<code>if</code>、<code>unless</code>、<code>rescue</code>、<code>case</code>構文がそれに当たる。 上記のように、何か条件を書いた後<code>then</code>を置き、式がそこで終了していることを示すマーカーとして機能する。
</p>
- <pre class="highlight" language="ruby" linenumbering="unnumbered">
- <code># Example:
+ <pre class="highlight" language="ruby" linenumbering="unnumbered"><code># Example:
if x then
a
@@ -97,8 +94,7 @@ end
case x
when p then
a
-end</code>
- </pre>
+end</code></pre>
</section>
<section id="section--_なぜ普段は書かなくてもよいのか">
@@ -107,21 +103,17 @@ end</code>
普通 Ruby のコードで<code>then</code>を書くことはない。なぜか。次のコードを実行してみるとわかる。
</p>
- <pre class="highlight" language="ruby" linenumbering="unnumbered">
- <code>if true puts &apos;Hello, World!&apos; end</code>
- </pre>
+ <pre class="highlight" language="ruby" linenumbering="unnumbered"><code>if true puts &apos;Hello, World!&apos; end</code></pre>
<p>
次のような構文エラーが出力される。
</p>
- <pre class="monospaced highlight">
- <code>20:1: syntax error, unexpected local variable or method, expecting `then&apos; or &apos;;&apos; or &apos;\n&apos;
+ <pre class="monospaced highlight"><code>20:1: syntax error, unexpected local variable or method, expecting `then&apos; or &apos;;&apos; or &apos;\n&apos;
if true puts &apos;Hello, World!&apos; end
^~~~
20:1: syntax error, unexpected `end&apos;, expecting end-of-input
- ...f true puts &apos;Hello, World!&apos; end</code>
- </pre>
+ ...f true puts &apos;Hello, World!&apos; end</code></pre>
<p>
二つ目のメッセージは無視して一つ目を読むと、<code>then</code>か<code>;</code>か改行が来るはずのところ変数だかメソッドだかが現れたことによりエラーとなっているようだ。
@@ -131,10 +123,8 @@ end</code>
ポイントは改行が<code>then</code>(や<code>;</code>) の代わりとなることである。<code>true</code>の後に改行を入れてみる。
</p>
- <pre class="highlight" language="ruby" linenumbering="unnumbered">
- <code>if true
-puts &apos;Hello, World!&apos; end</code>
- </pre>
+ <pre class="highlight" language="ruby" linenumbering="unnumbered"><code>if true
+puts &apos;Hello, World!&apos; end</code></pre>
<p>
無事 Hello, World! と出力されるようになった。
@@ -147,27 +137,21 @@ puts &apos;Hello, World!&apos; end</code>
なぜ<code>then</code>や<code>;</code>や改行 (以下 「<code>then</code>等」) が必要なのだろうか。次の例を見てほしい:
</p>
- <pre class="highlight" language="ruby" linenumbering="unnumbered">
- <code>if a b end</code>
- </pre>
+ <pre class="highlight" language="ruby" linenumbering="unnumbered"><code>if a b end</code></pre>
<p>
<code>then</code>も<code>;</code>も改行もないのでエラーになるが、これは条件式がどこまで続いているのかわからないためだ。 この例は二通りに解釈できる。
</p>
- <pre class="highlight" language="ruby" linenumbering="unnumbered">
- <code># a という変数かメソッドの評価結果が truthy なら b という変数かメソッドを評価
+ <pre class="highlight" language="ruby" linenumbering="unnumbered"><code># a という変数かメソッドの評価結果が truthy なら b という変数かメソッドを評価
if a then
b
-end</code>
- </pre>
+end</code></pre>
- <pre class="highlight" language="ruby" linenumbering="unnumbered">
- <code># a というメソッドに b という変数かメソッドの評価結果を渡して呼び出し、
+ <pre class="highlight" language="ruby" linenumbering="unnumbered"><code># a というメソッドに b という変数かメソッドの評価結果を渡して呼び出し、
# その結果が truthy なら何もしない
if a(b) then
-end</code>
- </pre>
+end</code></pre>
<p>
<code>then</code>等はこの曖昧性を排除するためにあり、条件式は<code>if</code>から<code>then</code>等までの間にある、ということを明確にする。 C系の<code>if</code>後に来る<code>(</code>/<code>)</code>や、Python の<code>:</code>、Rust/Go/Swift などの<code>{</code>も同じ役割を持つ。
@@ -188,8 +172,7 @@ end</code>
<a href="https://github.com/ruby/ruby/blob/221ca0f8281d39f0dfdfe13b2448875384bbf735/parse.y#L3961-L3986">https://github.com/ruby/ruby/blob/221ca0f8281d39f0dfdfe13b2448875384bbf735/parse.y#L3961-L3986</a>
</p>
- <pre class="highlight" language="yacc" linenumbering="unnumbered">
- <code>p_case_body : keyword_in
+ <pre class="highlight" language="yacc" linenumbering="unnumbered"><code>p_case_body : keyword_in
{
SET_LEX_STATE(EXPR_BEG|EXPR_LABEL);
p-&gt;command_start = FALSE;
@@ -214,17 +197,14 @@ end</code>
/*% %*/
/*% ripper: in!($4, $7, escape_Qundef($8)) %*/
}
- ;</code>
- </pre>
+ ;</code></pre>
<p>
簡略版:
</p>
- <pre class="highlight" language="yacc" linenumbering="unnumbered">
- <code>p_case_body : keyword_in p_top_expr then compstmt p_cases
-;</code>
- </pre>
+ <pre class="highlight" language="yacc" linenumbering="unnumbered"><code>p_case_body : keyword_in p_top_expr then compstmt p_cases
+;</code></pre>
<p>
ここで、<code>keyword_in</code>は文字通り<code>in</code>、<code>p_top_expr</code>はいわゆるパターン、<code>then</code>は<code>then</code>キーワードのことではなく、この記事で<code>then</code>等と呼んでいるもの、つまり<code>then</code>キーワード、<code>;</code>、改行のいずれかである。
@@ -234,8 +214,7 @@ end</code>
これにより、<code>case</code>-<code>when</code>による従来の構文と同じように、<code>then</code>等をパターンの後ろに挿入すればよいことがわかった。つまり次の3通りのいずれかになる:
</p>
- <pre class="highlight" language="ruby" linenumbering="unnumbered">
- <code>case x
+ <pre class="highlight" language="ruby" linenumbering="unnumbered"><code>case x
in 1 then a
in 2 then b
in 3 then c
@@ -254,20 +233,17 @@ case x
in 1; a
in 2; b
in 3; c
-end</code>
- </pre>
+end</code></pre>
<p>
ところで、<code>p_top_expr</code>には<code>if</code>による guard clause が書けるので、その場合は<code>if</code>-<code>then</code>と似たような見た目になる。
</p>
- <pre class="highlight" language="ruby" linenumbering="unnumbered">
- <code>case x
+ <pre class="highlight" language="ruby" linenumbering="unnumbered"><code>case x
in 0 then a
in n if n &lt; 0 then b
in n then c
-end</code>
- </pre>
+end</code></pre>
</section>
<section id="section--_まとめ">
diff --git a/public/posts/2021-10-02/rust-where-are-primitive-types-from/index.html b/public/posts/2021-10-02/rust-where-are-primitive-types-from/index.html
index 8bcb923..5b1f86a 100644
--- a/public/posts/2021-10-02/rust-where-are-primitive-types-from/index.html
+++ b/public/posts/2021-10-02/rust-where-are-primitive-types-from/index.html
@@ -55,8 +55,7 @@
Rust において、プリミティブ型の名前は予約語でない。したがって、次のコードは合法である。
</p>
- <pre class="highlight" language="rust" linenumbering="unnumbered">
- <code>#![allow(non_camel_case_types)]
+ <pre class="highlight" language="rust" linenumbering="unnumbered"><code>#![allow(non_camel_case_types)]
#![allow(dead_code)]
struct bool;
@@ -75,8 +74,7 @@ struct u128;
struct usize;
struct f32;
struct f64;
-struct str;</code>
- </pre>
+struct str;</code></pre>
<p>
では、普段単に<code>bool</code>と書いたとき、この<code>bool</code>は一体どこから来ているのか。rustc のソースを追ってみた。
@@ -111,34 +109,29 @@ struct str;</code>
<code>rustc</code>はセルフホストされている (=<code>rustc</code>自身が Rust で書かれている) ので、<code>bool</code>や<code>char</code>などで適当に検索をかけてもノイズが多すぎて話にならない。 しかし、お誂え向きなことに<code>i128</code>/<code>u128</code>というコンパイラ自身が使うことがなさそうな型が存在するのでこれを使って<code>git grep</code>してみる。
</p>
- <pre class="monospaced highlight">
- <code>$ git grep &quot;\bi128\b&quot; | wc # i128
+ <pre class="monospaced highlight"><code>$ git grep &quot;\bi128\b&quot; | wc # i128
165 1069 15790
$ git grep &quot;\bu128\b&quot; | wc # u128
293 2127 26667
$ git grep &quot;\bbool\b&quot; | wc # cf. bool の結果
-3563 23577 294659</code>
- </pre>
+3563 23577 294659</code></pre>
<p>
165 程度であれば探すことができそうだ。今回は、クレート名を見ておおよその当たりをつけた。
</p>
- <pre class="monospaced highlight">
- <code>$ git grep &quot;\bi128\b&quot;
+ <pre class="monospaced highlight"><code>$ git grep &quot;\bi128\b&quot;
...
rustc_resolve/src/lib.rs: table.insert(sym::i128, Int(IntTy::I128));
-...</code>
- </pre>
+...</code></pre>
<p>
<code>rustc_resolve</code>というのはいかにも名前解決を担いそうなクレート名である。該当箇所を見てみる。
</p>
- <pre class="highlight" language="rust" linenumbering="unnumbered">
- <code>/// Interns the names of the primitive types.
+ <pre class="highlight" language="rust" linenumbering="unnumbered"><code>/// Interns the names of the primitive types.
///
/// All other types are defined somewhere and possibly imported, but the primitive ones need
/// special handling, since they have no place of origin.
@@ -169,8 +162,7 @@ table.insert(sym::u64, Uint(UintTy::U64));
table.insert(sym::u128, Uint(UintTy::U128));
Self { primitive_types: table }
}
-}</code>
- </pre>
+}</code></pre>
<p>
これは初めに列挙したプリミティブ型の一覧と一致している。doc comment にも、
@@ -186,8 +178,7 @@ Self { primitive_types: table }
とある。次はこの struct の使用箇所を追う。追うと言っても使われている箇所は次の一箇所しかない。なお説明に不要な箇所は大きく削っている。
</p>
- <pre class="highlight" language="rust" linenumbering="unnumbered">
- <code> /// This resolves the identifier `ident` in the namespace `ns` in the current lexical scope.
+ <pre class="highlight" language="rust" linenumbering="unnumbered"><code> /// This resolves the identifier `ident` in the namespace `ns` in the current lexical scope.
/// (略)
fn resolve_ident_in_lexical_scope(
&amp;mut self,
@@ -207,8 +198,7 @@ return Some(LexicalScopeBinding::Item(binding));
}
None
-}</code>
- </pre>
+}</code></pre>
<p>
関数名や doc comment が示している通り、この関数は識別子 (identifier, ident) を現在のレキシカルスコープ内で解決 (resolve) する。<code>if ns == TypeNS</code>のブロック内では、<code>primitive_type_table</code>(上記の<code>PrimitiveTypeTable::new()</code>で作られた変数) に含まれている識別子 (<code>bool</code>、<code>i32</code>など) かどうか判定し、そうであればそれに紐づけられたプリミティブ型を返している。
@@ -226,15 +216,13 @@ None
動作がわかったところで、例として次のコードを考える。
</p>
- <pre class="highlight" language="rust" linenumbering="unnumbered">
- <code>#![allow(non_camel_case_types)]
+ <pre class="highlight" language="rust" linenumbering="unnumbered"><code>#![allow(non_camel_case_types)]
struct bool;
fn main() {
let _: bool = bool;
-}</code>
- </pre>
+}</code></pre>
<p>
ここで<code>main()</code>の<code>bool</code>は<code>struct bool</code>として解決される。なぜなら、プリミティブ型の判定をする前に<code>bool</code>という名前の別の型が見つかるからだ。
diff --git a/public/posts/2021-10-02/vim-difference-between-autocmd-bufwrite-and-bufwritepre/index.html b/public/posts/2021-10-02/vim-difference-between-autocmd-bufwrite-and-bufwritepre/index.html
index db28b1c..8e34b4d 100644
--- a/public/posts/2021-10-02/vim-difference-between-autocmd-bufwrite-and-bufwritepre/index.html
+++ b/public/posts/2021-10-02/vim-difference-between-autocmd-bufwrite-and-bufwritepre/index.html
@@ -112,30 +112,24 @@
<a href="https://github.com/vim/vim/blob/8e6be34338f13a6a625f19bcef82019c9adc65f2/src/autocmd.c#L85-L86">https://github.com/vim/vim/blob/8e6be34338f13a6a625f19bcef82019c9adc65f2/src/autocmd.c#L85-L86</a>
</p>
- <pre class="highlight" language="c" linenumbering="unnumbered">
- <code> {&quot;BufAdd&quot;, EVENT_BUFADD},
-{&quot;BufCreate&quot;, EVENT_BUFADD},</code>
- </pre>
+ <pre class="highlight" language="c" linenumbering="unnumbered"><code> {&quot;BufAdd&quot;, EVENT_BUFADD},
+{&quot;BufCreate&quot;, EVENT_BUFADD},</code></pre>
<p>
<a href="https://github.com/vim/vim/blob/8e6be34338f13a6a625f19bcef82019c9adc65f2/src/autocmd.c#L95-L97">https://github.com/vim/vim/blob/8e6be34338f13a6a625f19bcef82019c9adc65f2/src/autocmd.c#L95-L97</a>
</p>
- <pre class="highlight" language="c" linenumbering="unnumbered">
- <code> {&quot;BufRead&quot;, EVENT_BUFREADPOST},
+ <pre class="highlight" language="c" linenumbering="unnumbered"><code> {&quot;BufRead&quot;, EVENT_BUFREADPOST},
{&quot;BufReadCmd&quot;, EVENT_BUFREADCMD},
-{&quot;BufReadPost&quot;, EVENT_BUFREADPOST},</code>
- </pre>
+{&quot;BufReadPost&quot;, EVENT_BUFREADPOST},</code></pre>
<p>
<a href="https://github.com/vim/vim/blob/8e6be34338f13a6a625f19bcef82019c9adc65f2/src/autocmd.c#L103-L105">https://github.com/vim/vim/blob/8e6be34338f13a6a625f19bcef82019c9adc65f2/src/autocmd.c#L103-L105</a>
</p>
- <pre class="highlight" language="c" linenumbering="unnumbered">
- <code> {&quot;BufWrite&quot;, EVENT_BUFWRITEPRE},
+ <pre class="highlight" language="c" linenumbering="unnumbered"><code> {&quot;BufWrite&quot;, EVENT_BUFWRITEPRE},
{&quot;BufWritePost&quot;, EVENT_BUFWRITEPOST},
-{&quot;BufWritePre&quot;, EVENT_BUFWRITEPRE},</code>
- </pre>
+{&quot;BufWritePre&quot;, EVENT_BUFWRITEPRE},</code></pre>
</section>
<section id="section--_neovim_のソースコード">
@@ -148,24 +142,20 @@
<a href="https://github.com/neovim/neovim/blob/71d4f5851f068eeb432af34850dddda8cc1c71e3/src/nvim/auevents.lua#L119-L124">https://github.com/neovim/neovim/blob/71d4f5851f068eeb432af34850dddda8cc1c71e3/src/nvim/auevents.lua#L119-L124</a>
</p>
- <pre class="highlight" language="lua" linenumbering="unnumbered">
- <code> aliases = {
+ <pre class="highlight" language="lua" linenumbering="unnumbered"><code> aliases = {
BufCreate = &apos;BufAdd&apos;,
BufRead = &apos;BufReadPost&apos;,
BufWrite = &apos;BufWritePre&apos;,
FileEncoding = &apos;EncodingChanged&apos;,
-},</code>
- </pre>
+},</code></pre>
<p>
ところで、上では取り上げなかった<code>FileEncoding</code>だが、これは<code>:help FileEncoding</code>にしっかりと書いてある。
</p>
- <pre class="monospaced highlight">
- <code> *FileEncoding*
+ <pre class="monospaced highlight"><code> *FileEncoding*
FileEncoding Obsolete. It still works and is equivalent
-to |EncodingChanged|.</code>
- </pre>
+to |EncodingChanged|.</code></pre>
</section>
<section id="section--_まとめ">
diff --git a/public/posts/2021-10-02/vim-swap-order-of-selected-lines/index.html b/public/posts/2021-10-02/vim-swap-order-of-selected-lines/index.html
index 8a3b304..f4e2b71 100644
--- a/public/posts/2021-10-02/vim-swap-order-of-selected-lines/index.html
+++ b/public/posts/2021-10-02/vim-swap-order-of-selected-lines/index.html
@@ -115,11 +115,9 @@
なお、<code>:g/^/m0</code>は全ての行を入れ替えるが、<code>:N,Mg/^/mN-1</code>とすることで N行目から M行目を処理範囲とするよう拡張できる。手でこれを入力するわけにはいかないので、次のようなコマンドを用意する。
</p>
- <pre class="highlight" language="vim" linenumbering="unnumbered">
- <code>command! -bar -range=%
+ <pre class="highlight" language="vim" linenumbering="unnumbered"><code>command! -bar -range=%
\ Reverse
-\ &lt;line1&gt;,&lt;line2&gt;g/^/m&lt;line1&gt;-1</code>
- </pre>
+\ &lt;line1&gt;,&lt;line2&gt;g/^/m&lt;line1&gt;-1</code></pre>
<p>
これは望みの動作をするが、実際に実行してみると全行がハイライトされてしまう。次節で詳細を述べる。
@@ -152,15 +150,13 @@
前述した<code>:Reverse</code>コマンドの定義を少し変えて、次のようにする:
</p>
- <pre class="highlight" language="vim" linenumbering="unnumbered">
- <code>function! s:reverse_lines(from, to) abort
+ <pre class="highlight" language="vim" linenumbering="unnumbered"><code>function! s:reverse_lines(from, to) abort
execute printf(&quot;%d,%dg/^/m%d&quot;, a:from, a:to, a:from - 1)
endfunction
command! -bar -range=%
\ Reverse
- \ call &lt;SID&gt;reverse_lines(&lt;line1&gt;, &lt;line2&gt;)</code>
- </pre>
+ \ call &lt;SID&gt;reverse_lines(&lt;line1&gt;, &lt;line2&gt;)</code></pre>
<p>
実行しているコマンドが変わったわけではないが、関数呼び出しを経由するようにした。これだけで前述の問題が解決する。
@@ -211,11 +207,9 @@
</p>
</blockquote>
- <pre class="highlight" language="vim" linenumbering="unnumbered">
- <code>command! -bar -range=%
+ <pre class="highlight" language="vim" linenumbering="unnumbered"><code>command! -bar -range=%
\ Reverse
- \ keeppatterns &lt;line1&gt;,&lt;line2&gt;g/^/m&lt;line1&gt;-1</code>
- </pre>
+ \ keeppatterns &lt;line1&gt;,&lt;line2&gt;g/^/m&lt;line1&gt;-1</code></pre>
<p>
まさにこのための Exコマンド、<code>:keeppatterns</code>が存在する。<code>:keeppatterns {command}</code>のように使い、読んで字の如く、後ろに続く Exコマンドを「現在の検索パターンを保ったまま」実行する。はるかに分かりやすく意図を表現できる。
@@ -230,13 +224,11 @@
<section id="section--_コピペ用再掲">
<h2><a href="#section--_コピペ用再掲">コピペ用再掲</a></h2>
- <pre class="highlight" language="vim" linenumbering="unnumbered">
- <code>&quot; License: Public Domain
+ <pre class="highlight" language="vim" linenumbering="unnumbered"><code>&quot; License: Public Domain
command! -bar -range=%
\ Reverse
- \ keeppatterns &lt;line1&gt;,&lt;line2&gt;g/^/m&lt;line1&gt;-1</code>
- </pre>
+ \ keeppatterns &lt;line1&gt;,&lt;line2&gt;g/^/m&lt;line1&gt;-1</code></pre>
</section>
</div>
</article>