emacs - 커서가 있는 줄 전체를 comment out하기 등

auditory의 이미지

emacs입문하려고하는데 쉽지 않네요.. ^^
두가지 질문입니다.
사용하는 버전은 GNU Emacs 22.2.1 입니다.

첫째.
emacs 에서 현재 커서가 있는 줄을 comment out하고 싶습니다.
간단하게 할 수 있는 방법이 있을까요?

찾아보니 아래의 것이 있던데요,
region-active-p의 타입이 void라면서 실행이 안되네요..

http://www.emacswiki.org/emacs/ExtensionsSylecn

;;======================================================================
;; M-; enhancement
;; Now it can comment current line when not at end of line.
;;ref: <a href="http://www.emacswiki.org/emacs/CommentingCode
;;Original" rel="nofollow">http://www.emacswiki.org/emacs/CommentingCode
;;Original</a> idea from
;;http://www.opensubscriber.com/message/emacs-devel@gnu.org/10971693.html
 
;; There is still one difference between the orginal and this one.
;; You can't align the in-line comment at end of code now.
 
(defun comment-dwim-line (&optional arg)
  "When no region active and not at end of line, comment current line; else call comment-dwim."
  (interactive "*P")
  (comment-normalize-vars)
  (if (and (not (region-active-p)) (not (looking-at "[ \t]*$")))
      (comment-or-uncomment-region (line-beginning-position) (line-end-position))
    (comment-dwim arg)))

둘째로는 아래처럼 %로 괄호매치를 하는것을 쓰고 있는데요,
괄호매치를 할때 처음 위치를 mark 해두고 싶습니다. (이동후에 kill을 하려고..)

  (global-set-key "%" 'match-paren)
    (defun match-paren (arg)
      "Go to the matching paren if on a paren; otherwise insert %."
      (interactive "p")
      (cond ((looking-at "\\s\(") (forward-list 1) (backward-char 1))
            ((looking-at "\\s\)") (forward-char 1) (backward-list 1))
            (t (self-insert-command (or arg 1)))))

(looking-at .... ) 바로 다음에 (set-mark-command 1) 을 넣으면 될것 같은데,
오히려 이상하게 동작하네요..
어떻게 해야할까요?

cinsk의 이미지

1. "(not (region-active-p))" 대신에 "(not mark-active)"를 써보세요.

2. 원하는게 해당 괄호의 짝을 찾는 것이라면 M-x show-paren-mode를 쓰는 것이 좋을 것 같네요.

--
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
Korean Ver: http://www.cinsk.org/cfaqs/

redneval의 이미지

(set-mark-command 1) 대신에 (push-mark-command t) 를 써보세요.

(참고 : http://www.emacswiki.org/emacs/TransientMarkMode)

--------------------Signature--------------------
Light a candle before cursing the darkness.