Skip to content

Instantly share code, notes, and snippets.

@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 / eval-print-region.el
Last active October 17, 2022 09:40
リージョン選択範囲、もしくは現在行のLisp 式を(1つ)読み込み、評価した結果を、次行に挿入する
(defun eval-print-region ()
(interactive)
(let ((f (lambda (s e)
(print (eval (read (replace-regexp-in-string "," "" (buffer-substring s e)))) (current-buffer)))))
(if (region-active-p)
;; リージョン全体
(funcall f (region-beginning) (region-end))
;; カーソルのある行全体
(progn (end-of-line)
(funcall f (point-at-bol) (point-at-eol))))))
@kobapan
kobapan / exif.sh
Last active September 29, 2022 00:17
Show or Update the exif ImageDescription and DateTimeOriginal in command line
#!/usr/bin/env bash
# exif.sh
# usage
usage_exit() {
if [[ $1 ]]; then echo "error $1"; fi
echo "---
Usage:
@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 / set-env-from-shell.el
Last active October 5, 2020 05:26
シェル の PATH と alias を、emacs に引き継ぐ
(defun set-env-from-shell ()
"シェル の PATH と alias を、emacs に引き継ぐ"
(let* ((trim (lambda (string &optional needle)
(let* ((n (if needle needle "[ \t\n\r]+"))
(s (if (string-match (concat "\\`" n) string)
(replace-match "" t t string)
string)))
(if (string-match (concat n "+\\'") s)
(replace-match "" t t s)
s))))
@kobapan
kobapan / uri-get.scm
Created April 6, 2020 02:33
get html body with uri (Gauche Scheme lisp)
(use rfc.http) ; http-get http-compose-query
(use rfc.uri) ; uri-parse uri-compose
(define (uri-get uri :key (query #f))
(if query (set! uri (string-append uri (if (car query) (http-compose-query "" query)
#"&~(http-compose-query #f (cdr query))"))))
(receive (code status body)
(receive (scheme user-info hostname port path query frament)
(uri-parse uri)
(http-get hostname (uri-compose :path path :query query)))
;;; Depentancy:
;;
;; e2ps
;; ps2pdf
;; sudo apt install e2ps; sudo apt install ghostscript ;
;;; Usage:
;;
;; M-x e2ps-ps2pdf
;; 保存ディレクトリを選ぶ
@kobapan
kobapan / date-mod-second.scm
Last active October 1, 2018 03:57
scheme で 日付を加減算。明日の日付とか、1週間後の日付とか。
;; @original [日付に対する加算 | 逆引きScheme](http://tips.cddddr.org/scheme/index.cgi?%e6%97%a5%e4%bb%98%e3%81%ab%e5%af%be%e3%81%99%e3%82%8b%e5%8a%a0%e7%ae%97)
(use srfi-19)
;; 日付 date の seconds 秒後の日付を返す。閏秒は考えない。
(define (date-mod-second date seconds)
(time-utc->date
(add-duration (date->time-utc date)
(make-time time-duration 0 seconds))))
@kobapan
kobapan / call-sxiv.el
Last active January 19, 2018 08:08
emacsのdiredでsxivを呼び出して、ディレクトリ内の全画像を表示する。
(defun call-sxiv ()
(interactive)
(let ((image-files;画像ファイル名のリスト
(delq nil;この辺はemacs26辺りで filterマクロに置き換えか?
(mapcar
(lambda (f)
(when (string-match
"\.\\(jpe?g\\|png\\|gif\\|bmp\\)$"
f )
f ))
@kobapan
kobapan / sudo.el
Last active January 10, 2018 08:11
一般ユーザでemacsを起動しているのに、root権限のフィルを編集したくなることが多かったらこれ
;;; sudo.el ---
;; Author: kobapan <kobapan@gmail.com>
;; Keywords: emacs,lisp
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.