태그 보관물: emacs

[Tip] Emacs에서 pdb 사용할 때 UnicodeEncodeError

*** UnicodeEncodeError: ‘ascii’ codec can’t encode characters in position 168-169: ordinal not in range(128)

Emacs에서 shell을 열고 pdb를 실행 할 때 표시하고자 하는 문자열이 ASCII가 아니라면 발생 할 수 있는 문제인데 emacs의 초기화 파일에 unicode locale 설정을 해주는 것으로 해결할 수 있다. 인터넷 문서들 중에는 LANG, LC_LANG, LC_CTYPE 모두를 설정해 주어야 한다는 내용도 있었으나, 내 terminal에서 LC_CTYPE만 설정해서도 잘 동작되고 있으므로 이를 따라 LC_CTYPE만 UTF-8으로 다음과 같이 설정해 주었다.

;;; **************************************************************
;;; Unicode Encoding
;;; **************************************************************
(setenv "LC_CTYPE" "UTF-8")

Init file을 reload하거나 emac를 재 실행해서 ASCII외의 문자들이 잘 표시 되는지 확인해 본다.

그리고 환경 설정은 GitHub repository에 업뎃. 🙂

Emacs로 AWS EC2 원격지 파일 편집

Emacs의 TRAMP mode를 사용하면 원격서버에 있는 불러와서 바로 편집할 수 있다. 다음은 ssh가 돌고있는 AWS EC2 서버의 파일을 TRAMP mode로 편집하기 위한 설정을 설명한다.

Emacs: version 25.1 (macOS)

init.el에 TRAMP mode 설정을 추가.

;TRAMP
(require 'tramp)
(setq tramp-default-method "ssh")

편집할 원격지 파일을 불러 올 때는 계정@호스트:파일경로 형식으로 하면되는데, EC2의 pem 키를 지정할 수 있는 ‘-i’ option을 지원하지 않는다. 매번 비밀번호를 입력하는게 귀찮다면 ssh-add로 키를 추가한다.

$ ssh-add ~/.ssh/ec2_key.pem 
Identity added: /Users/USER/.ssh/ec2_key.pem (/Users/USER/.ssh/ec2_key.pem)

이제 Emacs에서 다음의 명령어로 원격 파일에 접속하거나 파일 목록을 불러 올 수 있다.

Find file: /USERID@REMOTE_SERVER:~/

Android emacs (android-host.el) 기능 추가

AOSP에서 제공되는 Emacs용 Andorid 개발환경을 설정한 이후(이 post 참조) 잘 모르는 LISP을 더듬어 가며 추가한 몇 가지 기능을 소개합니다.

adb reboot (M-x android-adb-reboot)

Module등을 변경한 후에 device를 reset하는 명령어가 없어서 추가했다. 이 기능의 장점을 굳이 꼽자면 shell을 따로 뛰우지 않고 리붓을 할수 있다는거…

(defun android-adb-reboot ()
  "Execute 'adb reboot'."
  (interactive)
  (android-adb-command "reboo

Module push (M-x android-adb-push-module)

Compile한 module을 target에 push 할 때 사용한다. Command를 입력하면 push 할 source와 target을 물어보고 adb push command를 실행한다.

(defun android-adb-push-module (source target)
  "Push specified module into target path."
  (interactive "fSource: \nsTarget: ")

  (android-adb-root)
  (android-adb-remount)
  (android-adb-command
    (concat "push " source " " target) 'p))

Module push Hotkey  (C-x a p)

위의 android-adb-push-module 함수를 쓰다보니 path를 입력하는게 무척 귀찮다. android-compile 명령어를 수행해서 만들어지는 출력 버퍼에서 위의 단축키로 target의 해당 directory로 module을 push한다.

Install: out/target/product/TARGET_DEVICE/system/xxx/yyy.zz

출력 버퍼로 이동해서 출력된 결과물 위에 cursor를 놓고 ‘C-x a p’를 입력하면 그 경로를 읽어서 target으로 push 한다. Source의 path에서 target 위치를 읽어 오게 되어 있어서 특별한 입력이 필요 하지 않다.

(define-key map (kbd "p") 'android-adb-push-module-at-point)
...

(defun android-adb-push-module-at-point ()
  "Push module path at cursor point an push to the target path."
  (interactive)

  (let*
    (
      (sourcepath (concat (android-find-build-tree-root) (thing-at-point 'filename)))
      (targetpath (substring sourcepath (string-match "\/system" sourcepath) nil)))
    (android-adb-push-module sourcepath targetpath)))

전체 수정내역을 포함하는 파일: icon_text_file android-host.el