From a631951c4d21c43ab906a3cad226f0eff47bf21a Mon Sep 17 00:00:00 2001 From: 10sr <8slashes+git@gmail.com> Date: Tue, 3 Mar 2015 12:48:12 +0900 Subject: [PATCH 01/12] Add run-emacs target --- Makefile | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index d60b813..d347730 100644 --- a/Makefile +++ b/Makefile @@ -76,6 +76,9 @@ setups := setup-darwin setup-directories setup-emacs setup-gitconf \ setup-all: $(setups) +runs := run-emacs run-bash run-zsh + + # `make check` is just an alias for `make test` check: test @@ -343,6 +346,13 @@ setup-rc-tmux.conf: topfile := $(home)/.tmux.conf setup-rc-emacs.el: topfile := $(home)/.emacs.d/init.el +# run +# === + +run-emacs: $(dotfiles_dir)/emacs.el + $(emacs) -q --eval "(setq )" --load "$<" + + @@ -395,8 +405,3 @@ sexp_elisp_syntax_check := \ $(test_syntax_els): test-syntax-%: $(dotfiles_dir)/% $(emacs) -Q --debug-init --batch \ --eval '(let ((file "$<")) $(sexp_elisp_syntax_check))' --kill - - - -run-emacs: - $(emacs) -nw From aed6a353165f79e04c1433f088a1aa10adbe1053 Mon Sep 17 00:00:00 2001 From: 10sr <8slashes+git@gmail.com> Date: Tue, 3 Mar 2015 13:33:39 +0900 Subject: [PATCH 02/12] Add var files and simplify tasks to retrieve files --- Makefile | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/Makefile b/Makefile index d347730..6c76ed9 100644 --- a/Makefile +++ b/Makefile @@ -60,6 +60,8 @@ git ?= $(shell which git 2>/dev/null) curl ?= $(shell which curl 2>/dev/null) grep ?= GREP_OPTIONS= $(shell which grep 2>/dev/null) +files := Makefile emacs.el profile shrc tmux.conf vimrc _keysnail.js + # Targets all: default @@ -138,26 +140,24 @@ endif # preparing files # =============== -ifeq (,$(use_git)) -$(warning 'use_git' is set to empty. Use curl to fetch files) -$(dotfiles_dir)/%: +files_fullpath := $(files:%=$(dotfiles_dir)/%) +fetch_files := $(files:%=fetch-%) +.PHONY: $(fetch_files) + +$(fetch_files): mkdir -vp $(dotfiles_dir) curl --url $(dotfiles_url_base)/$* --output $@ + + +ifeq (,$(use_git)) +$(files_fullpath): $(dotfiles_dir)/%: fetch-% +$(warning 'use_git' is empty. Use curl to fetch files) else -$(warning 'use_git' is set to non-empty. Use git to retrieve files) -$(dotfiles_dir)/%: setup-repository +$(warning 'use_git' is not empty. Use git to retrieve files) +$(files_fullpath): setup-repository test -f "$@" endif -# Shortcut target for interactive usage -# For example, `make file-emacs.el use_git=` will fetch emacs.el from web with -# curl program. -# NOTE: Is there any way to make all `file-%` targets phony? -file-%: $(dotfiles_dir)/% - test -f "$<" - -# Make sure $(dotfiles_dir)/% wont be removed as intermidiate files -.PRECIOUS: $(dotfiles_dir)/% From fd5b5bf95cd6214d5b3525b4e32e4bf3b908ca28 Mon Sep 17 00:00:00 2001 From: 10sr <8slashes+git@gmail.com> Date: Wed, 4 Mar 2015 15:08:03 +0900 Subject: [PATCH 03/12] Makefile: Use HOME env instead of private home variable for setting dotfiles_dir --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 6c76ed9..c34045b 100644 --- a/Makefile +++ b/Makefile @@ -32,7 +32,7 @@ ifeq (,$(dotfiles_dir)) ifeq (,$(DOTFILES_DIR)) $(warning Neigher DOTFILES_DIR nor dotfiles_dir is defined) $(warning Use default value) - dotfiles_dir := $(home)/10sr_dotfiles + dotfiles_dir := $(HOME)/10sr_dotfiles else # dotfiles_dir is empty but DOTFILES_DIR has a value $(warning dotfiles_dir is set from DOTFILES_DIR) From e7c295497557605574b360334ff254ff8652272c Mon Sep 17 00:00:00 2001 From: 10sr <8slashes+git@gmail.com> Date: Thu, 5 Mar 2015 23:57:28 +0900 Subject: [PATCH 04/12] Use private home by default --- Makefile | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index c34045b..3c0b5a6 100644 --- a/Makefile +++ b/Makefile @@ -3,8 +3,6 @@ # Variable definitions -home ?= $(HOME) - dotfiles_url_base := https://raw.githubusercontent.com/10sr/dotfiles/master use_git ?= t git_auth ?= t @@ -46,6 +44,18 @@ endif $(warning dotfiles_dir: $(dotfiles_dir)) +ifeq ($(home),) +ifeq ($(global_home),) +$(warning home not set and global_home is empty) +# TODO: What this should be? +home := $(dotfiles_dir)/.home +else +home := $(HOME) +endif +endif +$(warning home: $(home)) + + localdir := $(home)/.local vardir := $(home)/.var bindir := $(localdir)/bin From f4ddbdb742cf6310ca18efb38c284690598c7477 Mon Sep 17 00:00:00 2001 From: 10sr <8slashes+git@gmail.com> Date: Fri, 6 Mar 2015 00:00:07 +0900 Subject: [PATCH 05/12] Remove append_load vaiable --- Makefile | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 3c0b5a6..85d5939 100644 --- a/Makefile +++ b/Makefile @@ -333,8 +333,7 @@ endif # Load codes are defined by following SETUP_LOAD: indicator. # String DOTFILES_DIR in the load codes will be replaced into the value of # $(dotfiles_dir). -# If append_load is non-empty, the load codes are appended to $(topfile), -# otherwise the code will be just printed out to stdout. +# The load codes are appended to $(topfile). setup_rcs := setup-rc-vimrc setup-rc-tmux.conf setup-rc-emacs.el setup-rc: $(setup_rcs) @@ -344,12 +343,7 @@ command_extract_setup_load := $(grep) -e 'SETUP_LOAD: ' | \ sed -e 's/^.*SETUP_LOAD: //' -e 's|DOTFILES_DIR|$(dotfiles_dir)|' $(setup_rcs): setup-rc-%: $(dotfiles_dir)/% -ifeq (,$(append_load)) - @echo "\`append_load' is not defined. Just print load command." - cat "$<" | $(command_extract_setup_load) -else cat "$<" | $(command_extract_setup_load) | tee -a "$(topfile)" -endif setup-rc-vimrc: topfile := $(home)/.vimrc setup-rc-tmux.conf: topfile := $(home)/.tmux.conf From a4d02628a61d3721b39ca0fe8af33f4d2851fa5f Mon Sep 17 00:00:00 2001 From: 10sr <8slashes+git@gmail.com> Date: Fri, 6 Mar 2015 00:41:46 +0900 Subject: [PATCH 06/12] setup-rc basically works --- Makefile | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/Makefile b/Makefile index 85d5939..be8ef03 100644 --- a/Makefile +++ b/Makefile @@ -59,6 +59,8 @@ $(warning home: $(home)) localdir := $(home)/.local vardir := $(home)/.var bindir := $(localdir)/bin +directories := $(dotfiles_dir) $(home) $(localdir) $(vardir) $(bindir) \ + $(home)/.emacs.d current := $(shell date) uname := $(shell uname) @@ -105,6 +107,10 @@ check-syntax: test-syntax +$(directories): + test -d "$@" || mkdir -vp "$@" + + # System detection # ================ @@ -154,8 +160,7 @@ files_fullpath := $(files:%=$(dotfiles_dir)/%) fetch_files := $(files:%=fetch-%) .PHONY: $(fetch_files) -$(fetch_files): - mkdir -vp $(dotfiles_dir) +$(fetch_files): fetch-%: $(dotfiles_dir) curl --url $(dotfiles_url_base)/$* --output $@ @@ -212,17 +217,6 @@ ack-2.12: util_url := http://beyondgrep.com/ack-2.12-single-file -# create directories -# ------------------ - -setup_directories := $(localdir) $(vardir) $(bindir) -setup-directory: $(setup_directories) - -$(localdir) $(vardir) $(bindir): - mkdir -vp $@ - - - # darwin setup # ------------ @@ -342,13 +336,15 @@ setup-rc: $(setup_rcs) command_extract_setup_load := $(grep) -e 'SETUP_LOAD: ' | \ sed -e 's/^.*SETUP_LOAD: //' -e 's|DOTFILES_DIR|$(dotfiles_dir)|' -$(setup_rcs): setup-rc-%: $(dotfiles_dir)/% +$(setup_rcs): setup-rc-%: $(dotfiles_dir)/% $(home) cat "$<" | $(command_extract_setup_load) | tee -a "$(topfile)" setup-rc-vimrc: topfile := $(home)/.vimrc setup-rc-tmux.conf: topfile := $(home)/.tmux.conf setup-rc-emacs.el: topfile := $(home)/.emacs.d/init.el +setup-rc-emacs.el: $(home)/.emacs.d + # run # === From 8e63867bc1023929cbad50e2e813efbbfa351556 Mon Sep 17 00:00:00 2001 From: 10sr <8slashes+git@gmail.com> Date: Fri, 6 Mar 2015 01:02:39 +0900 Subject: [PATCH 07/12] make run-emacs basically seems to work --- Makefile | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index be8ef03..a7957fd 100644 --- a/Makefile +++ b/Makefile @@ -333,23 +333,26 @@ setup_rcs := setup-rc-vimrc setup-rc-tmux.conf setup-rc-emacs.el setup-rc: $(setup_rcs) .PHONY: $(setup_rcs) +setup-rc-vimrc: $(home)/.vimrc +setup-rc-tmux.conf: $(home)/.tmux.conf +setup-rc-emacs.el: $(home)/.emacs.d/init.el + +$(home)/.emacs.d/init.el: $(dotfiles_dir)/emacs.el $(home) $(home)/.emacs.d +$(home)/.vimrc: $(dotfiles_dir)/vimrc $(home) +$(home)/.tmux.conf: $(dotfiles_dir)/tmux.conf $(home) + command_extract_setup_load := $(grep) -e 'SETUP_LOAD: ' | \ sed -e 's/^.*SETUP_LOAD: //' -e 's|DOTFILES_DIR|$(dotfiles_dir)|' -$(setup_rcs): setup-rc-%: $(dotfiles_dir)/% $(home) - cat "$<" | $(command_extract_setup_load) | tee -a "$(topfile)" - -setup-rc-vimrc: topfile := $(home)/.vimrc -setup-rc-tmux.conf: topfile := $(home)/.tmux.conf -setup-rc-emacs.el: topfile := $(home)/.emacs.d/init.el +$(home)/.emacs.d/init.el $(home)/.vimrc $(home)/.tmux.conf: + cat "$<" | $(command_extract_setup_load) | tee -a "$@" -setup-rc-emacs.el: $(home)/.emacs.d # run # === -run-emacs: $(dotfiles_dir)/emacs.el +run-emacs: $(home)/.emacs.d/init.el $(emacs) -q --eval "(setq )" --load "$<" From 1e4aed3fd6c37b768775773db949797fc7b4f2dd Mon Sep 17 00:00:00 2001 From: 10sr <8slashes+git@gmail.com> Date: Fri, 6 Mar 2015 15:09:16 +0900 Subject: [PATCH 08/12] Fix fetching library error --- emacs.el | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/emacs.el b/emacs.el index e80b698..ea0bbbf 100644 --- a/emacs.el +++ b/emacs.el @@ -920,11 +920,11 @@ IF OK-IF-ALREADY-EXISTS is true force download." ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; window -(and (fetch-library - "https://raw.github.com/10sr/emacs-lisp/master/window-organizer.el" - t) - (autoload-eval-lazily 'window-organizer) - (define-key ctl-x-map (kbd "w") 'window-organizer)) +'(and (fetch-library + "https://raw.github.com/10sr/emacs-lisp/master/window-organizer.el" + t) + (autoload-eval-lazily 'window-organizer) + (define-key ctl-x-map (kbd "w") 'window-organizer)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; server @@ -1009,13 +1009,13 @@ IF OK-IF-ALREADY-EXISTS is true force download." (autoload-eval-lazily 'sql '(sql-mode) (safe-require-or-eval 'sql-indent)) -(and (fetch-library "https://raw.github.com/10sr/emacs-lisp/master/gtkbm.el" - t) - (autoload-eval-lazily 'gtkbm) - (global-set-key (kbd "C-x C-d") 'gtkbm)) +'(and (fetch-library "https://raw.github.com/10sr/emacs-lisp/master/gtkbm.el" + t) + (autoload-eval-lazily 'gtkbm) + (global-set-key (kbd "C-x C-d") 'gtkbm)) (and (fetch-library - "https://raw.github.com/10sr/emacs-lisp/master/git-command.el" + "https://raw.github.com/10sr/git-command-el/master/git-command.el" t) (autoload-eval-lazily 'git-command nil From b5d57e4a27c4f82be0923c8bbfa213f5216d0cb6 Mon Sep 17 00:00:00 2001 From: 10sr <8slashes+git@gmail.com> Date: Fri, 6 Mar 2015 15:21:26 +0900 Subject: [PATCH 09/12] Fix make run-emacs --- Makefile | 4 ++-- emacs.el | 37 +++++++++++++++++++++---------------- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/Makefile b/Makefile index a7957fd..84b306a 100644 --- a/Makefile +++ b/Makefile @@ -345,7 +345,7 @@ command_extract_setup_load := $(grep) -e 'SETUP_LOAD: ' | \ sed -e 's/^.*SETUP_LOAD: //' -e 's|DOTFILES_DIR|$(dotfiles_dir)|' $(home)/.emacs.d/init.el $(home)/.vimrc $(home)/.tmux.conf: - cat "$<" | $(command_extract_setup_load) | tee -a "$@" + test -f "$@" || cat "$<" | $(command_extract_setup_load) | tee -a "$@" @@ -353,7 +353,7 @@ $(home)/.emacs.d/init.el $(home)/.vimrc $(home)/.tmux.conf: # === run-emacs: $(home)/.emacs.d/init.el - $(emacs) -q --eval "(setq )" --load "$<" + $(emacs) -q --eval "(setq user-emacs-directory \"$(home)/.emacs.d/\")" --load "$<" diff --git a/emacs.el b/emacs.el index ea0bbbf..2a32b6d 100644 --- a/emacs.el +++ b/emacs.el @@ -30,6 +30,14 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Some macros for internals +(defun call-after-init (func) + "If `after-init-hook' has been run, call FUNC immediately. +Otherwize hook it." + (if after-init-time + (funcall func) + (add-hook 'after-init-hook + func))) + (defmacro defvar-set (symbol value &optional docstring) "Define SYMBOL as a variable and set to VALUE. @@ -276,12 +284,11 @@ IF OK-IF-ALREADY-EXISTS is true force download." (let ((kill-emacs-hook nil)) (kill-emacs))) -(add-hook 'after-init-hook - (lambda () - (message "%s %s" invocation-name emacs-version) - (message "%s was taken to initialize emacs." (emacs-init-time)) - (switch-to-buffer "*Messages*") - )) +(call-after-init + (lambda () + (message "%s %s" invocation-name emacs-version) + (message "%s was taken to initialize emacs." (emacs-init-time)) + (switch-to-buffer "*Messages*"))) (cd ".") ; when using windows use / instead of \ in `default-directory' @@ -302,9 +309,8 @@ IF OK-IF-ALREADY-EXISTS is true force download." ;; (comint-show-maximum-output) ;; kill scratch -(add-hook 'after-init-hook - (lambda () - (kill-buffer "*scratch*"))) +(call-after-init (lambda () + (kill-buffer "*scratch*"))) ;; modifier keys ;; (setq mac-option-modifier 'control) @@ -447,11 +453,10 @@ IF OK-IF-ALREADY-EXISTS is true force download." ;; http://www.geocities.jp/simizu_daisuke/bunkei-meadow.html#frame-title ;; display date -(add-hook 'after-init-hook - (lambda () - (when display-time-mode - (display-time-update)) - )) +(call-after-init (lambda () + (when display-time-mode + (display-time-update)) + )) (when (safe-require-or-eval 'time) (setq display-time-interval 29) @@ -824,7 +829,7 @@ IF OK-IF-ALREADY-EXISTS is true force download." ;; Load scim-bridge. (when (safe-require-or-eval 'scim-bridge) ;; Turn on scim-mode automatically after loading .emacs - (add-hook 'after-init-hook 'scim-mode-on) + (call-after-init 'scim-mode-on) (defvar-set scim-cursor-color "red") (scim-define-preedit-key ?\^h t) (scim-define-common-key ?\* nil) @@ -915,7 +920,7 @@ IF OK-IF-ALREADY-EXISTS is true force download." ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; https://github.com/lunaryorn/flycheck (when (safe-require-or-eval 'flycheck) - (add-hook 'after-init-hook 'global-flycheck-mode)) + (call-after-init 'global-flycheck-mode)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; window From dddfd9785d0627d26a15889e65309c40f4458737 Mon Sep 17 00:00:00 2001 From: 10sr <8slashes+git@gmail.com> Date: Sat, 7 Mar 2015 19:59:20 +0900 Subject: [PATCH 10/12] Delete scratch buf only if found --- emacs.el | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/emacs.el b/emacs.el index 2a32b6d..6cd8762 100644 --- a/emacs.el +++ b/emacs.el @@ -310,7 +310,9 @@ IF OK-IF-ALREADY-EXISTS is true force download." ;; kill scratch (call-after-init (lambda () - (kill-buffer "*scratch*"))) + (let ((buf (get-buffer "*scratch*"))) + (when buf + (kill-buffer buf))))) ;; modifier keys ;; (setq mac-option-modifier 'control) @@ -455,8 +457,7 @@ IF OK-IF-ALREADY-EXISTS is true force download." ;; display date (call-after-init (lambda () (when display-time-mode - (display-time-update)) - )) + (display-time-update)))) (when (safe-require-or-eval 'time) (setq display-time-interval 29) @@ -1327,7 +1328,7 @@ IF OK-IF-ALREADY-EXISTS is true force download." 'aggressive)) (defvar-set woman-cache-filename (expand-file-name (concat user-emacs-directory - "woman_cache.el"))) + "woman_cache.el"))) (defalias 'man 'woman) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -2007,8 +2008,8 @@ Optional prefix ARG says how many lines to unflag; default is one line." C-x t to toggling emacs-text-mode " - (shell-command-to-string "uname -a") - )) + (shell-command-to-string "uname -a") + )) (defvar eshell-text-mode-map (let ((map (make-sparse-keymap))) From 6f88e71f1ab321e8f64c7d1315bc077a237a4c43 Mon Sep 17 00:00:00 2001 From: 10sr <8slashes+git@gmail.com> Date: Fri, 13 Mar 2015 14:33:17 +0900 Subject: [PATCH 11/12] Adopt more robust duplicate check for setup-rc --- Makefile | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 84b306a..869d84c 100644 --- a/Makefile +++ b/Makefile @@ -344,8 +344,18 @@ $(home)/.tmux.conf: $(dotfiles_dir)/tmux.conf $(home) command_extract_setup_load := $(grep) -e 'SETUP_LOAD: ' | \ sed -e 's/^.*SETUP_LOAD: //' -e 's|DOTFILES_DIR|$(dotfiles_dir)|' +setup_rc_marker := ADDED BY 10sr_dotfiles/Makefile + $(home)/.emacs.d/init.el $(home)/.vimrc $(home)/.tmux.conf: - test -f "$@" || cat "$<" | $(command_extract_setup_load) | tee -a "$@" + set -x; if ! $(grep) "$(setup_rc_marker)" "$@"; \ + then \ + (echo '$(line_comment)' $(setup_rc_marker); cat "$<" | $(command_extract_setup_load)) \ + | tee -a "$@"; \ + fi + +$(home)/.emacs.d/init.el: line_comment := ;; +$(home)/.vimrc: line_comment := \" +$(home)/.tmux.conf: line_comment := \# From 62fdc9542efd4b2d6fa2a1e8bc6375a4e638a07f Mon Sep 17 00:00:00 2001 From: 10sr <8slashes+git@gmail.com> Date: Fri, 13 Mar 2015 14:36:59 +0900 Subject: [PATCH 12/12] Add setup-util dependency --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 869d84c..343328a 100644 --- a/Makefile +++ b/Makefile @@ -205,7 +205,7 @@ setup_utils_path := $(setup_utils:%=$(bindir)/%) $(setup_utils): %: $(bindir)/% -$(setup_utils_path): +$(setup_utils_path): $(bindir) $(curl) -L --url "$(util_url)" --output "$@" chmod +x "$@"