0

私はこれを参照として使用します: Emacsのコメント/コメント解除の現在の行

私の質問は、defadviceを使用して同じタスクを実行できるかどうかです(これは私にとってより適切だと思われます)?の線に沿った何か

(defadvice comment-or-uncomment-region (before mark-whole-line (arg beg end) activate)
  (unless (region-active-p)
    (setq beg (line-beginning-position) end (line-end-position))))
(ad-activate 'comment-or-uncomment-region) 
4

1 に答える 1

2

この答えは、上記の私のコメントに基づいています。

defadvice別の解決策よりも適切ではありません。それは他の解決策よりも決して適切ではありません。


defadvice他の方法で問題を解決できない場合の最後の手段です。

限目。


使用するときはいつでもdefadvice、パッケージ開発者が依存するEmacsAPIを基本的に変更していることに注意してください。

これらの動作を微妙に変更すると、Emacs APIがで壊れているため、「バグ」を報告すると、最終的にはパッケージ開発者に多くの問題が発生しますdefadvice

したがって、機能をローカルで変更する場合は、既存の機能を使用して新しいコマンドを定義し、それに再マップする方法があります。

ウィットするには(あなたが参照した答えから):

(defun comment-or-uncomment-region-or-line ()
    "Comments or uncomments the region or the current line if there's no active region."
    (interactive)
    (let (beg end)
        (if (region-active-p)
            (setq beg (region-beginning) end (region-end))
            (setq beg (line-beginning-position) end (line-end-position)))
        (comment-or-uncomment-region beg end)
        (next-line)))

(global-set-key [remap comment-dwim] 'comment-or-uncomment-region-or-line)
于 2012-10-27T14:35:52.153 に答える