読者です 読者をやめる 読者になる 読者になる

個人的自由ノート

ふと自分が気になった事を書いてます

Emacsを無難にカスタマイズ

tabbar-ruler.elをやってましたけど、faceのカスタマイズが出来ないということで(テーマが用意されているが改善せず。mode-lineの色を変えているので、copy-faceで適用されてしまう。M-x customize-faceでカスタマイズして設定ファイルに書き込んでも駄目。)、tabbar.elを単独で使うことにしました。何か惜しいですね。もう一つのところで…。カスタマイズ結果はこんな感じです。neotree.elも使ってます。ついでにAquamacsも載せておきますね。

f:id:kh2n:20170427002646p:plain

f:id:kh2n:20170427003026p:plain

tabbar rulerを使う GNU Emacs on macOS

こんな感じです。package.elでインストールすると使えます。

;; Added by Package.el.  This must come before configurations of
;; installed packages.  Don't delete this line.  If you don't want it,
;; just comment it out by adding a semicolon to the start of the line.
;; You may delete these explanatory comments.

;; Added by Package.el.  This must come before configurations of
;; installed packages.  Don't delete this line.  If you don't want it,
;; just comment it out by adding a semicolon to the start of the line.
;; You may delete these explanatory comments.

(require 'package)
(add-to-list 'package-archives '("melpa" . "http://melpa.milkbox.net/packages/"))
(add-to-list 'package-archives '("marmalade" . "http://marmalade-repo.org/packages/"))
(add-to-list 'package-archives '("org" . "http://orgmode.org/elpa/"))
(add-to-list 'package-archives '("gnu" . "http://elpa.gnu.org/packages/"))
(package-initialize)

(require 'color-theme)
(color-theme-initialize)
(color-theme-midnight)

(progn
  (set-face-foreground 'mode-line "white")
  (set-face-background 'mode-line "blue")
  (set-face-background 'region "white")
)

(require 'tabbar)
(tabbar-mode)
(tabbar-mwheel-mode nil)

(setq tabbar-ruler-global-tabbar t)    ; get tabbar
(setq tabbar-ruler-global-ruler t)     ; get global ruler
(setq tabbar-ruler-popup-menu t)       ; get popup menu.
(setq tabbar-ruler-popup-toolbar t)    ; get popup toolbar
(setq tabbar-ruler-popup-scrollbar t)  ; show scroll-bar on mouse-move
(require 'tabbar-ruler)

;; (set-face-attribute 'default nil :family "Menlo" :height 120)

;; (custom-set-faces
;;  '(default ((t (:inherit autoface-default :height 120 :family "Menlo"))) t))

(setq x-select-enable-clipboard nil)
(setq save-interprogram-paste-before-kill nil)
(setq yank-pop-change-selection nil)
(setq x-select-enable-clipboard-manager nil)
(setq x-select-enable-primary t)
(setq mouse-drag-copy-region t)

(defun copy-from-osx ()
 (shell-command-to-string "pbpaste"))

(defun paste-to-osx (text &optional push)
 (let ((process-connection-type nil))
     (let ((proc (start-process "pbcopy" "*Messages*" "pbcopy")))
       (process-send-string proc text)
       (process-send-eof proc))))

(setq interprogram-cut-function 'paste-to-osx)
(setq interprogram-paste-function 'copy-from-osx)

(define-key global-map (kbd "C-x C-c") 'clipboard-kill-ring-save)
(define-key global-map (kbd "C-x C-x") 'clipboard-kill-region)
(define-key global-map (kbd "C-x C-k") 'kill-line)
(define-key global-map (kbd "C-x C-s") 'save-buffer)
(define-key global-map (kbd "C-x C-a") 'mark-whole-buffer)
(define-key global-map (kbd "C-x C-v") 'clipboard-yank)
(define-key global-map (kbd "C-x C-z") 'undo)
(define-key global-map (kbd "C-s") 'isearch-forward)

(tool-bar-mode 0)

(global-set-key [f1] 'neotree-toggle)
(setq neo-show-hidden-files t)
(setq neo-create-file-auto-open t)
(setq neo-persist-show t)
(setq neo-keymap-style 'concise)
(setq neo-smart-open t)
(setq neo-vc-integration '(face char))
(when neo-persist-show
  (add-hook 'popwin:before-popup-hook
            (lambda () (setq neo-persist-show nil)))
  (add-hook 'popwin:after-popup-hook
            (lambda () (setq neo-persist-show t))))

(prefer-coding-system 'utf-8)

(setq make-backup-files nil)

(setq delete-auto-save-files t)

(setq-default tab-width 4 indent-tabs-mode nil)

(setq eol-mnemonic-dos "(CRLF)")
(setq eol-mnemonic-mac "(CR)")
(setq eol-mnemonic-unix "(LF)")

(add-to-list 'default-frame-alist '(alpha . (0.85 0.85)))

(column-number-mode t)

(global-linum-mode t)

(blink-cursor-mode 0)

(global-hl-line-mode t)

(show-paren-mode 1)
(setq show-paren-style 'expression)

(global-whitespace-mode 1)
(setq whitespace-space-regexp "\x3000+")
(set-face-foreground 'whitespace-newline "gray40")

(require 'cl)
(dolist (d '((space-mark ?\ ) (newline-mark ?\n)))
  (setq whitespace-display-mappings
        (delete-if
         '(lambda (e) (and (eq (car d) (car e))
                           (eq (cadr d) (cadr e))))
         whitespace-display-mappings)))

(dolist (e '((space-mark   ?\x3000 [?\□])
             (newline-mark ?\n     [?\u21B5 ?\n] [?$ ?\n])))
  (add-to-list 'whitespace-display-mappings e))

(dolist (d '(face lines space-before-tab
                  indentation empty space-after-tab tab-mark))
  (setq whitespace-style (delq d whitespace-style)))

(setq scroll-conservatively 1)

(setq kill-whole-line t)

(require 'dired-x)

(defun my-bell-function ()
  (unless (memq this-command
        '(isearch-abort abort-recursive-edit exit-minibuffer
              keyboard-quit mwheel-scroll down up next-line previous-line
              backward-char forward-char))
    (ding)))
(setq ring-bell-function 'my-bell-function)

(custom-set-variables
 ;; custom-set-variables was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(package-selected-packages (quote (tabbar-ruler tabbar tuareg neotree color-theme))))
(custom-set-faces
 ;; custom-set-faces was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 )

(add-to-list 'auto-mode-alist '("\\.ml[iylp]?" . tuareg-mode))
(autoload 'tuareg-mode "tuareg" "Major mode for editing OCaml code" t)
(autoload 'tuareg-run-ocaml "tuareg" "Run an inferior OCaml process." t)
(autoload 'ocamldebug "ocamldebug" "Run the OCaml debugger" t)

要約するとこの部分ですね。

(require 'tabbar)
(tabbar-mode)
(tabbar-mwheel-mode nil)

(setq tabbar-ruler-global-tabbar t)    ; get tabbar
(setq tabbar-ruler-global-ruler t)     ; get global ruler
(setq tabbar-ruler-popup-menu t)       ; get popup menu.
(setq tabbar-ruler-popup-toolbar t)    ; get popup toolbar
(setq tabbar-ruler-popup-scrollbar t)  ; show scroll-bar on mouse-move
(require 'tabbar-ruler)

実行結果

f:id:kh2n:20170426193056p:plain

現在のmacOSのGNU Emacsの設定

今のところこんな感じです。

;; Added by Package.el.  This must come before configurations of
;; installed packages.  Don't delete this line.  If you don't want it,
;; just comment it out by adding a semicolon to the start of the line.
;; You may delete these explanatory comments.

;; Added by Package.el.  This must come before configurations of
;; installed packages.  Don't delete this line.  If you don't want it,
;; just comment it out by adding a semicolon to the start of the line.
;; You may delete these explanatory comments.

(require 'package)
(add-to-list 'package-archives '("melpa" . "http://melpa.milkbox.net/packages/"))
(add-to-list 'package-archives '("marmalade" . "http://marmalade-repo.org/packages/"))
(add-to-list 'package-archives '("org" . "http://orgmode.org/elpa/"))
(add-to-list 'package-archives '("gnu" . "http://elpa.gnu.org/packages/"))
(package-initialize)

(require 'color-theme)
(color-theme-initialize)
(color-theme-midnight)

(progn
  (set-face-foreground 'mode-line "white")
  (set-face-background 'mode-line "blue")
  (set-face-background 'region "white")
)

(require 'tabbar)
(tabbar-mode)
(tabbar-mwheel-mode nil)

(set-face-attribute
 'tabbar-default nil
 :background "#90ee90"
 :foreground "#696969"
 )
(set-face-attribute
 'tabbar-selected nil
 :background "#7cfc00"
 :foreground "brightwhite"
 :box nil
 )
(set-face-attribute
 'tabbar-modified nil
 :background "#90ee90"
 :foreground "brightwhite"
 :box nil
 )

;; (set-face-attribute 'default nil :family "Menlo" :height 120)

;; (custom-set-faces
;;  '(default ((t (:inherit autoface-default :height 120 :family "Menlo"))) t))

(setq x-select-enable-clipboard nil)
(setq save-interprogram-paste-before-kill nil)
(setq yank-pop-change-selection nil)
(setq x-select-enable-clipboard-manager nil)
(setq x-select-enable-primary t)
(setq mouse-drag-copy-region t)

(defun copy-from-osx ()
 (shell-command-to-string "pbpaste"))

(defun paste-to-osx (text &optional push)
 (let ((process-connection-type nil))
     (let ((proc (start-process "pbcopy" "*Messages*" "pbcopy")))
       (process-send-string proc text)
       (process-send-eof proc))))

(setq interprogram-cut-function 'paste-to-osx)
(setq interprogram-paste-function 'copy-from-osx)

(define-key global-map (kbd "C-x C-c") 'clipboard-kill-ring-save)
(define-key global-map (kbd "C-x C-x") 'clipboard-kill-region)
(define-key global-map (kbd "C-x C-k") 'kill-line)
(define-key global-map (kbd "C-x C-s") 'save-buffer)
(define-key global-map (kbd "C-x C-a") 'mark-whole-buffer)
(define-key global-map (kbd "C-x C-v") 'clipboard-yank)
(define-key global-map (kbd "C-x C-z") 'undo)
(define-key global-map (kbd "C-s") 'isearch-forward)

(tool-bar-mode 0)

(global-set-key [f1] 'neotree-toggle)
(setq neo-show-hidden-files t)
(setq neo-create-file-auto-open t)
(setq neo-persist-show t)
(setq neo-keymap-style 'concise)
(setq neo-smart-open t)
(setq neo-vc-integration '(face char))
(when neo-persist-show
  (add-hook 'popwin:before-popup-hook
            (lambda () (setq neo-persist-show nil)))
  (add-hook 'popwin:after-popup-hook
            (lambda () (setq neo-persist-show t))))

(prefer-coding-system 'utf-8)

(setq make-backup-files nil)

(setq delete-auto-save-files t)

(setq-default tab-width 4 indent-tabs-mode nil)

(setq eol-mnemonic-dos "(CRLF)")
(setq eol-mnemonic-mac "(CR)")
(setq eol-mnemonic-unix "(LF)")

(add-to-list 'default-frame-alist '(alpha . (0.85 0.85)))

(column-number-mode t)

(global-linum-mode t)

(blink-cursor-mode 0)

(global-hl-line-mode t)

(show-paren-mode 1)
(setq show-paren-style 'expression)

(global-whitespace-mode 1)
(setq whitespace-space-regexp "\x3000+")
(set-face-foreground 'whitespace-newline "gray40")

(require 'cl)
(dolist (d '((space-mark ?\ ) (newline-mark ?\n)))
  (setq whitespace-display-mappings
        (delete-if
         '(lambda (e) (and (eq (car d) (car e))
                           (eq (cadr d) (cadr e))))
         whitespace-display-mappings)))

(dolist (e '((space-mark   ?\x3000 [?\□])
             (newline-mark ?\n     [?\u21B5 ?\n] [?$ ?\n])))
  (add-to-list 'whitespace-display-mappings e))

(dolist (d '(face lines space-before-tab
                  indentation empty space-after-tab tab-mark))
  (setq whitespace-style (delq d whitespace-style)))

(setq scroll-conservatively 1)

(setq kill-whole-line t)

(require 'dired-x)

(defun my-bell-function ()
  (unless (memq this-command
        '(isearch-abort abort-recursive-edit exit-minibuffer
              keyboard-quit mwheel-scroll down up next-line previous-line
              backward-char forward-char))
    (ding)))
(setq ring-bell-function 'my-bell-function)

(custom-set-variables
 ;; custom-set-variables was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(package-selected-packages (quote (tabbar-ruler tabbar tuareg neotree color-theme))))
(custom-set-faces
 ;; custom-set-faces was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 )

(add-to-list 'auto-mode-alist '("\\.ml[iylp]?" . tuareg-mode))
(autoload 'tuareg-mode "tuareg" "Major mode for editing OCaml code" t)
(autoload 'tuareg-run-ocaml "tuareg" "Run an inferior OCaml process." t)
(autoload 'ocamldebug "ocamldebug" "Run the OCaml debugger" t)

tabbar rulerの設定忘れてるな…。使うと重たくなるという話で保留してました。

macOSのAquamacsの設定

最近人気あるんですかね。Emacsの派生アプリなんですけど、使ってみたところ、便利ですけどフォントが少し…といった感じでした。これをカスタマイズすれば使えるのではと思ってやってみましたが、GNU Emacsと若干設定が違う感じがしました。試行錯誤して、こんな感じにしてみました。GNU Emacsの設定ファイルをベースに設定したので、コメントアウトした後が残ってますけど…。Emacsコメントアウトする機能、便利ですね。

;; Added by Package.el.  This must come before configurations of
;; installed packages.  Don't delete this line.  If you don't want it,
;; just comment it out by adding a semicolon to the start of the line.
;; You may delete these explanatory comments.

;; Added by Package.el.  This must come before configurations of
;; installed packages.  Don't delete this line.  If you don't want it,
;; just comment it out by adding a semicolon to the start of the line.
;; You may delete these explanatory comments.

(require 'package)
(add-to-list 'package-archives '("melpa" . "http://melpa.milkbox.net/packages/"))
(add-to-list 'package-archives '("marmalade" . "http://marmalade-repo.org/packages/"))
(add-to-list 'package-archives '("org" . "http://orgmode.org/elpa/"))
(add-to-list 'package-archives '("gnu" . "http://elpa.gnu.org/packages/"))
(package-initialize)

(require 'color-theme)
(color-theme-initialize)
(color-theme-midnight)

(progn
  (set-face-foreground 'mode-line "white")
  (set-face-background 'mode-line "blue")
  (set-face-background 'region "white")
)

;; (require 'tabbar)
;; (tabbar-mode)
;; (tabbar-mwheel-mode nil)

;; (set-face-attribute
;;  'tabbar-default nil
;;  :background "#90ee90"
;;  :foreground "#696969"
;;  )
;; (set-face-attribute
;;  'tabbar-selected nil
;;  :background "#7cfc00"
;;  :foreground "brightwhite"
;;  :box nil
;;  )
;; (set-face-attribute
;;  'tabbar-modified nil
;;  :background "#90ee90"
;;  :foreground "brightwhite"
;;  :box nil
;;  )

;; (set-face-attribute 'default nil :family "Menlo" :height 120)

(custom-set-faces
 '(default ((t (:inherit autoface-default :height 120 :family "Menlo"))) t))

(setq x-select-enable-clipboard nil)
(setq save-interprogram-paste-before-kill nil)
(setq yank-pop-change-selection nil)
(setq x-select-enable-clipboard-manager nil)
(setq x-select-enable-primary t)
(setq mouse-drag-copy-region t)

(defun copy-from-osx ()
 (shell-command-to-string "pbpaste"))

(defun paste-to-osx (text &optional push)
 (let ((process-connection-type nil))
     (let ((proc (start-process "pbcopy" "*Messages*" "pbcopy")))
       (process-send-string proc text)
       (process-send-eof proc))))

(setq interprogram-cut-function 'paste-to-osx)
(setq interprogram-paste-function 'copy-from-osx)

(define-key global-map (kbd "C-x C-c") 'clipboard-kill-ring-save)
(define-key global-map (kbd "C-x C-x") 'clipboard-kill-region)
(define-key global-map (kbd "C-x C-k") 'kill-line)
(define-key global-map (kbd "C-x C-s") 'save-buffer)
(define-key global-map (kbd "C-x C-a") 'mark-whole-buffer)
(define-key global-map (kbd "C-x C-v") 'clipboard-yank)
(define-key global-map (kbd "C-x C-z") 'undo)
(define-key global-map (kbd "C-s") 'isearch-forward)

(tool-bar-mode 0)

(global-set-key [f1] 'neotree-toggle)
(setq neo-show-hidden-files t)
(setq neo-create-file-auto-open t)
(setq neo-persist-show t)
(setq neo-keymap-style 'concise)
(setq neo-smart-open t)
(setq neo-vc-integration '(face char))
(when neo-persist-show
  (add-hook 'popwin:before-popup-hook
            (lambda () (setq neo-persist-show nil)))
  (add-hook 'popwin:after-popup-hook
            (lambda () (setq neo-persist-show t))))

(prefer-coding-system 'utf-8)

(setq make-backup-files nil)

(setq delete-auto-save-files t)

(setq-default tab-width 4 indent-tabs-mode nil)

(setq eol-mnemonic-dos "(CRLF)")
(setq eol-mnemonic-mac "(CR)")
(setq eol-mnemonic-unix "(LF)")

(add-to-list 'default-frame-alist '(alpha . (0.85 0.85)))

(column-number-mode t)

(global-linum-mode t)

(blink-cursor-mode 0)

(global-hl-line-mode t)

(show-paren-mode 1)
(setq show-paren-style 'expression)

(global-whitespace-mode 1)
(setq whitespace-space-regexp "\x3000+")
(set-face-foreground 'whitespace-newline "gray40")

(require 'cl)
(dolist (d '((space-mark ?\ ) (newline-mark ?\n)))
  (setq whitespace-display-mappings
        (delete-if
         '(lambda (e) (and (eq (car d) (car e))
                           (eq (cadr d) (cadr e))))
         whitespace-display-mappings)))

(dolist (e '((space-mark   ?\x3000 [?\□])
             (newline-mark ?\n     [?\u21B5 ?\n] [?$ ?\n])))
  (add-to-list 'whitespace-display-mappings e))

(dolist (d '(face lines space-before-tab
                  indentation empty space-after-tab tab-mark))
  (setq whitespace-style (delq d whitespace-style)))

(setq scroll-conservatively 1)

(setq kill-whole-line t)

(require 'dired-x)

(defun my-bell-function ()
  (unless (memq this-command
        '(isearch-abort abort-recursive-edit exit-minibuffer
              keyboard-quit mwheel-scroll down up next-line previous-line
              backward-char forward-char))
    (ding)))
(setq ring-bell-function 'my-bell-function)

(custom-set-variables
 ;; custom-set-variables was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(package-selected-packages (quote (tabbar-ruler tabbar tuareg neotree color-theme))))
(custom-set-faces
 ;; custom-set-faces was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 )

(add-to-list 'auto-mode-alist '("\\.ml[iylp]?" . tuareg-mode))
(autoload 'tuareg-mode "tuareg" "Major mode for editing OCaml code" t)
(autoload 'tuareg-run-ocaml "tuareg" "Run an inferior OCaml process." t)
(autoload 'ocamldebug "ocamldebug" "Run the OCaml debugger" t)

Zodiac アレンジ 黒い瞳のノア


【黒い瞳のノア】 Zodiac 【アレンジ】

OCamlで問題を解く(訂正分)

一つ前の記事に載せたプログラム、間違ってましたので直しました。

print_string "2以上の整数値 : ";;
let n = read_int()
let cnt = ref 0;;

let answer () = if !cnt = 1 then
                  print_string "それは素数です。\n"
                else
                  print_string "それは素数ではありません。\n";;

let rec prime i = if i = n + 1 then
                    ()
                  else if n mod i = 0 then
                    (
                      cnt := !cnt + 1;
                      prime (i + 1)
                    )
                  else
                    prime (i + 1);;

prime 2;;
answer ();;

OCamlで問題を解く

forループ、使いづらいなぁと思ってましたけど、慣れたら使えるようになってきました。添字が0からだと使いづらいですが、1からにすれば無問題ですね。forループでリストを参照するときとかは少し工夫しないといけないかもしれませんけど。foreachのような命令文があれば楽に走査できそうですけど、部分的には参照出来ないし・・・。これに関してはイテレータがあったかな。まだあまりリストは使ったことないのでわかりません。

print_string "ピラミッドを表示します。\n";;
print_string "段数は : ";;
let n = read_int();;
for i = 1 to n do
  for j = 1 to n - i do
    print_string " ";
  done;
  for k = 1 to (i - 1) * 2 + 1 do
    print_string "*";
  done;
  print_newline ();
done;;




print_string "数字ピラミッドを表示します。\n";;
print_string "段数は : ";;
let n = read_int();;
for i = 1 to n do
  for j = 1 to n - i do
    print_string " ";
  done;
  for k = 1 to (i - 1) * 2 + 1 do
    print_int (i mod 10);
  done;
  print_newline ();
done;;




print_string "2以上の整数値 : ";;
let n = read_int()
let cnt = ref 0;;

let answer () = if !cnt = 1 then
                  print_string "それは素数です。\n"
                else
                  print_string "それは素数ではありません。\n";;

let rec prime i = if n mod i = 0 then
                    (
                      cnt := !cnt + 1;
                      prime (i + 1)
                    )
                  else if i = n + 1 then
                    ()
                  else
                    prime (i + 1);;

prime 2;;
answer ();;