Sunday, February 28, 2010

emacs türkçe modu

Daha önce Deniz Yüret'in emacs için yazdığı Türkçe modundan bahsetmiştim. Söz konusu eklenti sayesinde Türkçe'ye özgü olan ı, ş, ü gibi harfleri yerine i, s, u harflerini kullanarak yazdığınız bir yazıdaki gerekli yerlere otomatik olarak bu harfler ekleniyor. Son yapılan değişiklerle emacs'in son sürümü ile uyumlu hale getirilen bu modu her Türk emacs kullanıcısının denemesini tavsiye ederim.
Bu eklenti sayesinde, Google Chrome'daki Edit in emacs ya da Firefox'taki It's All Text eklentisini kullarak Gmail gibi web tabanlı yerlerdeki epostalarınızı da emacs içinden yazıp tarayıcı içerisine otomatik olarak atabilirsiniz.

Kurulum:

  1. turkish.el dosyasını bir klasöre kaydedin.
  2. (load-file "~/dosya-yolu/turkish.el") gibi bir satırı emacs başlangıç dosyanıza koyarak dosyanın yüklenmesini sağlayın.
Etkinleştirme:
Yukarıdaki komut dosyayı sadece hafızaya alacaktır, etkinleştirmeyecektir.Herhangi bir modda bu minör modu etkinleştirmek için M-x turkish-mode komutunu girin.

Otomatik Etkinleştirme:

Eğer modu text-mode gibi belli bir majör modla otomatik olarak etkinleştirmek istiyorsanız emacs başlangıç dosyanıza şu satırı ekleyin:
(add-hook 'text-mode-hook 'turkish-mode)
Google Chrome ile Edit in Emacs kullanıyorsanız şu satırı ekleyin:
(add-hook 'edit-server-text-mode-hook 'turkish-mode)

Modun diğer özellikleri

  1. Modun bir harfte yaptığı değişikliği geri almak için o harfin üzerine gidin ve Ctrl-T tuşlarına basın. 
  2. Modun son sözcükte yaptığı değişikliği geri almak için sözcük sonunda Alt-T tuşlarına basın.
  3. Başka yerden kopyalayıp yapıştırdığınız bir metni düzeltmek için turkish-correct-buffer fonksiyonunu kullanın, sadece belli bir bölgeyi düzeltmek için ise turkish-correct-region fonksiyonunu kullanın.
Son olarak, modla ilgili yorumlarınızı şu adrese bırakabilirsiniz.

Saturday, February 27, 2010

Opera and vi Style Navigation Scrolling Shortcuts

I'm an emacs user, but honestly, vi style navigation is better if you are a touch typist. By vi style navigation, I mean scrolling down with j and up with k, and with these keys, you can keep your hands on the home row.

One thing that annoys me reading web pages is that in order to scroll, I have to press the down button instead; however this has an easy fix in Opera since it supports customizable one key shortcuts.

  1. Go to Tools - Preferences.
  2. Go to Advanced - Shortcuts
  3. Select Enable single-key shortcuts.
  4. Duplicate the current keyboard  setup by pressing Duplicate.
  5. Select the new duplicate keyboard setup, press Edit.
  6. Select the Browser Window group.
  7. Select  New, for the shortcut, enter "j", for the command, enter Scroll down.
  8. Select  New, for the shortcut, enter "k", for the command, enter Scroll up
  9. Select OK, and make sure you select the duplicate, not the original keyboard set.

Now, you can scroll down with j and up with k. This works in all sites except those that make use of j already, like Gmail and Google Reader.  j and k already have different functions in those sites.

Combined with this Readability tip, it makes perusing the web much nicer.

Opera and Readability Bookmarklet Shortcut

Arclab's Readability is a browser bookmarklet that gets the text of the current webpage you are viewing, and reformats it for a much better reading experience. Since it is Javascript based, it is usable with most browsers.

One catch though is, one has to click the readability link and there is no keyboard shortcut. I have seen a Google Chrome extension that assigns a keyboard shortcut to readability, and since Opera is my browser of choice, came up with a solution for Opera.

  1. Go to http://lab.arc90.com/experiments/readability/ and select your preferred style.
  2. Now, instead of dragging the bookmarklet to your toolbar, right click it and select "Copy Link Address".
  3. Go to the Speed Dial page in Opera, and assign one of the speed dial pages (1-9) with the link you copied.
  4. Now, you can view any page with Readability by pressing Ctrl-1 for example if you have assigned the Readability for the first SpeedDial page. 

Also see http://www.ustunozgur.com/2010/02/opera-and-vi-style-navigation-scrolling.html for more reading tips within Opera.

