From db3d51ddc421dad68abddb95d01ffdab440197d6 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 19 Mar 2023 03:24:43 +0900 Subject: feat(content): specify heading id --- .../ruby-then-keyword-and-case-in/index.html | 24 ++--- .../rust-where-are-primitive-types-from/index.html | 12 +-- .../index.html | 112 ++++++++++----------- .../vim-swap-order-of-selected-lines/index.html | 46 ++++----- 4 files changed, 97 insertions(+), 97 deletions(-) (limited to 'public/posts/2021-10-02') 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 097d417..ba31a99 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,15 +65,15 @@

-
-

TL; DR

+
+

TL; DR

case - in によるパターンマッチング構文でも、case - when と同じように then が使える (場合によっては使う必要がある)。

-
-

then とは

+
+

then とは

使われることは稀だが、Ruby では then がキーワードになっている。次のように使う:

@@ -110,8 +110,8 @@ end
-
-

なぜ普段は書かなくてもよいのか

+
+

なぜ普段は書かなくてもよいのか

普通 Ruby のコードで then を書くことはない。なぜか。次のコードを実行してみるとわかる。

@@ -144,8 +144,8 @@ puts 'Hello, World!' -

なぜ then; や改行が必要か

+
+

なぜ then; や改行が必要か

なぜ then; や改行 (以下 「then 等」) が必要なのだろうか。次の例を見てほしい:

@@ -175,8 +175,8 @@ b

-
-

case - in における then

+
+

case - in における then

ようやく本題にたどり着いた。来る Ruby 3.0 では casein キーワードを使ったパターンマッチングの構文が入る予定である。この構文でもパターン部との区切りとして then 等が必要になる。 (現在の) Ruby には formal な形式での文法仕様は存在しないので、yacc の定義ファイルを参照した (yacc の説明は省略)。

@@ -259,8 +259,8 @@ p_cases end
-
-

まとめ

+
+

まとめ

  • ifcase の条件の後ろには then;、改行のいずれかが必要 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 9e77a85..8c6e269 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 @@ -62,8 +62,8 @@

    -
    -

    前置き

    +
    +

    前置き

    Rust において、プリミティブ型の名前は予約語でない。したがって、次のコードは合法である。

    @@ -100,8 +100,8 @@
    -
    -

    調査

    +
    +

    調査

    調査に使用したソース (調査時点での最新 master)

    @@ -242,8 +242,8 @@ rustc_resolve/src/lib.rs: table.insert(sym::i128, Int(IntTy::I128));

    -
    -

    まとめ

    +
    +

    まとめ

    Rust のプリミティブ型は予約語ではない。名前解決の最終段階で特別扱いされ、他に同名の型が見つかっていなければ対応するプリミティブ型に解決される。

    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 44ee689..b9455f7 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 @@ -62,15 +62,15 @@

    -
    -

    TL; DR

    +
    +

    TL; DR

    違いはない。ただのエイリアス。

    -
    -

    調査記録

    +
    +

    調査記録

    Vim の autocmd events には似通った名前のものがいくつかある。大抵は :help に説明があるが、この記事のタイトルにある2つを含めた以下のイベントには、その違いについて説明がない。

    @@ -109,8 +109,8 @@

    -
    -

    vim のソースコード

    +
    +

    vim のソースコード

    以下は、autocmd events の名前と内部で使われている整数値とのマッピングを定義している箇所である。見ての通り、上でエイリアスではないかと述べた3組には、それぞれ同じ内部値が使われている。

    @@ -139,8 +139,8 @@ {"BufWritePre", EVENT_BUFWRITEPRE},
    -
    -

    neovim のソースコード

    +
    +

    neovim のソースコード

    neovim の場合でも同様のマッピングが定義されているが、こちらの場合は Lua で書かれている。以下にある通り、はっきり aliases と書かれている。

    @@ -160,59 +160,59 @@ FileEncoding = 'EncodingChanged', ところで、上では取り上げなかった FileEncoding だが、これは :help FileEncoding にしっかりと書いてある。

    -
                                                               *FileEncoding*
    -  FileEncoding                    Obsolete.  It still works and is equivalent
    +              
                                                                  *FileEncoding*
    +FileEncoding                    Obsolete.  It still works and is equivalent
                                     to |EncodingChanged|.
    +
    + +
    +

    まとめ

    +

    + 記事タイトルについて言えば、どちらも変わらないので好きな方を使えばよい。あえて言えば、次のようになるだろう。 +

    -
    -

    まとめ

    -

    - 記事タイトルについて言えば、どちらも変わらないので好きな方を使えばよい。あえて言えば、次のようになるだろう。 -

    +
      +
    • + BufAdd/BufCreate +
        +
      • + → BufCreate は歴史的な理由により ("for historic reasons") 存在しているため、新しい方 (BufAdd) を使う +
      • +
      +
    • -
        -
      • - BufAdd/BufCreate -
          -
        • - → BufCreate は歴史的な理由により ("for historic reasons") 存在しているため、新しい方 (BufAdd) を使う -
        • -
        -
      • - -
      • - BufRead/BufReadPost -
          -
        • - → BufReadPre との対称性のため、あるいは BufWritePost との対称性のため BufReadPost を使う -
        • -
        -
      • - -
      • - BufWrite/BufWritePre -
          -
        • - → BufWritePost との対称性のため、あるいは BufReadPre との対称性のため BufWritePre を使う -
        • -
        -
      • - -
      • - FileEncoding/EncodingChanged -
          -
        • - → FileEncoding`Obsolete'' と明言されているので、`EncodingChanged を使う -
        • -
        -
      • -
      +
    • + BufRead/BufReadPost +
        +
      • + → BufReadPre との対称性のため、あるいは BufWritePost との対称性のため BufReadPost を使う +
      • +
      +
    • -

      - ところでこの調査で知ったのだが、BufReadBufWrite は上にある通り発火するタイミングが「後」と「前」で対称性がない。可能なら Pre/Post 付きのものを使った方が分かりやすいだろう。 -

      -
    +
  • + BufWrite/BufWritePre +
      +
    • + → BufWritePost との対称性のため、あるいは BufReadPre との対称性のため BufWritePre を使う +
    • +
    +
  • + +
  • + FileEncoding/EncodingChanged +
      +
    • + → FileEncoding`Obsolete'' と明言されているので、`EncodingChanged を使う +
    • +
    +
  • +
