Showing posts with label emacs. Show all posts
Showing posts with label emacs. 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.

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

Thursday, July 16, 2009

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

Wednesday, July 01, 2009

Latest version of MATLAB.el for Emacs

The file in the goodies package in Debian is old, and doesn't support parfor. The latest is here: http://sourceforge.net/scm/?type=cvs&group_id=154105

Saturday, June 20, 2009

Elisp Codebook

Snippets from the emacswiki are here

Wednesday, June 17, 2009

Tuesday, May 12, 2009

Improve Focus-Follows-Mouse Behaviour under Emacs

Just use the file here so that focus follows the window the pointer is on.

Sunday, March 01, 2009

Markdown ve ReStructuredText: Hafif Siklet Isaretleme Dilleri (Lightweight Markup Languages)

Dökümentasyon ya da basit belgeler oluştururken HTML ya da XML gibi bir işaretleme dili kullanmak zor gelebilir. WYSWYG türü Word benzeri programlarda belge hazırlamak da bazı konularda özgürlüğünüzü kısıtlar.

Bu gibi durumlarda İngilizce lightweight markup language olarak tabir edilen hafif sıklet işaretleme dillerini kullanmak uygun bir çözüm. Bu belgelerde metnin nasil gorunecegiyle ilgili kucuk isaretler kullanilmakta ve bu sekilde duz metin de olsa okunakli bir gorunum elde edilmekte. Daha sonra bu metinler bazi parserlardan gecirilip diger formatlara aktarilabilmekte.

Ben önceden reStructured Text kullanıyordum. Bugün markdown adı verilen (markup vs markdown ;) bir işaretleme diliyle karşılaştim. İkisi birbirine oldukça benziyor; genel kanı, LaTeX ya da PDF gibi formatlara dönüştürme hedefiniz yoksa ve inline (kaynak kod içi) dökümentasyon hazırlamıyorsanız, yani sadece HTML çıktısıyla ilgileniyorsanız markdown'in daha kolay bir çözüm olduğu yönünde. 

Ayrica rst'nin kullanımı emacs'te oldukça kolay olmakla beraber markdown daha metin editör bağımsız bir ortam sunuyor gibi.

Markdown'da belge hazirlama

Baslik ve altbasliklar

Bunlar baslik ya da altbaslik metninin basindaki # isaretlerinin sayisiyla belirleniyor. Ornegin en ust baslik (h1) icin, # Ana Baslik yazmaniz yeterli. Bir alt baslik (h2) da bu durumda ## Alt baslik olarak yaziliyor.

Kalin ve italik yazilar

Italik yazilacak metinlerin soluna ve sagina * isareti koymak gerek. Kalin olmasi icin ise sola ve saga ** koymak gerek. Ornegin, *bu metin italik*, ** bu metin kalin olacak**.

Listeler

Liste olusturmak icin her ogeyi alt alta yazip satir basina -, * gibi isaretleri koymak gerekiyor. Icice liste olusturmak icin de iki satir iceriden yeni bir isaretle baslamak gerek. Ornegin:

- elma
  * golden
  * starking
  *grannysmith
- armut
- muz

Link (baglanti) verme

Satirici ve referans olarak ikiye ayriliyor. Ayni linki birden fazla kullanacaksaniz referans turunu tercih edebilirsiniz.

