Home | Index | Changes | Diaries

Emacs Lisp

とは?

Emacsのマクロ言語のことです。(ぇー

覚書き

.cannaを書き換えたら

(canna-reset)で初期化するべし。

HTML特殊記号の置き換え

Web日記として公開するために、タグをいちいち手で置き換えるのが面倒になってきた。

(defun cake-html-escape-region (begin end)

  "escape html special chars in region"

  (interactive "r")

  (save-restriction

    (narrow-to-region (region-beginning) (region-end))

    (goto-char (point-min))

    (emacs-wiki-escape-html-specials)))

カレンダーをちゃんと使う

下記を参照の上、

こんな感じで jp-holidays.el というファイルに保存。


(defvar general-holidays-JP

  '((holiday-fixed  1  1  "元旦")

    (holiday-float  1 1 2 "成人の日")

    (holiday-fixed  2 11  "建国記念の日")

    (holiday-fixed  4 29  "みどりの日")

    (holiday-fixed  5  3  "憲法記念日")

    (holiday-fixed  5  4  "国民の休日")

    (holiday-fixed  5  5  "こどもの日")

    (holiday-fixed  7 20  "海の日")

    (holiday-fixed  9 15  "敬老の日")

    (holiday-float 10 1 2 "体育の日")

    (holiday-fixed 11  3  "文化の日")

    (holiday-fixed 11 23  "勤労感謝の日")

    (holiday-fixed 12 23  "天皇誕生日")

    ;; 春分の日と秋分の日

    (if (memq displayed-month '(2 3 4 8 9 10))

        (solar-equinoxes-solstices))

    ;; 振替休日

    (when (not (boundp 'called-recursively))

      (let* (called-recursively

             (month displayed-month)

             (year displayed-year)

             (day (progn

                    (increment-calendar-month month year -2)

                    (list month (calendar-last-day-of-month month year) year)))

             (calendar-holidays general-holidays-JP) ;; ここ変数名と同じにする

             (holiday-list (calendar-holiday-list))

             holiday mmday ret)

        (if (check-calendar-holidays day)

            (setq holiday-list (cons (list day "dummy") holiday-list)))

        (while holiday-list

          (setq holiday (caar holiday-list))

          (and (= (calendar-day-of-week holiday) 0)

               (setq mmday (calendar-gregorian-from-absolute

                            (1+ (calendar-absolute-from-gregorian holiday))))

               (null (check-calendar-holidays mmday))

               (setq ret (cons (list mmday "振替休日") ret)))

          (setq holiday-list (cdr holiday-list)))

        ret))))



(defvar calendar-weekend '(0)

  "List of days of week to be marked as holiday.")

(defvar calendar-weekend-marker nil)



(defun calendar-mark-weekend ()

  (let ((m displayed-month)

	(y displayed-year))

    (increment-calendar-month m y -1)

    (calendar-for-loop

     i from 1 to 3 do

     (let ((sunday (- 1 (calendar-day-of-week (list m 1 y))))

	   (last (calendar-last-day-of-month m y)))

       (while (<= sunday last)

	 (mapcar (function

		  (lambda (x)

		    (let ((d (+ sunday x)))

		      (and (<= 1 d)

			   (<= d last)

			   (mark-visible-calendar-date

			    (list m d y)

			    calendar-weekend-marker)))))

		 calendar-weekend)

	 (setq sunday (+ sunday 7))))

     (increment-calendar-month m y 1))))



(add-hook 'calendar-load-hook

	  (function

	   (lambda ()

	     (setq calendar-weekend-marker calendar-holiday-marker

		   calendar-holidays (append general-holidays-JP

					     local-holidays

					     other-holidays)))))

(add-hook 'today-visible-calendar-hook 'calendar-mark-weekend)

(add-hook 'today-visible-calendar-hook 'mark-calendar-holidays)

(add-hook 'today-visible-calendar-hook 'calendar-mark-today)

~/.emacs から、 (load "jp-holidays.el") として読み込む。

rels

書籍

EmacsLispプログラミング入門

Robert J.Chassell 著/大木敦雄 訳/ASCII出版局 刊 ISBN4-5761-1805-4

これ見ながらいじってます。

はっきりいってGnuから配布されているInfoの和訳。でも寝転がって読めるのがいいところ。