aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
Diffstat (limited to 'lisp')
-rw-r--r--lisp/init-editing-utils.el5
-rw-r--r--lisp/init-elpa.el38
-rw-r--r--lisp/init-gui.el45
-rw-r--r--lisp/init-nlinum.el76
-rw-r--r--lisp/init-theme.el10
-rw-r--r--lisp/init-utils.el24
-rw-r--r--lisp/lib/myemacs.el18
-rw-r--r--lisp/lib/sachachua.el39
8 files changed, 255 insertions, 0 deletions
diff --git a/lisp/init-editing-utils.el b/lisp/init-editing-utils.el
new file mode 100644
index 0000000..143d170
--- /dev/null
+++ b/lisp/init-editing-utils.el
@@ -0,0 +1,5 @@
+;; Delete trailing whitespace before saving fil
+(add-hook 'before-save-hook 'delete-trailing-whitespace)
+
+(myemacs/elapsed-time)
+(provide 'init-editing-utils)
diff --git a/lisp/init-elpa.el b/lisp/init-elpa.el
new file mode 100644
index 0000000..28737de
--- /dev/null
+++ b/lisp/init-elpa.el
@@ -0,0 +1,38 @@
+(require 'package)
+
+;; Repositories
+;; ================
+(let* ((no-ssl (and (memq system-type '(windows-nt ms-dos))
+ (not (gnutls-available-p))))
+ (proto (if no-ssl "http" "https")))
+ ;; Comment/uncomment these two lines to enable/disable MELPA and MELPA Stable as desired
+ (add-to-list 'package-archives (cons "melpa" (concat proto "://melpa.org/packages/")) t)
+ ;;(add-to-list 'package-archives (cons "melpa-stable" (concat proto "://stable.melpa.org/packages/")) t)
+ (when (< emacs-major-version 24)
+ ;; For important compatibility libraries like cl-lib
+ (add-to-list 'package-archives '("gnu" . (concat proto "://elpa.gnu.org/packages/")))))
+;; =================
+
+;;; Find packages if not installed
+
+;; =================
+;;; On-demand installation of packages
+(defun require-package (package &optional min-version no-refresh)
+ "Install given PACKAGE, optionally requiring MIN-VERSION.
+If NO-REFRESH is non-nil, the available package lists will not be
+re-downloaded in order to locate PACKAGE."
+ (if (package-installed-p package min-version)
+ t
+ (if (or (assoc package package-archive-contents) no-refresh)
+ (if (boundp 'package-selected-packages)
+ ;; Record this as a package the user installed explicitly
+ (package-install package nil)
+ (package-install package))
+ (progn
+ (package-refresh-contents)
+ (require-package package min-version t)))))
+;; =================
+
+(package-initialize)
+
+(provide 'init-elpa)
diff --git a/lisp/init-gui.el b/lisp/init-gui.el
new file mode 100644
index 0000000..86f0177
--- /dev/null
+++ b/lisp/init-gui.el
@@ -0,0 +1,45 @@
+;;-----------------------
+;; Remove some GUI stuff
+;;-----------------------
+(setq use-file-dialog nil)
+(setq use-dialog-box nil)
+(setq inhibit-startup-screen t)
+(setq inhibit-startup-echo-area-message t)
+(tool-bar-mode 0)
+(set-scroll-bar-mode nil)
+(menu-bar-mode 0)
+(setq make-backup-files nil)
+
+;;----------------------------------------------------------------------------
+;; Editor configuration
+;;----------------------------------------------------------------------------
+(setq indicate-empty-lines t)
+
+(let ((no-border '(internal-border-width . 0)))
+ (add-to-list 'default-frame-alist no-border)
+ (add-to-list 'initial-frame-alist no-border))
+
+(setq frame-title-format
+ '((:eval (if (buffer-file-name)
+ (abbreviate-file-name (buffer-file-name))
+ "%b"))))
+;; Non-zero values for `line-spacing' can mess up ansi-term and co,
+;; so we zero it explicitly in those cases.
+(add-hook 'term-mode-hook
+ (lambda ()
+ (setq line-spacing 0)))
+
+;;----------------------------------------------------------------------------
+;; Configure keys
+;;----------------------------------------------------------------------------
+(global-unset-key (kbd "C-z")) ; Stops C-z from minimizing window
+(global-set-key (kbd "M-<down>") (lambda () (interactive) (sanityinc/adjust-opacity nil -2))) ; M-down less visibility
+(global-set-key (kbd "M-<up>") (lambda () (interactive) (sanityinc/adjust-opacity nil 2))) ; M-up more visibility
+(global-set-key (kbd "M-0") (lambda () (interactive) (modify-frame-parameters nil '((alpha . 100))))) ; M-0 standard visibility
+(global-set-key (kbd "<f11>") 'myemacs/toggle-fullscreen) ; F11 FullScreen
+(global-set-key (kbd "s-C-+") 'sacha/increase-font-size) ; C-+ increase font size
+(global-set-key (kbd "s-C--") 'sacha/decrease-font-size) ; C-- decrease font size
+(global-set-key (kbd "<f12>") 'revert-buffer-no-confirm)
+(global-set-key (kbd "s-h") 'global-hl-line-mode) ; Highlight current line
+
+(provide 'init-gui)
diff --git a/lisp/init-nlinum.el b/lisp/init-nlinum.el
new file mode 100644
index 0000000..0e61eab
--- /dev/null
+++ b/lisp/init-nlinum.el
@@ -0,0 +1,76 @@
+;;----------------------------------------------------------------------------
+;; Line numbers
+;;----------------------------------------------------------------------------
+;; Linum snippets from: https://www.emacswiki.org/emacs/LineNumbers
+(require-package 'nlinum)
+(require 'linum)
+(require 'hl-line)
+
+(defface my-linum-hl
+ `((t :inherit linum :background ,(face-background 'hl-line nil t)))
+ "Face for the current line number."
+ :group 'linum)
+(add-hook 'linum-before-numbering-hook 'my-linum-get-format-string)
+
+(defun my-linum-get-format-string ()
+ (let* ((width (1+ (length (number-to-string
+ (count-lines (point-min) (point-max))))))
+ (format (concat "%" (number-to-string width) "d \u2502")))
+ (setq my-linum-format-string format)))
+
+(defvar my-linum-current-line-number 0)
+
+(defun my-linum-format (line-number)
+ (propertize (format my-linum-format-string line-number) 'face
+ (if (eq line-number my-linum-current-line-number)
+ 'my-linum-hl
+ 'linum)))
+(setq linum-format 'my-linum-format)
+
+(defadvice linum-update (around my-linum-update)
+ (let ((my-linum-current-line-number (line-number-at-pos)))
+ ad-do-it))
+(ad-activate 'linum-update)
+
+(defvar *linum-mdown-line* nil)
+
+(defun line-at-click ()
+ (save-excursion
+ (let ((click-y (cdr (cdr (mouse-position))))
+ (line-move-visual-store line-move-visual))
+ (setq line-move-visual t)
+ (goto-char (window-start))
+ (next-line (1- click-y))
+ (setq line-move-visual line-move-visual-store)
+ ;; If you are using tabbar substitute the next line with
+ ;; (line-number-at-pos))))
+ (1+ (line-number-at-pos)))))
+
+(defun md-select-linum ()
+ (interactive)
+ (goto-line (line-at-click))
+ (set-mark (point))
+ (setq *linum-mdown-line*
+ (line-number-at-pos)))
+
+(defun mu-select-linum ()
+ (interactive)
+ (when *linum-mdown-line*
+ (let (mu-line)
+ ;; (goto-line (line-at-click))
+ (setq mu-line (line-at-click))
+ (goto-line (max *linum-mdown-line* mu-line))
+ (set-mark (line-end-position))
+ (goto-line (min *linum-mdown-line* mu-line))
+ (setq *linum-mdown*
+ nil))))
+
+(global-set-key (kbd "<left-margin> <down-mouse-1>") 'md-select-linum)
+(global-set-key (kbd "<left-margin> <mouse-1>") 'mu-select-linum)
+(global-set-key (kbd "<left-margin> <drag-mouse-1>") 'mu-select-linum)
+
+(add-hook 'find-file-hook (lambda () (linum-mode 1)))
+(linum-mode)
+(setq global-linum-mode t)
+
+(provide 'init-nlinum)
diff --git a/lisp/init-theme.el b/lisp/init-theme.el
new file mode 100644
index 0000000..f3407dc
--- /dev/null
+++ b/lisp/init-theme.el
@@ -0,0 +1,10 @@
+(require-package 'sublime-themes)
+(load-theme 'spolsky t)
+
+;; Fix linum current-line highlight. Doesn't looks good with this theme
+(defface my-linum-hl
+ '((t :background "gray30" :foreground "gold"))
+ "Face for the currently active Line number"
+ :group 'linum)
+
+(provide 'init-theme)
diff --git a/lisp/init-utils.el b/lisp/init-utils.el
new file mode 100644
index 0000000..64dadc6
--- /dev/null
+++ b/lisp/init-utils.el
@@ -0,0 +1,24 @@
+;; Loads functions from libs
+(defun load-directory (dir)
+ (let ((load-it (lambda (f)
+ (load-file (concat (file-name-as-directory dir) f)))
+ ))
+ (mapc load-it (directory-files dir nil "\\.el$"))))
+
+;; Load lib functions
+(load-directory (expand-file-name "~/.emacs.d/lisp/lib/" user-emacs-directory))
+
+;; This is borrowed from https://github.com/purcell/emacs.d/blob/master/lisp/init-utils.el by Steve Purcell but I have added some stuff.
+
+(if (fboundp 'with-eval-after-load)
+ (defalias 'after-load 'with-eval-after-load)
+ (defmacro after-load (feature &rest body)
+ "After FEATURE is loaded, evaluate BODY."
+ (declare (indent defun))
+ '(eval-after-load ,feature
+ '(progn ,@body))))
+
+;; Elapsed time
+(myemacs/elapsed-time)
+
+(provide 'init-utils)
diff --git a/lisp/lib/myemacs.el b/lisp/lib/myemacs.el
new file mode 100644
index 0000000..6846bdc
--- /dev/null
+++ b/lisp/lib/myemacs.el
@@ -0,0 +1,18 @@
+;;----------------------------------------------------------------------------
+;; Some cool functions
+;;----------------------------------------------------------------------------
+;; These functions are made by me (Quitter: @heckyel) or
+;; heavily modified by me
+
+;;----------------------------------------------------------------------------
+;; Toggles fullscreen
+;;----------------------------------------------------------------------------
+(defun myemacs/toggle-fullscreen ()
+ (interactive)
+ (x-send-client-message nil 0 nil "_NET_WM_STATE" 32
+ '(2 "_NET_WM_STATE_FULLSCREEN" 0)))
+
+(defun myemacs/elapsed-time ()
+ (let ((elapsed (float-time (time-subtract (current-time)
+ emacs-start-time))))
+ (message "[STARTUP] Loading %s ... done (%.3fs)" load-file-name elapsed))) \ No newline at end of file
diff --git a/lisp/lib/sachachua.el b/lisp/lib/sachachua.el
new file mode 100644
index 0000000..c862223
--- /dev/null
+++ b/lisp/lib/sachachua.el
@@ -0,0 +1,39 @@
+;; Increase-decrease functions from Sacha Chua
+(defun sacha/increase-font-size ()
+ (interactive)
+ (set-face-attribute 'default
+ nil
+ :height
+ (ceiling (* 1.10
+ (face-attribute 'default :height)))))
+(defun sacha/decrease-font-size ()
+ (interactive)
+ (set-face-attribute 'default
+ nil
+ :height
+ (floor (* 0.9
+ (face-attribute 'default :height)))))
+
+;; Not original from Sacha. Taken from: http://emacsredux.com/blog/2013/05/22/smarter-navigation-to-the-beginning-of-a-line/
+(defun sacha/smarter-move-beginning-of-line (arg)
+ "Move point back to indentation of beginning of line.
+
+Move point to the first non-whitespace character on this line.
+If point is already there, move to the beginning of the line.
+Effectively toggle between the first non-whitespace character and
+the beginning of the line.
+
+If ARG is not nil or 1, move forward ARG - 1 lines first. If
+point reaches the beginning or end of the buffer, stop there."
+ (interactive "^p")
+ (setq arg (or arg 1))
+
+ ;; Move lines first
+ (when (/= arg 1)
+ (let ((line-move-visual nil))
+ (forward-line (1- arg))))
+
+ (let ((orig-point (point)))
+ (back-to-indentation)
+ (when (= orig-point (point))
+ (move-beginning-of-line 1))))