2013年1月19日土曜日

[Emacs][Elisp]関数定義

defun を使って関数を定義する
(defun hello (a b)
  (setq ans (+ a b))
  (message "Ans: %d" ans))

hello
(hello 1 3)
"Ans: 4"
フォーマット
defun NAME ARGUMENT-LIST BODY-FORMS
Table: defun の引数
引数意味
NAME関数名
ARGUMENT-LIST引数リスト
BODY-FORMS関数の中身

HTTP Post する elisp を関数で定義すると下記のようになる
(defun http-post (server)
  (setq proc (open-network-stream "http-proc" "*http-buffer*" server 80))
  (set-process-coding-system proc 'binary 'binary)
  (process-send-string
    proc
    (format (concat
      "POST /test.php HTTP/1.0\r\n"
      "Content-Type: application/x-www-form-urlencoded\r\n"
      "Content-Length: 23\r\n"
      "\r\n"
      "fname=hello&lname=world"))))

http-post
(http-post "localhost")
nil

0 件のコメント:

コメントを投稿