Initial commit

This commit is contained in:
Jesús
2018-07-29 20:12:28 -05:00
commit d172fb6e48
18 changed files with 1188 additions and 0 deletions

View File

@@ -0,0 +1,31 @@
;; Delete trailing whitespace before saving fil
(add-hook 'before-save-hook 'delete-trailing-whitespace)
;; Automatic pairs open symbols (, {, [...
;; Disable for default.
;; Uncomment the next 4 lines if you want to enable the pairs-mode
;;(when (fboundp 'electric-pair-mode)
;; (electric-pair-mode))
;;(when (eval-when-compile (version< "24.4" emacs-version))
;; (electric-indent-mode 1))
;;----------------------------------------------------------------------------
;; Show matching parens
;;----------------------------------------------------------------------------
(show-paren-mode 1)
;;----------------------------------------------------------------------------
;; More useful things - only one line
;;----------------------------------------------------------------------------
(set-default 'truncate-lines t)
(setq show-trailing-whitespace nil)
(setq site-lisp-path (file-name-as-directory (expand-file-name "site-lisp/" user-emacs-directory)))
;;----------------------------------------------------------------------------
;; Some basic preferences
;;----------------------------------------------------------------------------
(setq-default
indent-tabs-mode nil)
(myemacs/elapsed-time)
(provide 'init-editing-utils)

48
lisp/init-elpa.el Normal file
View File

@@ -0,0 +1,48 @@
;;; Find and load the correct package.el
;; When switching between Emacs 23 and 24, we always use the bundled package.el in Emacs 24
(let ((package-el-site-lisp-dir
(expand-file-name "site-lisp/package" user-emacs-directory)))
(when (and (file-directory-p package-el-site-lisp-dir)
(> emacs-major-version 23))
(message "Removing local package.el from load-path to avoid shadowing bundled version")
(setq load-path (remove package-el-site-lisp-dir load-path))))
(require 'package)
;; Repositories
;; ================
(setq package-archives
'(("melpa" . "https://melpa.org/packages/")
;;("melpa-stable" . "https://stable.melpa.org/packages/")
("gnu" . "https://elpa.gnu.org/packages/")
("org" . "https://orgmode.org/elpa/")))
(setq package-archive-priorities
'(("melpa" . 4)
("melpa-stable" . 0)
("gnu" . 1)
("org" . 3)))
;; =================
;;; 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)

2
lisp/init-flycheck.el Normal file
View File

@@ -0,0 +1,2 @@
(require-package 'flycheck)
(provide 'init-flycheck)

59
lisp/init-gui.el Normal file
View File

@@ -0,0 +1,59 @@
;;-----------------------
;; 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)))
;; Font theme (Monospace, or DejaVu Sans Mono if Monospace is not
;; present)
(condition-case nil
(set-frame-font "Monospace-9")
(error (set-frame-font "DejaVu Sans Mono-10")))
;;----------------------------------------------------------------------------
;; 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
;;----------------------------------------------------------------------------
;; clock
;;----------------------------------------------------------------------------
(setq display-time-day-and-date t)
(display-time)
(provide 'init-gui)

35
lisp/init-markdown.el Normal file
View File

@@ -0,0 +1,35 @@
;;----------------------------------------------------------------------------
;; Markdown mode
;;----------------------------------------------------------------------------
(require-package 'markdown-mode)
(autoload 'markdown-mode "markdown-mode"
"Major mode for editing Markdown files" t)
(add-to-list 'auto-mode-alist '("\\.markdown\\'" . markdown-mode))
(add-to-list 'auto-mode-alist '("\\.md\\'" . markdown-mode))
;;----------------------------------------------------------------------------
;; Generated HTML 5 and UTF-8 with Markdown
;;----------------------------------------------------------------------------
(eval-after-load "markdown-mode"
'(defalias 'markdown-add-xhtml-header-and-footer 'as/markdown-add-xhtml-header-and-footer))
(defun as/markdown-add-xhtml-header-and-footer (title)
"Wrap XHTML header and footer with given TITLE around current buffer."
(goto-char (point-min))
(insert "<!DOCTYPE html>\n"
"<html>\n"
"<head>\n<title>")
(insert title)
(insert "</title>\n")
(insert "<meta charset=\"utf-8\" />\n")
(when (> (length markdown-css-paths) 0)
(insert (mapconcat 'markdown-stylesheet-link-string markdown-css-paths "\n")))
(insert "\n</head>\n\n"
"<body>\n\n")
(goto-char (point-max))
(insert "\n"
"</body>\n"
"</html>\n"))
(provide 'init-markdown)

46
lisp/init-modeline.el Normal file
View File

@@ -0,0 +1,46 @@
;;----------------------------------------------------------------------------
;; Modeline configuration
;;----------------------------------------------------------------------------
(require-package 'smart-mode-line)
(require-package 'smart-mode-line-powerline-theme)
(require-package 'sml-modeline)
;; Show number of occurrences when searching
(require-package 'anzu)
(setq sml/theme 'powerline)
(setq sml/no-confirm-load-theme t)
(setq sml/shorten-modes t)
;; Show EOL mode
(setq sml/show-eol t)
;; Show remote buffers
(setq sml/show-remote t)
(sml/setup)
(add-to-list 'sml/replacer-regexp-list '("^~/Proyectos/git/" ":Git:") t)
(add-to-list 'sml/replacer-regexp-list '("^~/www/" ":www:") t)
(sml-modeline-mode t)
(custom-set-variables
'(anzu-search-threshold 1000)
'(anzu-replace-threshold 1000)
'(anzu-deactivate-region t)
'(anzu-input-idle-delay 0.1)
'(anzu-replace-to-string-separator " => "))
(global-anzu-mode +1)
(set-face-attribute 'anzu-mode-line nil
:foreground "yellow" :weight 'bold)
(define-key isearch-mode-map [remap isearch-query-replace] #'anzu-isearch-query-replace)
(define-key isearch-mode-map [remap isearch-query-replace-regexp] #'anzu-isearch-query-replace-regexp)
;;----------------------------------------------------------------------------
;; Keyboard shortcuts in Anzu Mode
;;----------------------------------------------------------------------------
(global-set-key (kbd "M-%") 'anzu-query-replace)
(global-set-key (kbd "s-<SPC>") 'anzu-query-replace)
(myemacs/elapsed-time)
(provide 'init-modeline)

76
lisp/init-nlinum.el Normal file
View File

@@ -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)

6
lisp/init-pkgbuild.el Normal file
View File

@@ -0,0 +1,6 @@
(require-package 'pkgbuild-mode)
(autoload 'pkgbuild-mode "pkgbuild-mode.el" "PKGBUILD mode." t)
(setq auto-mode-alist (append '(("/PKGBUILD$" . pkgbuild-mode)) auto-mode-alist))
(provide 'init-pkgbuild)

10
lisp/init-theme.el Normal file
View File

@@ -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)

24
lisp/init-utils.el Normal file
View File

@@ -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)

18
lisp/lib/myemacs.el Normal file
View File

@@ -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)))

39
lisp/lib/sachachua.el Normal file
View File

@@ -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))))