Skip to content

Instantly share code, notes, and snippets.

View chuntaro's full-sized avatar

chuntaro

View GitHub Profile
@chuntaro
chuntaro / eshell-utils.el
Created November 23, 2016 08:13
バッファのカレントディレクトリで eshell を起動する
;; 色々やり方があるけど、これはcdのコマンド履歴を残すやり方
(defun eshell-cd-default-directory ()
"Eshell 'cd' with current buffer's default-directory."
(interactive)
(let ((dir default-directory))
(eshell)
(eshell-reset)
(insert (concat "cd " (shell-quote-wildcard-pattern dir)))
(eshell-send-input)))
;; #Emacs でコーディングしてて、コメント内に TODO とか色々書き残したりするけど
;; 後でまとめてそれらを抜き出したりしたい時に役立つelisp
;;
;; Emacs はコメントを認識してるから、それを使って言語非依存になってる!
(defun comment-traversal (beg end func)
(save-excursion
(let (spt ept)
(goto-char beg)
(while (and (< (point) end)
;; 一応、以下のようにすると固定ウィンドウに表示する事は出来るよ
;; これだと *info* バッファを開く場合に右に出るようになる
;; 完璧なサイドウィンドウって訳じゃないけど…お試しあれ
(add-to-list 'display-buffer-alist
'("\\`\\*info\\*\\'" .
(display-buffer-in-side-window
(side . right)
(window-width . 40))))
@chuntaro
chuntaro / calc-pi.el
Last active March 15, 2018 01:27
素の Emacs で Calc の多倍長整数を使って円周率を1000桁計算する方法
;; 出力結果は文字列だけど、3の後ろに小数点が無いのと最後の4桁は未収束の為除いたものが正しい値
(defmath mpiarccot (x)
(let ((base (expt 10 (+ 1000 4)))
(a x)
(b 1)
pos
(sum 0))
(while (> (setq pos (idiv base (* a b))) 1)
(setq sum (+ sum (if (/= (logand 2 b) 0) (- pos) pos))
@chuntaro
chuntaro / calc-pi.py
Created March 15, 2018 02:16
円周率をマチンの公式を使って10000桁計算
# 出力結果は3の後ろに小数点が無いのと最後の4桁は未収束の為除いたものが正しい値
import time
def mpiarccot(x):
base = 10 ** (10000 + 4)
a = x
b = 1
pos = base // (a * b)
s = 0
@chuntaro
chuntaro / calc-pi.lisp
Created March 15, 2018 02:23
円周率をマチンの公式を使って10000桁計算
;; 出力結果は3の後ろに小数点が無いのと最後の4桁は未収束の為除いたものが正しい値
(defpackage #:pi
(:use #:cl))
(in-package #:pi)
(declaim (optimize (speed 3) (debug 0) (safety 0)))
(defun mpiarccot (x)
(loop with base = (expt 10 (+ 10000 4))
@chuntaro
chuntaro / total-of-even-number-under-100.el
Created April 2, 2018 13:46
なぜfor文は禁止なのか?関数型記述のススメ (Emacs Lisp 遅延評価版)
;;; -*- lexical-binding: t; -*-
;; なぜfor文は禁止なのか?関数型記述のススメ
;; https://qiita.com/ukiuni@github/items/abad07524856c65a20ea
;;
;; Emacs Lisp 遅延評価版 (25.1 以上)
;; ※ Emacs にバグがある為 100 をあまり大きい値にすると Emacs ごと落ちます…
(require 'cl-lib)
(require 'stream) ;; (package-install 'stream)
@chuntaro
chuntaro / test-monte-carlo-pi.el
Created August 17, 2018 22:48
モンテカルロ法による円周率の計算 (ベンチマーク用)
;;; -*- lexical-binding: t; -*-
(defvar rand-next 1)
(defsubst myrand ()
"C 言語版や Common Lisp 版等と計算結果を合わせたい為に 32 bit の整形合同法を実装してます…"
(setq rand-next (logand (+ (logand (* rand-next 1103515245) #x7fffffff) 12345) #x7fffffff))
(logand (ash rand-next -16) #x7fff))
(defsubst float-rand ()
@chuntaro
chuntaro / popframe.el
Last active September 27, 2018 14:26
Emacs でフレームのポップアップ
;;; -*- lexical-binding: t; -*-
;; load-path に書かれたディレクトリにコピーした後 (require 'popframe) するか、
;; (load-file "/path/to/popframe.el") してください。
;;
;; (setq frame-resize-pixelwise t)
;; ↑この設定をしておくことを推奨します。
;; してない場合は、画像サイズぴったりにフレームがリサイズされません。
(require 'subr-x)
@chuntaro
chuntaro / image-tooltip.el
Created October 1, 2018 05:11
Emacs でポイントの下の画像ファイル名をツールチップに表示
;;; -*- lexical-binding: t; -*-
(defun image-tooltip-at-point ()
"ポイントやマウスカーソルの下の画像ファイルをツールチップ内に表示します。
使い方:
(define-key c-mode-map \"\\C-co\" 'image-tooltip-at-point)
(define-key c-mode-map [mouse-1] 'image-tooltip-at-point)
./very-sorry.png