複数行の関数呼び出しを行い、それを 1 行に減らしたいことがよくあります。たとえば、変換...
function_call(
'first_arg',
'second')
に
function_call('first_arg', 'second')
emacs には、これを支援するコマンドがいくつかありますか。具体的には、ポイントから最初の非空白文字までのすべての空白を削除するコマンドはありますか?
複数行の関数呼び出しを行い、それを 1 行に減らしたいことがよくあります。たとえば、変換...
function_call(
'first_arg',
'second')
に
function_call('first_arg', 'second')
emacs には、これを支援するコマンドがいくつかありますか。具体的には、ポイントから最初の非空白文字までのすべての空白を削除するコマンドはありますか?
delete-indentation
複数の行を1行に結合するための私のお気に入りのコマンドを試してみてください。あなたの例では、「second」の行にカーソルを置き、M-^2回押します。ドキュメントは次のとおりです。
M-^コマンド
delete-indentation
を実行します。これは、でインタラクティブにコンパイルされたLisp関数ですsimple.el
。にバインドされていM-^ます。
(delete-indentation &optional arg)
この行を前の行に結合し、結合時に空白を修正します。塗りつぶしプレフィックスがある場合は、この行の先頭から削除します。引数を使用して、この行を次の行に結合します。
fixup-whitespace
関数を見てみましょう。Emacs に付属していsimple.el
ます。そのドキュメントは次のとおりです。
ポイントの周りのオブジェクト間の空白を修正します。文脈に応じて、スペースを 1 つ残すか、まったく残さないでください。
同様の関数just-one-space
、
ポイントの周囲のすべてのスペースとタブを削除し、スペースを 1 つ残します
通常、 にバインドされM-SPCます。
Specifically, is there a command that will delete all whitespace from the point to the first non-whitespace character?
There's a command that does almost that:
M-\ runs the command delete-horizontal-space which is an interactive compiled Lisp function in `simple.el'.
It is bound to M-\.
(delete-horizontal-space &optional backward-only)
Delete all spaces and tabs around point. If backward-only is non-nil, only delete them before point.
Mz を使用して、いつでも文字まで削除できます。
たとえば、あなたの場合:
Mz ' で一重引用符まで削除します (残念ながらこれにより一重引用符も削除されますが、これは少し不便です)。
次のマクロを使用して、次の行を現在の行の末尾に「プル」し、空白を圧縮します。
(defun pull-next-line()
(interactive)
(move-end-of-line 1)
(kill-line)
(just-one-space))
move-line-up
これは、@jrockway のとの正反対でありdelete-indentation
、より自然だと思います。マクロ内のjust-one-space
コマンドは、まさに @Mike のものM-SPACE
です。
私pull-next-line
の. M-J
_ J
_.emacs
(global-set-key (kbd "M-J") 'pull-next-line)
例。pull-next-line
の最初の行で呼び出す
function_call(
'first_arg',
'second')
収量
function_call( 'first_arg',
'second')
もう一度呼び出すと、
function_call( 'first_arg', 'second')
Alt-space は、空白の文字列を単一のスペース文字に減らしますが、改行は削除しません。それでも、それは少し役立つはずです。
ポイントから最初の非空白 (または改行) までのすべてを削除するには、非空白文字、Alt-space、backspace (最後の空白文字を削除する)、次に backspace (追加した文字を削除する) を入力します。
複数行の関数宣言を単一行の宣言に変えるには、Alt-space、backspace、および Alt-E (goto-endofline) コマンドを組み合わせて使用します。
これを行うかなり抜本的な方法は、Hungry-Deleteモードです。
Hungry-Delete は、削除する方向のすべての空白を削除するマイナー モードです。
わずかに異なるアプローチは、キーボード マクロを作成して作業を行うことです。したがって、マクロ ステージを作成するには、次のような一般的なシナリオを使用します。
foo
bar
[「foo」のある行、その数行後に空白を入れて「bar」と書く]
次に、foo と bar の間の任意の場所に立って、次の操作を行います。
Cx ( ; マクロの記録を開始 メガバイト; foo の先頭に戻る 終わり ; foo の末尾に移動 Cスペース; 目印 CMf; 小節の終わりに移動 家 ; 行頭に移動 CW ; すべての空白を引っ張る M-スペース; スペースを1つだけ残す Cx); マクロの記録を終了する Mx name-last-kbd-macro ; 名前を付けて、jline などと呼んでください
Mx one-line を使用して、2 つの単語間のすべての空白をいつでも削除できるようになりました。
.emacs ファイルのどこかに Mx insert-kbd-macro を発行して、キーボード マクロを保存することを忘れないでください。
(fset 'jline
[?\M-b end ?\C- ?\C-\M-f home ?\C-w escape ? ])
If you want all of your deletes to act that way, you might check out greedy-delete.
私はこれをします:
(defun move-line-up ()
"Removes leading spaces from the current line, and then moves
the current line to the end of the previous line."
(interactive)
(let (start end)
(save-excursion
(beginning-of-line)
; get first non-space character, only look on this line
(let ((search-end (save-excursion (end-of-line) (point))))
(re-search-forward "[^[:space:]]" search-end))
(setq end (1- (point)))
(previous-line)
(end-of-line)
(setq start (point))
(delete-region start end))
(goto-char start)))
(defun move-next-line-up ()
"Moves the next line to the end of the current line"
(interactive)
(next-line)
(move-line-up))
そして、これらを次のようにバインドします。
(global-set-key (kbd "C-x ,") 'move-line-up)
(global-set-key (kbd "C-x .") 'move-next-line-up)
したがって、問題を解決するには、「second)」という行で実行するだけですC-x , C-x ,