+ +

+ ところでこの調査で知ったのだが、BufReadBufWrite は上にある通り発火するタイミングが「後」と「前」で対称性がない。可能なら Pre/Post 付きのものを使った方が分かりやすいだろう。 +

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 6b9e423..320e80e 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 @@ -62,8 +62,17 @@

-
-

バージョン情報

+
+

TL; DR

+
" License: Public Domain
+
+command! -bar -range=%
+    \ Reverse
+    \ keeppatterns <line1>,<line2>g/^/m<line1>-1
+
+ +
+

バージョン情報

:version の一部

@@ -75,10 +84,10 @@
-
-

よく紹介されている手法

-
-

tac / tail

+
+

よく紹介されている手法

+
+

tac / tail

tactail -r などの外部コマンドを ! を使って呼び出し、置き換える。

@@ -94,8 +103,8 @@

-
-

:g/^/m0

+
+

:g/^/m0

こちらは外部コマンドに頼らず、Vim の機能のみを使う。g:global コマンドの、m:move コマンドの略

@@ -138,8 +147,8 @@
-
-

:g/^/m0 の問題点

+
+

:g/^/m0 の問題点

:global コマンドは各行に対してマッチングを行う際、現在の検索パターンを上書きしてしまう。^ は行の先頭にマッチするため、結果として全ての行がハイライトされてしまう。'hlsearch' オプションを無効にしている場合その限りではないが、その場合でも直前の検索パターンが失われてしまうと n コマンドなどの際に不便である。

@@ -151,8 +160,8 @@
-
-

解決策

+
+

解決策

[2020/9/28追記] より簡潔な方法を見つけたので次節に追記した @@ -212,8 +221,8 @@ command! -bar -range=%

-
-

解決策 (改訂版)

+
+

解決策 (改訂版)

[2020/9/28追記] より簡潔な方法を見つけたため追記する @@ -234,15 +243,6 @@ command! -bar -range=%

- -
-

コピペ用再掲

-
" License: Public Domain
-
-command! -bar -range=%
-    \ Reverse
-    \ keeppatterns <line1>,<line2>g/^/m<line1>-1
-
-- cgit v1.2.3-70-g09d2