First step of git

六月 9, 2008

git config –global user.name 『your name』
git config –global user.email 『your@email.address』

Emacs’ tips: transpose

五月 20, 2008

M-t 交換游標前後的兩個字
C-t 交換游標前後的兩個字元
C-x C-t 交換上下兩行

在 Emacs 中交換 buffer window

四月 17, 2008

Steve Yegge 在他舊的 blog 中有一篇提供了一個 elisp function 可以交換 buffer window,但是他所提供的只能在兩個 buffer window 的狀態下交換,因此我做了一點修改,讓他可以在多個 buffer window 下也能運行。


(defun swap-windows ()
  "If you have more than 2 windows, it swaps them."
  (interactive)
  (cond ((< (count-windows) 2)
         (message "You need more than 2 windows to do this."))
        (t
         (let* ((wlst-from (window-list))
                (wlst-to (window-list))
                (welm (pop wlst-to)))
           (append wlst-to welm)
           (while (and wlst-from wlst-to)
             (let* ((w1 (pop wlst-from))
                    (w2 (pop wlst-to))
                    (b1 (window-buffer w1))
                    (b2 (window-buffer w2))
                    (s1 (window-start w1))
                    (s2 (window-start w2)))
               (set-window-buffer w1 b2)
               (set-window-buffer w2 b1)
               (set-window-start w1 s2)
               (set-window-start w2 s1)))))))

我的第一次

四月 20, 2007

我用了 Haskell 小小的實做了 Unix 的 cat 指令
算是第一個有點用處的 Haskell 程式
代碼如下


{-
  Haskell implementation of cat(1)
  Copyright (c) Allen Lin, 2006.
-}

module Cat (catFile) where

import IO
import Text.Printf

data CatOpts = NeedReverse 
             | NeedLine 
             | NeedTab 
             | NeedEOL deriving Eq

catFile :: FilePath -> [CatOpts] -> IO ()
catFile fp opts = do
  h <- openFile fp ReadMode
  catContent h opts 1
  hClose h

catContent :: Handle -> [CatOpts] -> Int -> IO ()
catContent h opts line = do 
  eof <- hIsEOF h
  if eof then do 
        putNewLine
        return ()
   else do
       content <- hGetLine h
       putLineNumber line (NeedLine `elem` opts)
       let content' = content ++ "\n" in mapM_ (\x -> catContent2 x opts) content'
       catContent h opts line'
       where line' = incDecNum True line

catContent2 :: Char -> [CatOpts] -> IO ()
catContent2 c opts =
  if is_needeol && c == '\n' 
  then do putStrLn "$"
  else
      if is_needtab && c == '\t' 
      then do putStr "^I"
      else do putChar c
      where is_needtab = NeedTab `elem` opts
            is_needeol = NeedEOL `elem` opts

putNewLine :: IO ()
putNewLine = putStrLn ""

putLineNumber :: Int -> Bool -> IO ()
putLineNumber n b =
  case b of
    True  -> do putStr $ printf "%5d     " n
    _     -> do return ()

incDecNum :: Bool -> Int -> Int
incDecNum b n = 
    case b of 
      True      -> n + 1
      otherwise -> n - 1


Follow

Get every new post delivered to your Inbox.