2023年02月12日

Posted on Feb 12, 2023

Effective Go

6章を4ページ進めた。また原稿の移行は3章まで終わった。

原稿を進める中で、元原稿が無駄に改行が入ってて扱いづらかったので、マクロを書いて対応することにした。

このVS Code拡張を入れて、JavaScriptのマクロを書くと、改行と間にある余計な空白を一気に削除できるようになった。 ショートカットを何回も押さなくて良いので便利。

https://marketplace.visualstudio.com/items?itemName=EXCEEDSYSTEM.vscode-macros

const vscode = require('vscode');

module.exports.macroCommands = {
    RemoveNewLine: {
       no: 1,
       func: RemoveNewLineInSelection
    },
}

function RemoveNewLineInSelection() {
    const editor = vscode.window.activeTextEditor;
    if (!editor) {
        return "Editor is not available."
    }

    const document = editor.document;
    const selection = editor.selection;
    const selectedText = document.getText(selection);

    // remove newline and extra white spaces
    let replaced = selectedText.replace(/\r?\n/g, ' ');
    replaced = replaced.replace(/ +/g, ' ');

    editor.edit(editBuilder => {
        editBuilder.replace(selection, replaced);
    });
}