Monday, January 05, 2015

Install Mew 6.6 to Emacs 24.4 for Windows

  • Mew 6.6 (Windows用バイナリ) をダウンロードする
  •  C:\emacs-24.4\bin\emacs.exe  もしくは C:\cygwin\usr\bin\emacs-w32.exe に対応させるべく mew.ini の該当箇所を以下のいずれかに書き換える
  • インストーラ mew.exe を起動する

Sunday, September 21, 2014

Force kill buffer

Occasionally I want to kill a buffer without prompt even it is modified or related with a process.
 (defun kill-buffer-no-prompt (&optional BUFFER-OR-NAME)
   "Kill current buffer, even if it has been modified."
   (let* ((buffer (if BUFFER-OR-NAME (get-buffer BUFFER-OR-NAME)
          (process (get-buffer-process buffer)))
     (if process (delete-process process))
     (when buffer
       (switch-to-buffer buffer)
       (set-buffer-modified-p nil)
       (kill-buffer buffer))))

Sunday, August 03, 2014

Emacs to Word

Emacs で書いた文章をワープロに持っていく時、改行を除きたいものです。 標準の M-^ だと改行が単語を割らないとしてスペースでつなぎます。日本語ではそのそのスペースが不要です。以下のように ssk-j-mode が non-nil 時だけ、そのスペースを取り除きます。

(defun delete-indentation-ja()
  "Join current to previous line without whitespace when
`skk-j-mode' is non-nil.  This is supposed to bind to `M-^'."
  (if skk-j-mode
(global-set-key (kbd "M-^") 'delete-indentation-ja)

Sunday, May 18, 2014

A package smartrep to save fifth finger on left hand

To move around windows, I have to type "C-x o" often.  A package "smartrep" reduces a burden on fifth finger on left hand.

(require 'smartrep)
(smartrep-define-key global-map "C-x"
  '(("o" . 'other-window)
    ("k" . '(lambda () (interactive) (kill-buffer (window-buffer))))    ("0" . 'delete-window)
    ("2" . 'split-window-below)
    ("3" . 'split-window-right)
    ("^" . 'enlarge-window)
    ("{" . 'shrink-window-horizontally)
    ("}" . 'enlarge-window-horizontally)))

Friday, April 11, 2014

Mac and Windows friendly setup

 Since all people in our laboratory refuse to use Emacs, I decided to make Emacs behave like other applications on Windows or Mac.

(global-set-key (kbd "s-x") 'kill-region)
(global-set-key (kbd "s-c") 'kill-ring-save)
(global-set-key (kbd "s-v") 'yank)
(global-set-key (kbd "s-z") 'undo)
(global-set-key (kbd "s-a") 'mark-whole-buffer)
(global-set-key (kbd "s-w") 'close-frame-or-kill-buffer)
(global-set-key (kbd "s-n") 'new-frame-with-new-buffer)
(defun new-frame-with-new-buffer ()
  "Create a new frame with a new buffer `untitled-n'."
  (let* ((n-th 1)
         (dir (format-time-string "~/deleteme.d/%Y-%m" (current-time)))
         (region-p (region-active-p)))
    (if region-p (kill-ring-save (region-beginning) (region-end)))
    (switch-to-buffer-other-frame "*scratch*")
    (make-directory dir t)
    (while (file-exists-p (setq file (format "%s/untitled-%d" dir n-th)))
      (setq n-th (+ n-th 1)))
    (find-file file)
    (emacs-lisp-mode) ;; to use (lispxmp)
    (when region-p
    (write-file file))
  (when (fboundp 'w32-send-sys-command)
    (w32-send-sys-command #xf030)
    (w32-send-sys-command #xf120)))
(defvar no-warning-close-frame-or-kill-buffer nil)
(defun close-frame-or-kill-buffer ()
  "Close a frame if there are more than two frames.  If there is
only one frame, kill selected-buffer.  To avoid closing
frame/buffer by mistype of M-w, prompt for an action for the
first time."
  (let* ((close-buffer-p (= 1 (length (visible-frame-list))))
        (name-obj (if close-buffer-p "buffer" "frame")))
    (if (or no-warning-close-frame-or-kill-buffer
            (setq no-warning-close-frame-or-kill-buffer
                  (yes-or-no-p (format "Are you sure you want to close a %s?" name-obj))))
        (if close-buffer-p (kill-this-buffer) (delete-frame)))))

Saturday, April 05, 2014

Specify a dedicated window for other-window in Emacs

There is a way to specify a window to be used by (other-window).  Also, after a buffer poped up on a unexpected window, you can slide it to the right place.

(winner-mode 1)
(defvar window-locked-p nil)

(defun lockon-window ()
  "Set a window for other-window.  To set the target window,
    move point to the window, then call this.  Technically this sets
    all window dedicated but the target window.  Call again to free
   (lambda (win)
     (set-window-dedicated-p win (not window-locked-p))))
  (if window-locked-p
      (message "Windows are free")
    (set-window-dedicated-p (selected-window) nil)
    (message "Window is locked on"))
  (setq window-locked-p (not window-locked-p)))

(defun freeze-window ()
  "This freezes or locks a window where point is.  Call again to unfreeze.
    Technically this toggles window-dedicate-p property of a window."
   (not (window-dedicated-p (selected-window))))
  (if (window-dedicated-p (selected-window))
      (message (format "%s is freezed" (selected-window)))
    (message (format "%s is free" (selected-window)))))

(defun slide-window ()
  "This slides a buffer in a window where point is to
    next-window.  Technically this recalls previous windows-set by
    winnder-undo then shows the buffer to next-window"
  (let ((buf (buffer-name)))
    (set-window-buffer (next-window) buf)
    ;; (switch-to-buffer buf)
    (message "Window is slided")
    (other-window 1)))

Wednesday, March 26, 2014

A price table for orgtbl-mode using Emacs

You don't need Excel for price calculation but Emacs + orgtbl.

| item     | vendor | price | n | cost |
| monitor  | Eizo   | 10000 | 2 |      |
| keyboard | Topre  |  5000 | 3 |      |
| total    |        |       |   |      |
#+TBLFM: $5=$3*$4::@>$>=vsum(@-II..@-I)

LaTeX table from Emacs org-table

To make a scientific LaTeX table using Emacs + yasnippet + org-tbl is very comfortable.  First you have to convert your table into orgtbl somehow.  To convert the orgtbl to a LaTeX table, use following snippet.  See also instruction for org-mode.

#contributor : Tak Kunihiro
#name : a new table
#key : table
#Last modified: Fri Feb 07 16:06:35 JST 2014
# --
% `(turn-on-orgtbl)`
% ${1:Results} ${2:are} shown in Table \\ref{${3:`(file-name-nondirectory (directory-file-name (file-name-directory buffer-file-name)))`/`(file-name-base buffer-file-name)`}}.
%% ---------------
\begin{tabular}{ ${7:lll} }
${4:name} & ${5:value} & ${6:remarks} \\\\
#+ORGTBL: SEND tbl:$3 orgtbl-to-latex :no-escape t
| $4 | $5 | $6 |
|      |       |         |
%% ---------------

Saturday, February 01, 2014

Interaction between bash and dired in Emacs

Switch back and forth between Dired on Emacs and bash on Terminal is a headache. Add a visiting directory onto "~/.bash_history" and refer it by "tail -n 1" will help with following setup.

on ~/.emacs.d/init.el
(require 's)
(add-hook 'dired-mode-hook 'append-pwd-bash-history)
(add-hook 'find-file-hook 'append-pwd-bash-history)
(defun append-pwd-bash-history (&optional DIR)
  "Append a DIR where Dired visited to `~/.bash_history'."
  (setq DIR (or DIR (expand-file-name default-directory)))
  (let ((DIROUT DIR))
    (with-current-buffer (find-file-noselect "~/.bash_history") ;; $HISTFILE
      (if windows-p
          (setq DIROUT (shell-command-to-string (format "cygpath %s" (shell-quote-argument DIR)))))
      (setq DIROUT (replace-regexp-in-string "\\([@ #]\\)" "\\\\\\1" DIROUT)) ; escape
      (unless (string= DIROUT "")
        (goto-char (point-max))
        (insert (format "cd %s\n" (s-chomp DIROUT)))
 on ~/.bashrc
function cdd {
  lastdir=`grep "^cd /[a-zA-Z0-9]" $HOME/.bash_history | tail -1 | awk '{print $2}'`;
  if [ "$lastdir" != "" ] ; then
    cd "$lastdir";
  echo cd `pwd`;

Saturday, March 20, 2010

Tottori farmers market

Their vegetables are cheap, sweet and bitter at the same time.  Root vegetables, especially Wasabi, Renkon, and The long, are the best.  A woman butcher is blonds-colored Japanese girl.  She is the other hi-light in this market. 

Sunday, March 07, 2010

Biggest shock in 2009

Since my father in law bought a new car, I got his old one. The upgrade from Toyota Starlet 1.3 to Subaru Legacy 2.0 turbo was shocking. Stability at 100 km/h and acceleration above 3000 rpm is something that I have never experienced.

Even at Tottori airport with snow, the 4WD lets us out of the parking lot.

Sunday, July 01, 2007

Watermelon marathon 2007

This year, we made the Misasa Okayama-Univ running team. We ran 5 km which is same distance as last year.

My time was 23 minutes 20 second for 5 km this year (rank 145 out of ~500). I have completely forgot my time last year before checking this blog. It seems that I ran by 23 minutes 30 second last year.

During the race, I forced myself to run on even pace and I thought I ran much faster than the last year. Let me say 10 second is significant and at least I maintained my running capability.

Sunday, May 27, 2007

Japanese sea

Two months have passed since we (my wife and I) started to live together. There are many things that I want to do on weekend but I cannot do most of them.

What became clear is that I am happy if I see beach (sea?). It is such a nice day today. The height of the wave is relatively high. My grand parent's place is located in in-land sea and to see Japanese sea is still exciting to me.

Saturday, February 03, 2007

Snow 2007

It snowed significantly. Since I purchased studless tires this winter which cost $500 and this is the first time to appreciate for them, I was sort of happy.

But, due to the snow, a flight from Tokyo was canceled and my wife cannot come and visit to Misasa on this weekend. What a disappointing! This is after a month since I saw her last.

I think about conservation of lack. I should not have felt happy about snow.

One picture is taken from my apartment and other is Glanza.

Sunday, January 07, 2007

second thing in 2007

At the end of my stay in Tokyo (Jan 3rd), I got sick. Flight on 4th was terrible. After that, fever, belly, finally gut. The gut takes long to be cured.

My grand mother and parents visited me to enjoy hot sprint although really they took care of me. Too bad for them.

My preparation for the Japanese winter was not enough. I miss LA.

Tuesday, January 02, 2007

Saturday, December 16, 2006

DeLonghi heater

It is very cold. I am not sure if this is because I am in Misasa or because this is winter after 5 years. Winter in LA was too easy. Finally I decided to spend money to heater.

I purchased an oil heater by DeLonghi because not only shop clerk but also my mom recommended me. It cost more than $400. Besides DeLonghi the only heater I had just cost $20. The cheaper heater looks 20 times warmer.

Wow! This really works. Part of reason why this makes me so warm is that I want to believe. I planned to buy cheaper heater and iPod but I cannot get the latter.