Satirici link vermek icin Bu [ornek link](http://example.com/) kullanin. Referans linki vermek icin ise su kalibi kullanin. Ornek:

[gorunmesini istediginiz metin][referans adi]

Daha sonra, asagida bir yerde referanslarin hangi URL'e isaret ettigini gostermek icin,

[referans adi] http://www.cnn.com kismini ekleyin.

Kod bloklari

Kod bloklari icin basa ve sonra ` isareti koyun.

Daha fazla bilgi icin: Markdown Basics'e goz atin. Markdown'i aninda HTML'e donusturen bir online editor icin: http://attacklab.net/showdown/

Diger Kaynaklar

  1. http://en.wikipedia.org/wiki/Lightweight_markup_language

  2. Bir karsilastirma - http://stackoverflow.com/questions/34276/markdown-versus-restructuredtext

  3. Markdown'la ilgili kaynaklar:
  4. http://en.wikipedia.org/wiki/Markdown
  5. Online markdown derleyici: http://daringfireball.net/projects/markdown/dingus

  6. reStructuredText ile ilgili kaynaklar:
  7. http://docutils.sourceforge.net/rst.html

Friday, May 09, 2008

Matlab in Aquamacs under OS X 10.5

One can use Matlab without the IDE, under emacs. You need to set the value of matlab-shell-command-switches to '("-nojvm -nosplash") , and in .bash_profile; append export DISPLAY=localhost:0.0

Friday, April 25, 2008

Narrow to Region / Code Folding in Emacs

You can hide/show certain parts of a document using: - narrow-to-region : C-x n n - narrow-to-page : C-x n p - show all : C-x n w To define a page, insert ^L characters to keypoint by " C-q C-l". See also: All-out mode

Skeletons for Emacs

(define-skeleton skeleton-c++-mode-cout
" Prints out a variable using cout " 
" Print variable : "
"\ncout << \" " str "\" << " str " << endl;\n" )

(global-set-key [?\C-p] 'skeleton-c++-mode-cout)
This code snippet will automatically create a cout line for a variable.

Turkish mode : turkish.el for emacs

http://www.denizyuret.com/turkish/turkish.el "This is for people trying to type Turkish documents on a U.S. keyboard." See http://denizyuret.blogspot.com/2006/11/emacs-turkish-mode.html For example, if you write Ustun, it will automatically convert that to Üstün.

.emacs

I prefer Aquamacs. On Windows, I use Emacs W32. The following is for Aquamacs.

(setq mac-command-modifier 'meta)
(setq mac-option-modifier 'meta)


(setq inhibit-startup-message t)
(defun my-c-initialization-hook ()
 (define-key c-mode-base-map "\C-m" 'c-context-line-break)
 (add-hook 'c-initialization-hook 'my-c-initialization-hook)
)
(global-set-key [C-tab] 'next-buffer)
(global-set-key [C-S-tab] 'previous-buffer)
(global-set-key [S-tab] 'other-window)
(global-set-key [f2] 'save-buffer)
(global-set-key [f5] 'speedbar)
(global-set-key [f7] 'my-save-and-compile)
(global-set-key [f6] 'other-window)
(global-set-key [C-f6] 'comment-or-uncomment-region-or-line)
;(global-set-key [A-tab] 'other-window)
(global-set-key [M-f12] 'calendar)
(global-set-key [M-f9] 'kill-some-buffers)
(global-set-key [C-f4] 'kill-current-buffer)
;(global-set-key [?\A-h] 'mark-paragraph) sfsdfsdf 

(global-set-key [?\A- ] 'just-one-space)
(global-set-key [M-f1] 'man)
(global-set-key [?\A-n] 'new-frame)

(fset 'yes-or-no-p 'y-or-n-p)

;; Make control+pageup/down scroll the other buffer
(global-set-key [C-next] 'scroll-other-window)
(global-set-key [C-prior] 'scroll-other-window-down)
(global-set-key "\C-z" 'shell) ; or eshell
(global-set-key (kbd "M-a") 'execute-extended-command)

; return a backup file path of a give file path
; with full directory mirroring from a root dir
; non-existant dir will be created
(defun my-backup-file-name (fpath)
  "Return a new file path of a given file path.
If the new path's directories does not exist, create them."
  (let (backup-root bpath)
    (setq backup-root "~/.emacs.d/emacs-backup")
    (setq bpath (concat backup-root fpath "~"))
    (make-directory (file-name-directory bpath) bpath)
    bpath
  )
)
(setq make-backup-file-name-function 'my-backup-file-name)


(defun dotemacs ()
 "Open .emacs"
 (interactive)
 (find-file "~/Library/Preferences/Aquamacs Emacs/Preferences.el"))

(add-to-list 'load-path "~/elisp")
(setq-default abbrev-mode t)
(read-abbrev-file "~/.abbrev_defs")
(setq save-abbrevs t)

(setq require-final-newline 't)

;; Save the state of emacs
(desktop-save-mode 1)
(desktop-read)
(add-to-list 'desktop-globals-to-save 'file-name-history)



(defun kill-current-buffer ()
  "Kill the current buffer, without confirmation."
  (interactive)
  (kill-buffer (current-buffer)))


;; smarttab

;;;
;; Smart Tab

(defvar smart-tab-using-hippie-expand t
  "turn this on if you want to use hippie-expand completion.")

(global-set-key [(tab)] 'smart-tab)
(defun smart-tab (prefix)
  "Needs `transient-mark-mode' to be on. This smart tab is
minibuffer compliant: it acts as usual in the minibuffer.

In all other buffers: if PREFIX is \\[universal-argument], calls
`smart-indent'. Else if point is at the end of a symbol,
expands it. Else calls `smart-indent'."
  (interactive "P")
  (if (minibufferp)
      (minibuffer-complete)
    (if (smart-tab-must-expand prefix)
        (if smart-tab-using-hippie-expand
            (hippie-expand nil)
          (dabbrev-expand nil))
      (smart-indent))))

(defun smart-indent ()
  "Indents region if mark is active, or current line otherwise."
  (interactive)
  (if mark-active
      (indent-region (region-beginning)
                     (region-end))
    (indent-for-tab-command)))

(defun smart-tab-must-expand (&optional prefix)
  "If PREFIX is \\[universal-argument], answers no.
Otherwise, analyses point position and answers."
  (unless (or (consp prefix)
              mark-active)
    (looking-at "\\_>")))

;(load-library turkish.el)

(setq-default abbrev-mode t)

(read-abbrev-file "~/.abbrev_defs")

(setq save-abbrevs t)


;(setq initial-frame-alist '((top . 10) (left . 30)

 ;                           (width . 90) (height . 50)))

;(setq default-frame-alist '((width . 80) (height . 45)))

(setq speedbar-mode-hook '(lambda ()
    (interactive)
    (other-frame 0)))

(cd "/Users/ustun/Documents/")

(defun my-save-and-compile ()

(interactive "")

(save-buffer 0)

(compile compile-command)

)