Skip to content

Instantly share code, notes, and snippets.

@kobapan
kobapan / cut.scm
Last active October 11, 2017 08:32
cut の使い方
(map (cut * <> 2) `(1 2 3 4 5))
@kobapan
kobapan / def-add-hooks.el
Last active October 11, 2017 08:32
elisp 同じFUNCTIONを、複数モードのadd-hookに、一括で登録するマクロ
(defmacro def-add-hooks (lst body)
`(mapc #'(lambda (name)
(add-hook name #'(lambda () ,body)))
,lst))
; 使い方
; (def-add-hooks `(text-mode-hook markdown-mode-hook)
; (setq truncate-lines nil))
@kobapan
kobapan / ftp_class.php
Last active January 3, 2021 22:54
Modified Version of "PHP FTP Client Class By TOMO" - converted ereg* to preg*
<?php
/*********************************************************************
* Modified Version of "PHP FTP Client Class By TOMO"
*
* convert ereg* to preg*
*
* Author kobapan kobapan at gmail.com
********************************************************************/
/*********************************************************************
@kobapan
kobapan / scratch.el
Last active January 16, 2023 08:41
elisp *scratch* の永続化
(setq initial-scratch-message "") ; とりあえず initial message を消す
(add-hook 'kill-emacs-hook 'scratch-save) ; Emacs終了時に *scratch* を保存
(add-hook 'window-setup-hook 'scratch-resume); 起動時に.scratchを読み込み
;; window-setup-hook が最後に呼ばれるっぽい
;; @see info 38.1.1 Summary: Sequence of Actions at Startup
(add-hook 'kill-buffer-hook; *scratch* バッファで kill-buffer したら内容を保存
(lambda () (if (equal (buffer-name) "*scratch*") (scratch-save))))
(add-hook 'after-save-hook ; *scratch*をファイル保存したら、*scratch*復帰
(lambda () (unless (get-buffer "*scratch*") (scratch-resume))))
(defvar scratch-file "~/.emacs.d/.scratch")
@kobapan
kobapan / buffer-list-real.el
Created March 23, 2015 03:58
elisp buffer-listからファイルとディレクトリの一覧をフルパスで取得
(delq nil (mapcar
(lambda (x)
(set-buffer x)
(unless (string= (file-name-nondirectory "README") (buffer-name)) ;exclude README
(or (buffer-file-name) list-buffers-directory)))
(buffer-list)))
@kobapan
kobapan / kill-other-buffers.el
Last active October 11, 2017 08:30
elisp カレントバッファ以外の全てのバッファを閉じる
(defun kill-other-buffers ()
"Kill all other buffers."
(interactive)
(let ((exclude '("*scratch*" "*Messages*")))
(mapc (lambda (b)
(let ((buf (buffer-name b)))
(unless (member buf exclude)
(kill-buffer buf))))
(delq (current-buffer) (buffer-list)))))
@kobapan
kobapan / highlight.el
Created March 23, 2015 09:28
elisp 現在行をハイライト
; in the current buffer,
(hl-line-mode) ; enable or disable highlight cursor line
(hl-line-mode t) ; enable highlight cursor line
(hl-line-mode nil) ; disable highlight cursor line
; globally,
(global-hl-line-mode) ; enables or disables highlight cursor line
(global-hl-line-mode t) ; enable highlight cursor line
(global-hl-line-mode nil) ; disable highlight cursor line
@kobapan
kobapan / mapcar*.el
Created March 25, 2015 08:53
elisp mapcar*の使い方
(mapcar* 'cons '(a b c) '(1 2 3 4))
;=>((a . 1) (b . 2) (c . 3))
(mapcar* 'cons '(a b c) '(1 2 3 4) '(5 6 7))
;=>error
(mapcar* (lambda (a b c)
(+ a b c))
'(1 2 3)
@kobapan
kobapan / between.el
Created March 25, 2015 10:51
elisp betweenマクロ
(defmacro between (var start end &optional $=)
`(cond ((null ,var) nil)
((numberp ,var)
(let (($$ (if ,$= '<= '<)))
(and (funcall $$ ,start ,var) (funcall $$ ,var ,end))))
((stringp ,var)
(if ,$=
(or (and (string< ,start ,var) (string< ,var ,end)) (string= ,start ,var) (string= ,var ,end))
(and (string< ,start ,var) (string< ,var ,end))))
(t (error "comparing neither numberp nor stringp"))))
@kobapan
kobapan / frame-size-resume.el
Last active October 11, 2017 08:30
終了時のフレームサイズで起動する
(add-hook 'kill-emacs-hook 'frame-size-save); Emacs終了時
(add-hook 'window-setup-hook 'frame-size-resume); Emacs起動時
(defun frame-size-save ()
(set-buffer
(find-file-noselect (expand-file-name "~/.emacs.d/.framesize")))
(erase-buffer)
(insert (concat
"(set-frame-width (selected-frame) "
(int-to-string (frame-width))
") (set-frame-height (selected-frame) "