whitespace mode - trailing whitespace에서 한 걸음 더

;; whitespace mode
(custom-set-faces
 '(whitespace-line
   ((nil (:bold t :background "yellow"))))
 '(whitespace-trailing
   ((nil (:bold t :background "red1"))))
 '(whitespace-tab
   ((nil (:bold t :background "linen")))))

(global-whitespace-mode t)

(add-hook
 'after-change-major-mode-hook
 '(lambda ()
    (if (derived-mode-p 'prog-mode)
        (setq whitespace-line-column
              80
              whitespace-style
              '(face tabs trailing lines-tail tab-mark))
        (setq whitespace-line-column
              nil
              whitespace-style
              '(face tabs trailing tab-mark)))))
;; disable tabs mode
(setq-default indent-tabs-mode nil)

trailing whitespace를 보여주고 제거하는 설정을 추가했었다. 여기서 조금 더 강조하고 싶다. 80컬럼 넘어간 문자. tab 문자. 찾아보니 막판 대장 있네. whitespace-mode. 하도 많아서 필요한 옵션을 찾는 것도 일이다.

80컬럼 초과 강조는 prog-mode에만 적용했다. c++, clojure, elisp, … 메이저 모드는 상속받아서 사용하기 때문에 이걸로 퉁칠 수 있다.

뭐든 간에 안 섞어 쓰면 굿굿. 난 space 파.

whitespace-mode

tab, space, newline, … 등을 표시해주는 마이너 모드다. M-x whitespace-mode를 하면 온갖 정보를 다 보여주므로 필요한 것만 출력하게 수정했다. 다 출력하니 눈 아프다.

(setq whitespace-line-column 80
      whitespace-style '(face tabs trailing lines-tail tab-mark))

80컬럼을 넘어서는 문자를 강조. tab과 문장 끝에 따라붙는 whitespace를 출력하게 했다.

막판 대장. 이걸로 다 된다. trailing whitespace 쓰면서 추가한 (setq-default show-trailing-whitespace t)를 삭제했다.

add-hook

global-whitespace-mode 심볼에 whitespace-mode를 사용할 메이저 모드 이름을 넘겼는데, 동작 안 한다. 외로워서 고통 받는 동지를 찾아 인터넷을 헤맸다. 없네~ 인터넷으로 찾아보니 별 정보도 안 보인다. 그래서 모드가 바뀔 때 호출하는 after-change-major-mode-hook에 훅을 추가했다.

custom-set-faces

옐로카드, 레드카드 줬다. tab도 레드카드 주고 싶었다. 하지만 elisp 라이브러리 소스가 막 섞어서 사용했어. 눈 아파서 좀 양보했다. 색상은 colors available to emacs을 참고.

:retab!

M-x tabify
M-x untabify

M-: (untabify (point-min) (point-max))

point-min, point-max는 현재 버퍼 point 값을 가져온다. 즉, 저렇게 해서 버퍼 전체에서 tab -> space로 변경한다.

참고

C-x C-s C-x C-c


크리에이티브 커먼즈 라이선스


Published: November 29 2014


Feedback plz <3 @ohyecloudy, ohyecloudy@gmail.com