Showing posts with label emacs cocoa. Show all posts
Showing posts with label emacs cocoa. Show all posts

Sunday, October 18, 2015

Tags disappear after saving a buffer in emacs

Tags and Emacs

Tags and Emacs


This post is written with e[ ⎋Esc ]m[ ⌥Meta ]a[ ⌥Alt ]c[ ^Ctrl ]s[ ⇧Shift ] org-mode.


System Environments

Operating Systems

  • Main- : OS X Yosemite (10.10.5)
  • Sub- : Debian GNU/Linux Wheezy (7.9)
  • Server: Debian GNU/Linux Wheezy || Squeeze
  • Mobile: iOS 9.0.2

Softwares mentioned here

Tags disappear after saving a buffer in emacs, OS X

If your tags disappear sometimes, I bet you are an emacs and OS X user like me. It could happen under your .emacs file manually (il-)modified, particularly the backup file configuration.

It turns out that the reason why my tags disappear is caused by emacs. My il-modified .emacs had the following elisp code inside.

(setq backup-directory-alist `(("." . "~/.emacs.d/auto-save-list")))

That made all automatically generated backup files, i.e. file_name.extenson~, moved into the directory ~/.emacs.d/auto-save-list. I set it up, because file_name.extenson~ was nothing but bothering me. If an original file has a tag, then its emacs backup is gonna have the same tag as well. Whenever I tried to access such files via tags such as quicksilver's File Attribute Plugin, emacs backups also are there. Even further worse. So I decided to move them all to one directory by the elisp code above. However it was a wrong choice. According to this, a file with tags had its tags killed after saving it(^x ^s or ⌘s) in emacs.

I don't know why or how it technically happens, but it is true that the above elisp is the reason. Instead of putting all emacs backups to one directory, I simply disable all automatic backup precess by adding the following into my .emacs.

(setq backup-inhibited t)

There will be no tags disappearing again.


Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Created: 2015-10-18 Sun 22:56

Emacs 24.3.1 (Org mode 8.2.10)

Friday, June 5, 2015

Emacs 24

Emacs 24

Emacs 24


이 문서는 e[ ⎋Esc ]m[ ⌥Meta ]a[ ⌥Alt ]c[ ^Ctrl ]s[ ⇧Shift ] org-mode로 작성된 글입니다.


System Environments

Operating Systems

  • Main- : OS X Yosemite (10.10.3)
  • Sub- : Debian GNU/Linux Wheezy (7.8)
  • Server: Debian GNU/Linux Wheezy || Squeeze
  • Mobile: iOS 7.1.2

Emacs Cocoa 24.3 & GNU Emacs 24.3

우선 Emacs 버전부터 짚고 넘어가자.

현재(<2015-06-04 Thu>) Debian GNU/Linux Wheezy에서 debian repository에 저장되어 있어서 apt 로 설치할 수 있는 GNU Emacs는 23.4이다. OSX Yosemite에서 돌아가는 Aquamacs 최신 버전은 3.2이고, 이는 Emacs 24를 기본으로 하고 있다. OSX에서 사용할 수 있는 또 다른 Emacs fork인 Emacs Cocoa는 두 가지 경로를 통해 설치할 수 있다. 하나는 Homepage를 이용하는 것이고, 다른 하나는 MacPorts나 Homebrew 같은 package manager를 쓰는 것이다. Emacs Cocoa Homepage에서 제공하는 가장 높은 버전은 24.5이고 Homepage: Other versions에서는 아래로 23.2까지 다운로드 가능하다. MacPorts 이용자는 Debian의 apt 처럼 최신 버전만 설치할 수 있는데, 이는 24.5이다. 지난 Posts에서도 언급했다시피, Hunspell을 이용한 영/한 맞춤법 검사 를 구현하고자 하는 사용자는 반드시 24.3이나 그 이하 버전을 써야만 이 블로그에서 설명한 방법을 적용할 수 있다.

이번에는 조금 더 구체적으로, Emacs 24.3을 기준으로 그 특징과 Debian에서 설치 방법을 적어볼 생각이다.

Upgrade org-mode

그 전 버전과 차별화되는 Emacs 24의 특징은, marmalade같은 외부 package repository를 사용할 필요 없이 자체적으로 Emacs에 필요한 package를 설치하고 또 설치한 package를 업그레이드할 수 있다는 점이다. Emacs에 기본적으로 설치된 org-mode package를 통해서 어떻게 이를 진행하는 지 살펴보자.

How to upgrade

OS 와는 상관없이 Emacs 24에서 아래의 순서로 진행하면 된다. 단축키는 OSX Emacs Cocoa의 경우를 기준으로 썼고, Debian에서 GNU Emacs 경우는 괄호 안에 기본 표현으로 표기하였다.

  1. Emacs에서 ⌥x (M-x)을 친 후, package-list-packages 쓰고 ↩Return
  2. 세 번째 열 Status에서 가능한 (available) packages와 설치된 (built-in) packages를 볼 수 있다. 이 중 org 를 찾아 클릭한다.
  3. 다음에 등장하는 buffer에서 Install 을 클릭해서 설치하면 끝

18469818431_854726cf90_o.gif

Figure 1: Upgrading org-mode in GNU Emacs 24.3

Trouble shooting

가끔 문제가 발생하는데, 이는 사용자가 Emacs 설정 파일인 ~/.emacs 를 이미 수정해서 쓰는 경우나 marmalade같은 외부 package repository를 사용한 상황에서 주로 발생한다.

  1. Emacs 설정 파일인 ~/.emacs 를 적당한 곳에 백업해 두자.
  2. ~/.emacs.d/ 로 이동해서 elpa 이름의 디렉토리를 지우자. 이동은 Bash (혹은 Termianl)에서 해도 되고, Finder (혹은 Dolphin, Thunar, etc)에서 해도 된다.
  3. Emacs를 실행해서 위의 과정을 다시 한다.
  4. 백업해둔 Emacs 설정 파일을 다시 ~/.emacs 로 복사한다.
  5. 이제 Emacs를 다시 실행하자.

Emacs 24.3 in debain

설치 과정은 여기를 참고했다.1 아래의 명령들을 Bash (혹은 Terminal)에서 순서대로 실행하자.

$ sudo apt-get install ttf-inconsolata build-essential xorg-dev libgtk2.0-dev libjpeg-dev libgif-dev libtiff-dev libncurses-dev autoconf
$ wget http://ftp.gnu.org/pub/gnu/emacs/emacs-24.3.tar.gz
$ tar xvfz emacs-24.3.tar.gz
$ cd ~/emacs-24.3
$ ./configure
$ make
$ sudo make install

wget 으로 받은 emacs-24.3.tar.gz 파일은 홈디렉토리(~) 아래에 있으니 나중에 지워도 무방하다. 설치가 끝나면 Bash (혹은 Termianl)에서 emacs 까지만 치고 자동 완성을 위해 ↹Tab 키를 두 번 정도 치면, emacs란 이름으로 시작하는 가능한 모든 명령어를 볼 수 있다. 이미 설치했던 emacs 23은 emacs23 으로 바꾸어 있고, 새로 설치한 24는 표면적으로 없는 것처럼 보인다. 하지만 emacs 가 바로 emacs 24이다. 이는 emacs --version 명령어로 확인할 수 있다.

18467159295_4a02b21b93_o.png


Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Footnotes:

Created: 2015-06-05 Fri 00:18

Emacs 24.3.1 (Org mode 8.2.10)

Wednesday, June 3, 2015

Emacs Spell-checker English/Korean

Emacs Spell-checker English/Korean

Emacs Spell-checker English/Korean


This post is written with e[ ⎋Esc ]m[ ⌥Meta ]a[ ⌥Alt ]c[ ^Ctrl ]s[ ⇧Shift ] org-mode.

이 문서는 e[ ⎋Esc ]m[ ⌥Meta ]a[ ⌥Alt ]c[ ^Ctrl ]s[ ⇧Shift ] org-mode로 작성된 글입니다.


System Environments

Operating Systems

  • Main- : OS X Yosemite (10.10.3)
  • Sub- : Debian GNU/Linux Wheezy (7.8)
  • Server: Debian GNU/Linux Wheezy || Squeeze
  • Mobile: iOS 7.1.2

Ispell-word and the secondary click within Flyspell on

Needless to say, the GIF below is self-explanatory.

English/Korean spell-checker in Emacs 24.3, OS X

The work-flow was captured under Hunspell with Emacs Cocoa 24.3 in OSX. Hunspell was activated for English/Korean. Shortcuts I set are ⌘d for ispell-word and ⌘2⌘2 for the spell-checking pop-up window. For the former, you can select a word you want by typing a digit. The latter is technically nothing but the secondary click(or right click) at a mouse point on a word underscored by Flyspell On. I made the key-binding for it by ⌘2⌘2. Though the gif above shows way in Emacs Cocoa under OSX, it is completely possible in GNU Emacs under Linux.

FYI) ⌘⎵ in the gif indicates the shortcut I set for ispell-change-dictionary.

Requirements

  • Hunspell for Emacs cocoa 24.3 in OSX or for GNU Emacs 23.4/24.3 in Debian GNU/Linux

It is not dealt with in this post, because I explained it already. You can see the details by clicking one of the links followed.

There are descriptions for a simple way to change both input methods and hunspell dictionaries as well.

Instruction

Typing ispell-word after ⌥x (M-x in typical Emacs notation) would be enough for some users to check spelling. However, what I want to say is how to set up a key-stroke for the spell-checking pop-up window once the flyspell is on.

  1. Set flyspell-mode on for text-mode by adding the line
    '(text-mode-hook (quote (turn-on-flyspell text-mode-hook-identify)))
    

    into your Emacs preference file, i.e. ~/.emacs. For instance,

    (custom-set-variables
    ;; custom-set-variables was added by Custom.
    ;; If you edit it by hand, you could mess it up, so be careful.
    ;; Your init file should contain only one such instance.
    ;; If there is more than one, they won't work right.
    '(cua-mode t nil (cua-base)) ;;<--- let c-x c-c c-v work
    '(text-mode-hook (quote (turn-on-flyspell text-mode-hook-identify))) ;;<--- flyspell
    )
    

    The basic to read an elisp source is that anything after ;; is a comment, so that doesn't affect Emacs at all.

  2. Activate ⌘2⌘2 for the secondary click(or right click) at an underscored word by adding the following elisp code to ~/.emacs
    ;; \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
    ;; \\\\\[Body III-a.] For keyboard strokes for spelling check
    ;; \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
    (global-set-key [\s-mouse-2] 'flyspell-correct-word)   ;; <--- step 0/2 for s-2 s-2
    ;; ------------------------------
    ;; ---> function 1
    ;; ------------------------------
    (defun make-mouse-event-at-point (base-event)
    (let ((posn (posn-at-point))
      (prefix "")
      (basic-type (event-basic-type base-event))
      (modifiers (event-modifiers base-event)))
    (cond
    ((and (integerp basic-type) (>= basic-type ?0) (<= basic-type ?9))
    ;; click
    (let* ((mouse-type (intern (format "%smouse-%d" prefix (- basic-type ?0))))
           (click-count 1)
           (type (event-convert-list (append modifiers (list mouse-type)))))
      (list type posn click-count)))
    (t
    (error "Unsupported key for mouse event: %s" (event-basic-type base-event)))
    ))
    )
    ;; ------------------------------
    ;; ---> function 2
    ;; ------------------------------
    (defun simulate-mouse-event-at-point ()
    (interactive)
    (let ((event (make-mouse-event-at-point last-input-event)))
    (setq unread-command-events (cons event unread-command-events))))
    ;; ------------------------------
    ;; ---> function 3
    ;; ------------------------------
    (defvar simulate-mouse-event-map (make-sparse-keymap))
    (global-set-key (kbd "s-2") simulate-mouse-event-map)   ;; <--- step 1/2 for s-2 s-2
    ;; ------------------------------
    ;; #####!!! final step, i.e step 2/2 for keyboard stroke for mouse#-click
    ;; ------------------------------
    (define-key simulate-mouse-event-map [t] 'simulate-mouse-event-at-point)
    

    When you use the exactly same elisp above in GNU Emacs under Linux, the shortcut must be ⊞Win-2 ⊞Win-2 in a non-apple keyboard. If you want to change it to C-2 C-2, then it can be done after replacing s- and \s- with C- and \C- respectively.

FYI) In GNU Emacs under Linux, C, M, S, and s stand for Ctrl, Meta, Shift, and super-key (a.k.a. Windows key) respectively.

Acknowledgement

I acknowledge Gilles from StackExchange's debt to almost every elisp code here. You can find his source code explicitly in HERE.

Epilog, 한글 사용자를 위하여

Emacs에서 맞춤법 검사는, ⌥x (M-x Emacs 기본 표기) 후 ispell-word 로 간단히 실행할 수 있다. Flyspell mode(틀린 맞춤법에 밑줄 그어짐)이 켜있는 경우에는, 밑줄 그어진 단어 위에서 우클릭하면 팝업창이 뜨고 화살표키로 선택하는 방법으로도 사용할 수 있다. 영어의 경우는 특별한 사전을 설치하지 않아도 바로 검사할 수 있음은 물론이다. 한글 맞춤법 검사는 현재로는 hunspell이 거의 유일무이한 대안인데, 영어와 함께 이를 활성화 하는 방법은 지난 Posts에서 설명했다.

OSX Yosemite 전까지는 Aquamacs에서 ispell-word (or ispell-region)으로 영어/한글 맞춤법 모두를 해결해 왔었다. 바람입력기로 OSX 차원이 아닌 Aquamacs 자체에서 입력소스를 변경하고, 영어 맞춤법은 Aquamacs에서 기본으로 제공하는 것으로 한글 맞춤법은 OSX 차원에서 설치한 Korean hunspell dictionary로 약간은 변칙을 써왔었다. 당시에도 Aquamacs에서 Hunspell을 동작하게 하는 방법을 많이 시도했으나 다 무위로 돌아갔었고, 이 변칙 방법으로도 잘 작동하니 문제 없이 사용했었다. 물론, OSX 단에서 설치한 이 한글 사전은 Aquamacs는 물론 다른 프로그램에서도 잘 돌았었다.

OSX Yosemite 후, 모든 것이 달라졌다. OSX 단에서 설치한 한글 사전은 어디에서도 제대로 동작하지 않았다. BACK TO THE MAC에서 항상 추천하는 한글 맞춤법 검사기 "단디" 역시 나에게는 해당 사항이 없었다. 왜냐하면, 단축키를 지정해도 Emacs던 Aquamacs던 동작하지 않고, 설혹 가능해도 단순히 확인할 수 있을 뿐 수정은 직접 해주어야 하는 점 때문이다. 나에게는 Hunspell이 필요했다.

모든 문제의 시작은 Hunspell임을 직감하고, 어떻게 해도 이를 활성화 할 수 없었던 Aquamacs를 포기하고 Original GNU Emacs에 가장 가깝다고 하는 Emacs Cocoa로 전환하기로 결정했다. 다행히, OSX Yosemite Emacs Cocoa에서 Hunspell을 쓰는 방법을 찾았다. (Linux에서 GNU Emacs로 hunspell 이용은 사실 자명하다.) 이는 위에서 언급한 지난 두 글에서 자세히 설명했지만, 핵심은 OS 마다 적절한(?) Emacs version을 써야 하는 점이다. 그러면 문제 해결은 비교적 간단하다.

언제나 그렇듯이, 한글이 항상 문제(?)다. 어지간히 Emacs에서 한글을 써본 사람은 다 알겠지만, Linux를 제외한 OS에서 OS 단에서 제공하는 한/영 변환은 항상 문제를 일으키므로, Emacs 자체에서 제공하는 입력 소스 변환을 쓰는 것이 항상 추천된다. 이는 OSX Yosemite에서도 바람입력기를 통해 간단히 해결할 수 있다. Hunspell을 Emacs에서 쓸 수 있게 된다 하더라도 문제는 크게 두 가지가 남아있다.

첫째, ⌥x (M-x Emacs 기본 표기) ispell-word 후 *Choices* buffer 에서 한글이 잘린다

한글 잘림 in *Choices* buffer

이는 한글과 영어를 다른 크기로 지정함으로써, 어느 정도 해결 가능하다. 아래는 영어는 Anonymous Pro 10으로, 한글은 HCR Dotum LVT 16으로 만든 경우이다.

;; Setup different font family and size for English/Korean
(setq default-frame-alist
      '(
	(top . 0) (left . 182) (width . 96) (height . 36)   ---> window position and size
	))
(when (eq system-type 'darwin)
  (set-face-attribute 'default nil :family "Anonymous Pro")
  default font size (point * 10)
  (set-face-attribute 'default nil :height 195)
  (set-fontset-font t 'hangul (font-spec :name "HCR Dotum LVT-16"))
  )

이렇게 하면 한글 폰트 크기가 전반적으로 바뀌면서, *Choices* buffer 에서도 한글이 잘리지 않는다. 두벌식 사용자라면, ispell-word 단축키만 따로 지정해도 적당히 쓸 만한 환경을 구축할 수 있다.

나는 세벌식390 사용자다. 문제가 심각해졌다. Emacs 자체 입력 소스를 설정하면 한글 세벌식 입력 환경에서 *Choices* buffer 안에서 단어 선택이 안된다. Emacs 자체 입력 소스를 끄고, OSX 입력 소스를 쓰면 *Choices* buffer 안에서 단어 선택은 되지만, ⌥x 같은 Emacs 단축키가 안먹는다!!! 어떤 세벌식을 쓰는 지와는 무관하게 세벌식 모두(보통, 390, 최종)에서 다 안된다. 이는 Yosemite 이전에 Aquamacs (Aquamacs 2.5x 이하 버전) 사용 시는 발생하지 않는 문제였다.이 문제를 해결하기 위해서 Flyspell-mode에서 마우스 우클릭하면 팝업창이 뜨는 것에 착안, 이를 키보드로 쓸 수 있는 방법을 여기서 기술했다. 이 방법은 당연하게도 두벌식이든 세벌식이든 상관없다. 게다가 ispell-word 를 쓸 때에도 불만이었던, "화살표키로 단어선택이 안되던 문제"에서 자유롭다. 가능한 한 키보드로 모든 것을 해결하려는 이들에게 숫자키로 가는 손가락은 화살표키보다 불편하다.

지난 글과 여기에서 설명하려한 방법의 목적을 다시 정리하자면, " 어떤 한글 입력 방법을 쓰던 상관 없이 Emacs에서 맞춤법 검사 과정 전부를 키보드로 해결하자! "이다. Emacs 버전을 타는 경향이 있지만, 이는 OSX 전반은 물론 Debian GNU/Linux에서도 큰 수정 없이 바로 쓸 수 있는, 현재로써는 가장 완벽한 해결책이다.


Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Created: 2015-06-04 Thu 11:21

Emacs 24.3.1 (Org mode 8.2.10)

Saturday, May 30, 2015

Hunspell for Emacs in OSX

Hunspell for Emacs in OSX

Hunspell for Emacs in OSX


This post is written with e[ ⎋Esc ]m[ ⌥Meta ]a[ ⌥Alt ]c[ ^Ctrl ]s[ ⇧Shift ] org-mode.


System Environments

Operating Systems

  • Main- : OS X Yosemite (10.10.3)
  • Sub- : Debian GNU/Linux Wheezy (7.8)
  • Server: Debian GNU/Linux Wheezy || Squeeze
  • Mobile: iOS 7.1.2

Hunspell and Emacs under OSX

Hunspall is one of the famous spell-checker softwares and GNU licensed. However, it is tricky to use it. Furthermore, the latest Emacs porks provided not only by Emacs Cocoa, but also by MacPorts and all Aquamacs can not be applicable to Hunspell as long as I have tried. Frankly speaking, the only way I know how to make Hunspell work in Emacs is the Emacs Cocoa 24.3.1 Installation of hunspell is done by means of MacPorts. Note that a English-Korean multilingual environment is taken in this post as an example.

Additionally, dictionary-toggling in Emacs will be at issue of this post as well.

Instruction for Hunspell in Emacs Cocoa with English-Korean under OSX

  1. It assumed that MacPorts were already installed, so that ready to use.
  2. Install Hunspell and its English library via MacPorts
    $ sudo port install hunspell hunspell-dict-en_US
    
  3. See paths for hunspell and hunspell-dict-en_US by running
    $ hunspell -D
    

    They must be /opt/local/bin/hunspell and /opt/local/share/hunspell/en_US.

  4. Download Hunspell dictionary for Korean: Homepage, download page, or "direct download"
  5. After unzipped ko-aff-dic-0.5.6.zip, locate two files ko.aff and ko.dic into ~/Library/Spelling/.
  6. Open the Emacs preference file ~/.emacs and add library-information as the following elisp
    (setq ispell-local-dictionary-alist
    '(
      ("english-hunspell"
       "[A-Za-z]" "[^A-Za-z]" "[0-9a-zA-Z]" t
       ("-d" "/opt/local/share/hunspell/en_US")   ;; <--- exact path
       nil utf-8)
      ("korean-hunspell"
       ;; "[가-힝]" "[^가-힝]" "[0-9a-zA-Z]" nil   ;; <--- emacs 22이하
       "[가-힣]" "[^가-힣]" "[0-9a-zA-Z]" nil   ;; <--- emacs 23이상
       ("-d" "/Users/JOHN/Library/Spelling/ko")   ;; <--- JOHN indicates you in OSX
       nil utf-8)
      ;; ("german-hunspell"
      ;;  "[a-zäöüßA-ZÄÖÜ]" "[^a-zäöüßA-ZÄÖÜ]" "[']" t
      ;;  ("-d" "de_DE")
      ;;  nil utf-8)
      )
    )
    

    Remember that a) you have to use exact paths ,not like ~ for your home directory and b) JOHN above must be replaced by your name in OSX. FYI) If you wanna use a triple lingual environment such as German together, you can uncomment the last four sentences and modify a library.

  7. And put the Hunspell information
    (setq ispell-program-name "/opt/local/bin/hunspell"   ;; <--- exact path in OSX 10.10
          ispell-dictionary "english-hunspell")
    (setq ispell-really-hunspell t)   ;; <--- optional??? working w/o it in emacs(cocoa)
    

Toggle libraries

It must be great to change libraries with a keyboard stroke, like ^\ (C-\ in typical Emacs notation) for toggle-input-method rather than type it after ⌥x (M-x in typical Emacs notation). I set the toggle for libraries by ⇧SPC (S-SPC in typical Emacs notation). Add the following into ~/.emacs

;; ### korean-english
(let ((langs '("korean-hunspell" "english-hunspell")))
  (setq lang-ring (make-ring (length langs)))
  (dolist (elem langs) (ring-insert lang-ring elem)))
(defun cycle-ispell-languages ()
  (interactive)
  (let ((lang (ring-ref lang-ring -1)))
    (ring-insert lang-ring lang)
    (ispell-change-dictionary lang)))
;; ### key bindings
(global-set-key (kbd "S-SPC") 'cycle-ispell-languages)

Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Footnotes:

1

Exact version of the Emacs Cocoa working with Hunspell is 24.3.1. Other versions I have tested are 24.5-1, 24.4, and 23.4, which all I failed to use smoothly.


Created: 2015-05-30 Sat 21:01

Emacs 24.3.1 (Org mode 8.2.10)