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ı.

Friday, January 29, 2010

Revolution

On January 27th, 2010, 26 years after introducing Macintosh, Apple Computer introduced the iPad.
Mark this day. A revolution has just started.
Apple has once again redefined the PC.

Tuesday, November 24, 2009

Some Helpful CLI Utilities

These are mainly from this thread:

gt5 -- cli gui for du

autojump -- jumping to most used dirs

iptraf -- network monitor

Monday, November 23, 2009

git clean

git has a nice switch to clean untracked and/or ignored files. git help clean for more info.

Saturday, November 14, 2009

Adding All Subfolders to the Path in MATLAB

This is a quick tip:

addpath(genpath(pwd))

adds the current dir and its subfolders (recursively) to the path in MATLAB.

Thursday, November 12, 2009

Git GUI Fails to Load on OS X and How to Solve It

I don't use git gui much, I mainly prefer the command line or magit or GitX, but git gui might be useful sometimes, especially with the OpenInGitGui Finder extension. 

When installed, git gui by default doesn't work (at least on my Macbook running Leopard); and fails with the message: 

dyld: Library not loaded: /Library/Frameworks/Tk.framework/Versions/8.5/Tk Referenced from: /usr/local/git/share/git-gui/lib/Git Gui.app/Contents/MacOS/Wish Reason: image not found error: git-gui died of signal 5

Clearly, the Tk framework 8.5 is missing and can be downloaded from here. (Also see here) Once that is installed, everything works properly.

Thursday, November 05, 2009

Connecting to ssh servers running on non-standard ports

If you are running your ssh server on a port different than 21, for example 22, you can connect to the machine like this:

ssh mymachineip:22

or 

ssh mymachineip -p 22

However, there is an easier way:

Create the file  ~/.ssh/config, then fill it like this:

Host mymachineip

Port 22

Now you can just ssh to the machine: ssh mymachine

Monday, November 02, 2009

Reconnecting to a screen session

When there is only one screen session, screen -raAD attaches to the running screen. So far so good.  

However, if for some reason, there are more than one screen sessions, (screen -ls should give you those), screen suggests that you need to do screen -r  [[pid.]tty[.host]] to reattach. 

However, this simply doesn't work at first and yields weird errors like:

There is a screen on: 5541.pts-1.shannon (11/02/2009 04:40:02 PM) (Attached) There is no screen to be resumed matching 5541.pts-1.shannon.

This is utterly confusing, since it first says that there is a screen, but there is no screen to be resumed. What this means actually is just that however: one first has to detach that screen in order to attach to it. So, yes, there is a screen and that screen is not a screen one can connect directly.

The solution is to give the -d parameter to detach it at first, so

screen -d -r  5541.pts-1.shannon

should work. In fact, I guess screen -r -d 554 works too. That 554 portion has to be unique though, so screen -r -d 5 works too if no other screen session starts with a 5.

Sunday, November 01, 2009

Some Git Tips

  1. git add -u to add all modified files in the index.
  2. git checkout -f to trash all uncommitted changes. Useful before pulling.
  3. git stash as an alternative to above.
  4. git diff --cached to see the added changes.
  5. git rebase to squash multiple commits into a commit before pushing. Rebasing is useful for other stuff, but that needs more exploration.   git rebase -i origin/master to merge all unpushed commits.
  6. git commit --amend might be an alternative for that as well. 
  7. See here for some other tips.