Showing posts with label tech. Show all posts
Showing posts with label tech. Show all posts

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.

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

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

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.

Friday, October 30, 2009

How to make forward-word, backward-word, treat underscore as part of a word?

This tip is via here. For MATLAB, the corresponding command is:
(modify-syntax-entry ?_ "w" matlab-mode-syntax-table)

Tuesday, October 27, 2009

Monday, October 12, 2009

Currency Conversion in Google

Search for: 20 $ in lira Much more here.

Saturday, August 22, 2009

Weather Information on Command Line

Weather information can be obtained at command line using a Python script that retrieves the weather information from Yahoo API found here at GitHub.

For Ankara, the location code is TUXX0003 and I aliased it in ~/.bash_profile as:

alias hava='weather.py TUXX0003 -m c -f 2'

Tuesday, August 18, 2009

Compiling Documents via Both LaTeX and XeLaTeX

To compile files that require XeLaTeX-specific options using LaTeX, use the \ifx\XeTeXversion\undefinedcheck.

\documentclass[a4paper,12pt]{report}

\ifx\XeTeXversion\undefined
\usepackage[utf8]{inputenc}
\else
\usepackage{fontspec}
\usepackage{xunicode}
\usepackage{xltxtra}
\setmainfont[Mapping=tex-text]{Gentium}
\fi

\begin{document}


\ifx\XeTeXversion\undefined
Hello World from LaTeX!
\else
Hello World from XeLaTeX!
\fi


\end{document}

Sunday, August 16, 2009

Thursday, July 23, 2009

Setting a Lefty and a Righty Mouse in Linux at the Same Time

If you want to use two mouses in Linux, and want one of them lefty and the other righty: use this:

xinput set-button-map 2 3 2 1
will reverse the buttons of the mouse numbered 2. To get a list of the mouses,
xinput list
or
xsetpointer -l

Combining both, to set the Microsoft mouse as lefty for example, use:

xinput set-button-map `xsetpointer -l|grep Microsoft|cut -c 1` 3 2 1

This is not persistent across sessions.

Tuesday, July 21, 2009

Scroll Lock Mode in Emacs

This is nice for reading a source file, such that the cursor stays always at the right spot.

