From eeef4bcf52ebab3044852fc7cac1b761d73a8b2c Mon Sep 17 00:00:00 2001 From: Franck Cuny Date: Fri, 11 Nov 2016 19:31:18 -0800 Subject: [Emacs] renamed my custom files and load them with use-package. The new names are more logical. They are loaded with `use-package', and the bindings are also set that way. For general bindings, we store them in the 'bindings.el' library. --- emacs.d/init.el | 19 ++++++--- emacs.d/lib/bindings.el | 8 ++++ emacs.d/lib/config.el | 65 ++++++++++++++++++++++++++++ emacs.d/lib/funcs.el | 100 ++++++++++++++++++++++++++++++++++++++++++++ emacs.d/lib/my-functions.el | 99 ------------------------------------------- emacs.d/lib/my-settings.el | 63 ---------------------------- 6 files changed, 187 insertions(+), 167 deletions(-) create mode 100644 emacs.d/lib/bindings.el create mode 100644 emacs.d/lib/config.el create mode 100644 emacs.d/lib/funcs.el delete mode 100644 emacs.d/lib/my-functions.el delete mode 100644 emacs.d/lib/my-settings.el diff --git a/emacs.d/init.el b/emacs.d/init.el index 26cde75..67ceecf 100644 --- a/emacs.d/init.el +++ b/emacs.d/init.el @@ -9,20 +9,29 @@ (message "Refreshing ELPA package archives...") (package-refresh-contents)) +;; install the package 'use-package' unless it's already installed (unless (package-installed-p 'use-package) (progn - (package-refresh-contents) (package-install 'use-package))) +;; ... and load 'use-package' (require 'use-package) -(eval-and-compile - (add-to-list 'load-path (expand-file-name "lib" user-emacs-directory))) +(use-package config + :load-path (lambda () (expand-file-name "lib" user-emacs-directory))) -(use-package my-settings) -(use-package my-functions) +(use-package funcs + :load-path (lambda () (expand-file-name "lib" user-emacs-directory)) + :commands (fc/load-time) + :bind (("s-=" . fc/scale-up-font) + ("s--" . fc/scale-down-font) + ("s-0" . fc/reset-font-size))) + +(use-package bindings + :load-path (lambda () (expand-file-name "lib" user-emacs-directory))) (use-package server + ;; start emacs server if not already running :config (unless (server-running-p) (server-start))) diff --git a/emacs.d/lib/bindings.el b/emacs.d/lib/bindings.el new file mode 100644 index 0000000..2320fb5 --- /dev/null +++ b/emacs.d/lib/bindings.el @@ -0,0 +1,8 @@ +;; some bindings +(global-set-key (kbd "M-j") 'join-line) +(global-set-key (kbd "") 'toggle-frame-fullscreen) + +(define-key emacs-lisp-mode-map (kbd "C-c C-e") 'eval-buffer) +(define-key emacs-lisp-mode-map (kbd "C-c C-r") 'eval-region) + +(provide 'bindings) diff --git a/emacs.d/lib/config.el b/emacs.d/lib/config.el new file mode 100644 index 0000000..1c43223 --- /dev/null +++ b/emacs.d/lib/config.el @@ -0,0 +1,65 @@ +(dolist (mode '(tool-bar-mode scroll-bar-mode)) + (when (fboundp mode) (funcall mode -1))) + +;; auto close bracket insertion +(electric-pair-mode 1) + +;; ? +(add-hook 'prog-mode-hook + (lambda () (setq show-trailing-whitespace t))) + +;; this makes emacs slow to work with source +(delete 'Git vc-handled-backends) + +;; alias yes-or-no to y-or-n +(fset 'yes-or-no-p 'y-or-n-p) + +;; set utf-8 as the default encoding +(prefer-coding-system 'utf-8-unix) +(set-terminal-coding-system 'utf-8) +(set-keyboard-coding-system 'utf-8) + +;; reload the buffer when a file changes +(global-auto-revert-mode 1) + +;; global settings for built-in emacs parameters +(setq auto-save-default nil + auto-save-list-file-prefix nil + inhibit-startup-screen t + initial-scratch-message nil + make-backup-files nil + require-final-newline t + vc-follow-symlinks t + next-screen-context-lines 5 + column-number-mode t + ring-bell-function 'ignore + tab-always-indent 'complete) + +;; How long to display an echo-area message when the minibuffer is active. +(setq minibuffer-message-timeout 0.5) + +(setq-default indent-tabs-mode nil + create-lockfiles nil) + +;; show parenthesis +(show-paren-mode +1) + +;; no blinking cursor +(blink-cursor-mode -1) + +;; I don't want a frindge on the right +(fringe-mode '(4 . 0)) + +;; frame title +(setq frame-title-format '( "%b" " [" (:eval mode-name) "]")) + +;; Set default font. Large font for the main window, but small font for the modeline +(set-face-attribute 'default nil :family "Menlo" :height 130 :weight 'normal :width 'normal) +(set-face-attribute 'mode-line nil :height 110 :background "grey90") + +;; nicer background than plain white +(set-face-background 'default "#FAF6EB") + +(setq custom-file (expand-file-name "var/emacs-custom.el" user-emacs-directory)) + +(provide 'config) diff --git a/emacs.d/lib/funcs.el b/emacs.d/lib/funcs.el new file mode 100644 index 0000000..18899f6 --- /dev/null +++ b/emacs.d/lib/funcs.el @@ -0,0 +1,100 @@ +;;; funcs.el --- functions for my own usage + +(defun fc/load-time (emacs-start-time) + "How long did it take to load the configuration." + (let ((load-time (float-time (time-subtract (current-time) emacs-start-time)))) + (message (format "Emacs loaded in %.3fs" load-time)))) + +(defun fc/system-info () + "Display system informations" + (format + (concat "### System information :\n" + "- OS: %s\n" + "- Emacs: %s") + system-type + emacs-version)) + +(defun fc/emacs-is-ready () + "Emacs is ready" + (message "Emacs is ready.")) + +;; font manipulation +(defun fc/scale-up-or-down-font-size (direction) + "Scale the font. If DIRECTION is positive or zero the font is scaled up, +otherwise it is scaled down." + (interactive) + (let ((scale 0.5)) + (if (eq direction 0) + (text-scale-set 0) + (if (< direction 0) + (text-scale-decrease scale) + (text-scale-increase scale))))) + +(defun fc/scale-up-font () + "Scale up the font." + (interactive) + (fc/scale-up-or-down-font-size 1)) + +(defun fc/scale-down-font () + "Scale up the font." + (interactive) + (fc/scale-up-or-down-font-size -1)) + +(defun fc/reset-font-size () + "Reset the font size." + (interactive) + (fc/scale-up-or-down-font-size 0)) + +;; jump to the scratch buffer +(defun fc/switch-to-scratch () + "Switch to scratch, grab the region if it's active." + (interactive) + (let ((contents + (and (region-active-p) + (buffer-substring (region-beginning) + (region-end))))) + (switch-to-buffer "*scratch*") + (if contents + (progn + (goto-char (buffer-end 1)) + (insert contents))))) + +(global-set-key (kbd "s-N") 'fc/switch-to-scratch) + +;; rename a buffer +(defun fc/rename-this-buffer-and-file () + "Renames current buffer and file it is visiting." + (interactive) + (let ((name (buffer-name)) + (filename (buffer-file-name)) + (read-file-name-function 'read-file-name-default)) + (if (not (and filename (file-exists-p filename))) + (error "Buffer '%s' is not visiting a file!" name) + (let ((new-name (read-file-name "New name: " filename))) + (cond ((get-buffer new-name) + (error "A buffer named '%s' already exists!" new-name)) + (t + (rename-file filename new-name 1) + (rename-buffer new-name) + (set-visited-file-name new-name) + (set-buffer-modified-p nil) + (message "File '%s' successfully renamed to '%s'" name (file-name-nondirectory new-name)))))))) + +;; create temporary files +(defun fc/start--file (path) + "Create a file at PATH, creating any containing directories as necessary. +Visit the file after creation." + (make-directory (file-name-directory path) t) + (find-file path)) + +(defun fc/start-tmp-file (file-name) + "Create a file in /tmp for the given file name." + (interactive "sName of temporary file: ") + (fc/start--file (expand-file-name (format "/tmp/%s" file-name)))) + +(defun fc/start-nest-tmp-file (file-name) + "Create a file in ~/tmp on nest for the give file name." + (interactive "sName of the temporary file: ") + (fc/start--file (expand-file-name (format "/nest:~/tmp/%s" file-name)))) + +(provide 'funcs) diff --git a/emacs.d/lib/my-functions.el b/emacs.d/lib/my-functions.el deleted file mode 100644 index 3513a84..0000000 --- a/emacs.d/lib/my-functions.el +++ /dev/null @@ -1,99 +0,0 @@ -;; these functions are for loading my configuration -(defun fc/load-time (emacs-start-time) - "How long did it take to load the configuration." - (let ((load-time (float-time (time-subtract (current-time) emacs-start-time)))) - (message (format "Emacs loaded in %.3fs" load-time)))) - -(defun fc/system-info () - "Display system informations" - (format - (concat "### System information :\n" - "- OS: %s\n" - "- Emacs: %s") - system-type - emacs-version)) - -(defun fc/emacs-is-ready () - "Emacs is ready" - (message "Emacs is ready.")) - -;; font manipulation -(defun fc/scale-up-or-down-font-size (direction) - "Scale the font. If DIRECTION is positive or zero the font is scaled up, -otherwise it is scaled down." - (interactive) - (let ((scale 0.5)) - (if (eq direction 0) - (text-scale-set 0) - (if (< direction 0) - (text-scale-decrease scale) - (text-scale-increase scale))))) - -(defun fc/scale-up-font () - "Scale up the font." - (interactive) - (fc/scale-up-or-down-font-size 1)) - -(defun fc/scale-down-font () - "Scale up the font." - (interactive) - (fc/scale-up-or-down-font-size -1)) - -(defun fc/reset-font-size () - "Reset the font size." - (interactive) - (fc/scale-up-or-down-font-size 0)) - -;; jump to the scratch buffer -(defun fc/switch-to-scratch () - "Switch to scratch, grab the region if it's active." - (interactive) - (let ((contents - (and (region-active-p) - (buffer-substring (region-beginning) - (region-end))))) - (switch-to-buffer "*scratch*") - (if contents - (progn - (goto-char (buffer-end 1)) - (insert contents))))) - -(global-set-key (kbd "s-N") 'fc/switch-to-scratch) - -;; rename a buffer -(defun fc/rename-this-buffer-and-file () - "Renames current buffer and file it is visiting." - (interactive) - (let ((name (buffer-name)) - (filename (buffer-file-name)) - (read-file-name-function 'read-file-name-default)) - (if (not (and filename (file-exists-p filename))) - (error "Buffer '%s' is not visiting a file!" name) - (let ((new-name (read-file-name "New name: " filename))) - (cond ((get-buffer new-name) - (error "A buffer named '%s' already exists!" new-name)) - (t - (rename-file filename new-name 1) - (rename-buffer new-name) - (set-visited-file-name new-name) - (set-buffer-modified-p nil) - (message "File '%s' successfully renamed to '%s'" name (file-name-nondirectory new-name)))))))) - -;; create temporary files -(defun fc/start--file (path) - "Create a file at PATH, creating any containing directories as necessary. -Visit the file after creation." - (make-directory (file-name-directory path) t) - (find-file path)) - -(defun fc/start-tmp-file (file-name) - "Create a file in /tmp for the given file name." - (interactive "sName of temporary file: ") - (fc/start--file (expand-file-name (format "/tmp/%s" file-name)))) - -(defun fc/start-nest-tmp-file (file-name) - "Create a file in ~/tmp on nest for the give file name." - (interactive "sName of the temporary file: ") - (fc/start--file (expand-file-name (format "/nest:~/tmp/%s" file-name)))) - -(provide 'my-functions) diff --git a/emacs.d/lib/my-settings.el b/emacs.d/lib/my-settings.el deleted file mode 100644 index 89ce365..0000000 --- a/emacs.d/lib/my-settings.el +++ /dev/null @@ -1,63 +0,0 @@ -(dolist (mode '(tool-bar-mode scroll-bar-mode)) - (when (fboundp mode) (funcall mode -1))) - -;; auto close bracket insertion -(electric-pair-mode 1) - -;; ? -(add-hook 'prog-mode-hook - (lambda () (setq show-trailing-whitespace t))) - -;; this makes emacs slow to work with source -(delete 'Git vc-handled-backends) - -;; alias yes-or-no to y-or-n -(fset 'yes-or-no-p 'y-or-n-p) - -;; set utf-8 as the default encoding -(prefer-coding-system 'utf-8-unix) -(set-terminal-coding-system 'utf-8) -(set-keyboard-coding-system 'utf-8) - -;; reload the buffer when a file changes -(global-auto-revert-mode 1) - -;; global settings for built-in emacs parameters -(setq auto-save-default nil - auto-save-list-file-prefix nil - inhibit-startup-screen t - initial-scratch-message nil - make-backup-files nil - require-final-newline t - vc-follow-symlinks t - next-screen-context-lines 5 - column-number-mode t - ring-bell-function 'ignore - tab-always-indent 'complete) - -;; How long to display an echo-area message when the minibuffer is active. -(setq minibuffer-message-timeout 0.5) - -(setq-default indent-tabs-mode nil - create-lockfiles nil) - -;; show parenthesis -(show-paren-mode +1) - -;; no blinking cursor -(blink-cursor-mode -1) - -;; I don't want a frindge on the right -(fringe-mode '(4 . 0)) - -;; frame title -(setq frame-title-format '( "%b" " [" (:eval mode-name) "]")) - -;; Set default font. Large font for the main window, but small font for the modeline -(set-face-attribute 'default nil :family "Menlo" :height 130 :weight 'normal :width 'normal) -(set-face-attribute 'mode-line nil :height 110 :background "grey90") - -;; nicer background than plain white -(set-face-background 'default "#F6F6F6") - -(provide 'my-settings) -- cgit 1.4.1