Emacs Mxのクエリでパッケージング文書を置き換えますか?

Emacs Mxのクエリでパッケージング文書を置き換えますか?

私はM-x query-replaceEmacs()をたくさん使っており、次のオプションから選択できる柔軟性が好きです。M-%

Spacebar               Replace text and find the next occurrence
Del                    Leave text as is and find the next occurrence
. (period)             Replace text, then stop looking for occurrences
! (exclamation point)  Replace all occurrences without asking
^ (caret)              Return the cursor to previously replaced text

次の方法はありますか?

  • 文書の終わりに達した後、文書の先頭に戻りますか?

  • コマンド実行中に検索と置換の方向を変更します。

ベストアンサー1

query-replace非常に重要な機能なので、全体的に変更する意図はありません。私がしたことは、それを新しい関数にコピーすることで、my-query-replace最初は同じ動作をしました。次に、関数がバッファの終わりに達した後、バッファの先頭でクエリ置換検索を繰り返すことを提案します。これは過度に慎重になる可能性があります。query-replace代わりに適用する推奨事項を変更し、my-query-replaceこの動作をグローバルに有効にできます。

;; copy the original query-replace-function 
(fset 'my-query-replace 'query-replace)

;; advise the new version to repeat the search after it 
;; finishes at the bottom of the buffer the first time:    
(defadvice my-query-replace 
  (around replace-wrap 
          (FROM-STRING TO-STRING &optional DELIMITED START END))
  "Execute a query-replace, wrapping to the top of the buffer 
   after you reach the bottom"
  (save-excursion
    (let ((start (point)))
      ad-do-it
      (beginning-of-buffer)
      (ad-set-args 4 (list (point-min) start))
      ad-do-it)))

;; Turn on the advice    
(ad-activate 'my-query-replace)

このコードを評価したら、呼び出しを使用して検索をラップしM-x my-query-replaceたり、便利な項目にバインドしたりできます。

(global-set-key "\C-cq" 'my-query-replace)

おすすめ記事