(global-set-key (quote [Scroll_Lock]) 'scroll-lock-mode)
to map it to the Scroll Lock key.

Also see: Centered Cursor Mode

Saturday, July 18, 2009

Listing Package Contents in Debian

The command

 dpkg -L   
lists the files installed with a package. Ex: dpkg -L iceweasel

Thursday, July 16, 2009

Opening Files from the Command Line via the Default Application

Files can be opened from the command line as if they were double clicked.

  1. On Windows, simply typing the name of the file should work IIRC.
  2. On OS X, there is the open command.
  3. On KDE and Gnome, there are kde-open and gnome-open respectively.

I have created a function in my .bashrc, so that I can open files by the command o. Just add it to ~/.bashrc and source .bashrc or reboot(!)

function o
{
  kde-open "$@" &>/dev/null &             
}

This sends all stdout and stderr to outer space in order to save you an Enter press, so beware.

Bonus: Actually, all this was done so that I can open the files in dired mode in emacs by their default application, pdf, jpg, mp3 files etc.

(define-key dired-mode-map "o" 'dired-launch-command)
(defun dired-launch-command ()
  (interactive)
  (dired-do-shell-command
   (case system-type
     (gnu/linux "kde-open") ;right for gnome (ubuntu), not for other systems
     (darwin "open"))
   nil
   (dired-get-marked-files t current-prefix-arg)))

Now in dired mode, pressing 'o' will open the file in the default application.

See here if that doesn't work.

Ans in Bash: Using the Output of the Latest Command in Bash

MATLAB shell has a sometimes useful variable called ans which you can use in your current calculations as a variable. My TI-83 had one as well actually, but Bash doesn't have one. :)

So, suppose you want to make use of the latest Bash command output. Using !! will redo the previous command. Using !! inside backticks (` `) or $( ) will give its output, as any other Bash command. (Although the $ notation is preferred, the backtick is more convenient in this particular case.)

So, operating on the last output is as simple as:

command_name `!!`

Note that this redoes the previous action, doesn't actually make use of the latest output.

One example:

$ which firefox
/usr/bin/firefox
#This is usually the symlink, we want to learn where the actual target is.
$ ls -l `!!`

Another one:

$ find -name "*.org"
$ emacs `!!`

Note that the -exec option of find or feeding to xargs might be more suitable in most cases, but this is just for demonstration.

Of course, C-p C-a command_name ` C-e ` is an option, but this seems easier.

Inspired via: http://feedproxy.google.com/~r/Command-line-fu/~3/mvkfpS8SZfw/edit-list-of-files-in-last-command

Emacs Shortcuts on Command Line

Via readline, some of Emacs' keybindings are available on the command line.

I was aware some shortcuts like C-a, C-e, C-r were already working; but was surprised to discover that even more are available, like undo, capitalize word etc.

Via:

http://www.catonmat.net/blog/bash-emacs-editing-mode-cheat-sheet/ and from "man readline"
 "C-@"  set-mark
 "C-A"  beginning-of-line
 "C-B"  backward-char
 "C-D"  delete-char
 "C-E"  end-of-line
 "C-F"  forward-char
 "C-G"  abort
 "C-H"  backward-delete-char
 "C-I"  complete
 "C-J"  accept-line
 "C-K"  kill-line
 "C-L"  clear-screen
 "C-M"  accept-line
 "C-N"  next-history
 "C-P"  previous-history
 "C-Q"  quoted-insert
 "C-R"  reverse-search-history
 "C-S"  forward-search-history
 "C-T"  transpose-chars
 "C-U"  unix-line-discard
 "C-V"  quoted-insert
 "C-W"  unix-word-rubout
 "C-Y"  yank
 "C-]"  character-search
 "C-_"  undo
 " " to "/"  self-insert
 "0"  to "9"  self-insert
 ":"  to "~"  self-insert
 "C-?"  backward-delete-char

 Emacs Meta bindings

 "M-C-G"  abort
 "M-C-H"  backward-kill-word
 "M-C-I"  tab-insert
 "M-C-J"  vi-editing-mode
 "M-C-M"  vi-editing-mode
 "M-C-R"  revert-line
 "M-C-Y"  yank-nth-arg
 "M-C-["  complete
 "M-C-]"  character-search-backward
 "M-space"  set-mark
 "M-#"  insert-comment
 "M-&"  tilde-expand
 "M-*"  insert-completions
 "M--"  digit-argument
 "M-."  yank-last-arg
 "M-0"  digit-argument
 "M-1"  digit-argument
 "M-2"  digit-argument
 "M-3"  digit-argument
 "M-4"  digit-argument
 "M-5"  digit-argument
 "M-6"  digit-argument
 "M-7"  digit-argument
 "M-8"  digit-argument
 "M-9"  digit-argument
 "M-<"  beginning-of-history    "M-="  possible-completions    "M->"  end-of-history
 "M-?"  possible-completions
 "M-B"  backward-word
 "M-C"  capitalize-word
 "M-D"  kill-word
 "M-F"  forward-word
 "M-L"  downcase-word
 "M-N"  non-incremental-forward-search-history
 "M-P"  non-incremental-reverse-search-history
 "M-R"  revert-line
 "M-T"  transpose-words
 "M-U"  upcase-word
 "M-Y"  yank-pop
 "M-\"  delete-horizontal-space
 "M-~"  tilde-expand
 "M-C-?"  backward-kill-word
 "M-_"  yank-last-arg

 Emacs Control-X bindings

 "C-XC-G"  abort
 "C-XC-R"  re-read-init-file
 "C-XC-U"  undo
 "C-XC-X"  exchange-point-and-mark
 "C-X("  start-kbd-macro
 "C-X)"  end-kbd-macro
 "C-XE"  call-last-kbd-macro
 "C-XC-?"  backward-kill-line

PS: C-/ also works for undo. Note that C-w is not the same as the Emacs default.

PPS: This is my current .inputrc, mostly the same as /etc/inputrc, except the last 8 lines.

# /etc/inputrc - global inputrc for libreadline
# See readline(3readline) and `info rluserman' for more information.

# Be 8 bit clean.
set input-meta on
set output-meta on

# To allow the use of 8bit-characters like the german umlauts, comment out
# the line below. However this makes the meta key not work as a meta key,
# which is annoying to those which don't need to type in 8-bit characters.

# set convert-meta off

# try to enable the application keypad when it is called.  Some systems
# need this to enable the arrow keys.
# set enable-keypad on

# see /usr/share/doc/bash/inputrc.arrows for other codes of arrow keys

# do not bell on tab-completion
# set bell-style none
# set bell-style visible

# some defaults / modifications for the emacs mode
$if mode=emacs

# allow the use of the Home/End keys
"\e[1~": beginning-of-line
"\e[4~": end-of-line

# allow the use of the Delete/Insert keys
"\e[3~": delete-char
"\e[2~": quoted-insert

# mappings for "page up" and "page down" to step to the beginning/end
# of the history
# "\e[5~": beginning-of-history
# "\e[6~": end-of-history

# alternate mappings for "page up" and "page down" to search the history
# "\e[5~": history-search-backward
# "\e[6~": history-search-forward

# mappings for Ctrl-left-arrow and Ctrl-right-arrow for word moving
"\e[1;5C": forward-word
"\e[1;5D": backward-word
"\e[5C": forward-word
"\e[5D": backward-word
"\e\e[C": forward-word
"\e\e[D": backward-word

$if term=rxvt
"\e[8~": end-of-line
"\eOc": forward-word
"\eOd": backward-word
$endif

# for non RH/Debian xterm, can't hurt for RH/Debian xterm
# "\eOH": beginning-of-line
# "\eOF": end-of-line

# for freebsd console
# "\e[H": beginning-of-line
# "\e[F": end-of-line

$endif
"\e[A": history-search-backward
"\e[B": history-search-forward
"\M-o": "\C-p\C-a\M-f "
set match-hidden-files off
set completion-ignore-case on
set visible-stats on
set show-all-if-ambiguous on
"\M-s": menu-complete