Alternative Method:

The method above, though simple forces you to sacrifice a speeddial just for Readability. Also, one can't assign an alternative keyboard shortcut, like Ctrl-r to his liking. An alternative approach is to assign a shortcut in Opera that goes to the Readability bookmarklet:

  1. Copy the Readability bookmarklets url to clipboard as above. 
  2. Go to Tools-Preferences.
  3. Go to Advanced-Shortcuts.
  4. Keyboard setup, Edit.
  5. Click on Application.
  6. Click New, for the shortcut key, Enter r Ctrl if you want Ctrl-r for readability.
  7. For the  action, enter Go to page," (with only opening quote), then paste the url and close the quote "
  8. Now, Ctrl-r is assigned to reload by default, search for r ctrl and remove that assignment in the shortcuts list.
  9. Pressing Ctrl-r on any page will format it using Readability now. Obviously, this method works for any bookmarklet, for example, Instapaper. 

Sunday, February 21, 2010

emacs'i daemon modda çalıştırma

Daemon Mod Nedir?

emacs 23.1'den beri daemon modu ile birlikte gelmekte. Daha önceden var olan server moduna benzeyen bu mod sayesinde arkaplanda, penceresiz çalışan bir emacs daemonınız oluyor. Daha sonra dosyaları hızlıca emacsclient ile daemona bağlanarak açabiliyorsunuz. Böylece emacs'ın açılma anındaki yavaşlığı tamamen ortadan kalkıyor.

Çalıştırma

emacs'ı daemon modu ile başlatmak için emacs --daemon komutunu kullanabilir, daha sonra da dosyaları emacsclient ile açıp bu daemona bağlanabilirsiniz. Dosya ile işiniz bittiğinde C-x # komutu ile pencereyi kapatabilirsiniz; emacs arkaplanda çalışmaya devam edecektir.

Alternatif (ve daha güzel) Yöntem

Bunu yapmanın daha kolay bir yolu ise ~/.bashrc dosyasına export ALTERNATE_EDITOR="" satırını eklemek. Bu satırı ekledikten sonra emacs'ı açmak için kullanmanız gereken tek komut emacsclient. Çalışan bir emacs daemoni yoksa emacsclient, emacs komutunu çağırıp yeni bir daemon yaratacak, çalışan daemon varsa doğrudan o daemon'a bağlanacaktır.

emacs'i Terminalden kullanmak

Dosyaları GUI'siz terminalde açmak için ise emacsclient -t komutunu kullanabilirsiniz.

Kısayollar

Daha sonra yapmanız gereken ~/.bashrc dosyasına kolay kullanım için birkaç alias eklemek:

alias vi="emacsclient -t" #Terminalden kullanmak icin 
alias e="emacsclient -c" # GUI ile açmak için

GUI'de ise istediğiniz dosya uzantılarını (.c, .java gibi) emacsclient ile açılacak şekilde ayarlarsanız dosyalara çift tıkladığınızda anında açılacaktır.

Daemon'ı Sonlandırma

emacs daemon kullanırken dikkat edilmesi gereken önemli bir konu da daemon sürecinin düzgün sonlandırılması.

Doğrudan oturumu kapatır ya da bilgisayarı kapatırsanız desktop-save kullanıyorsanız (son oturumda açık olan dosyaların yeniden açılmasını sağlayan eklenti) daemon emacs desktop dosyasına bir lock koyacak, daha sonraki daemonların açılmasını engelleyecektir. (Açılış sırasında .emacs.desktop locked gibi bir hata mesajı verebilir.)

Bu nedenle emacs daemonini düzgün kapatmak sonraki oturumlarda daemonin çalışması için çok önemlidir. Bunu yapmanın en kolay yolu ise emacs içerisinden M-x save-buffers-kill-emacs komutu ile bufferları kaydedip daemoni sonlandırmaktır; ancak bu yöntemin en önemli sorunu bilgisayarı kapatırken bu komutu çalıştırmayı unutmak. Bu konuda daha detaylı bilgiye http://stackoverflow.com/questions/1167484/how-to-gracefully-shutdown-emacs-daemon adresinden ulaşabilirsiniz.

Sonuç

emacs daemon sayesinde dosyaları emacs ile çok hızlı bir şekilde açabilirsiniz. Bu daemonin önceki emacs-server eklentisine göre en önemli avantajı açıkta bir pencereye ihtiyaç duymaması, anlattığım alternatif yöntemle daemon yoksa yeni bir daemonı otomatik yaratması, aynı zamanda SSH ile bağlandığınızda var olan daemoni kullanmaya olanak tanıması.