aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesús <heckyel@hyperbola.info>2019-11-06 17:20:55 -0500
committerJesús <heckyel@hyperbola.info>2019-11-06 17:20:55 -0500
commitc3a5ae44b04f72cff4278dbce2427f94f8e428b2 (patch)
treeb9e664a2cd395eba342ed2bebb2878eeb542d9d0
parent2de9f0c2ef0d7900e0b96d9db9b33be542a476f8 (diff)
downloademacs-personal-c3a5ae44b04f72cff4278dbce2427f94f8e428b2.tar.lz
emacs-personal-c3a5ae44b04f72cff4278dbce2427f94f8e428b2.tar.xz
emacs-personal-c3a5ae44b04f72cff4278dbce2427f94f8e428b2.zip
Refactoring and cleanup code
Linum-mode is disabled for default (can be activated with F6 key), and improves the handling of large files.
-rw-r--r--init.el45
-rw-r--r--modules/init-linum.el52
-rw-r--r--modules/init-nlinum.el118
3 files changed, 56 insertions, 159 deletions
diff --git a/init.el b/init.el
index 2bca5e9..43fdb56 100644
--- a/init.el
+++ b/init.el
@@ -7,9 +7,8 @@
;; Without this comment emacs25 adds (package-initialize) here
;; (package-initialize)
-(let* ((minver "24.4"))
- (when (version< emacs-version minver)
- (error "Emacs v%s or higher is required" minver)))
+;;; Time Mark
+(setq emacs-load-start-time (current-time))
;;; Welcome message
(setq-default initial-scratch-message
@@ -18,41 +17,6 @@
;;; Modules directory
(push (concat user-emacs-directory "modules") load-path)
-;;; Raise garbage collection threshold after init
-(defvar best-gc-cons-threshold
- 4000000
- "Best default gc threshold value. Should NOT be too big!")
-
-;; don't GC during startup to save time
-(setq gc-cons-threshold most-positive-fixnum)
-
-(setq emacs-load-start-time (current-time))
-
-;;----------------------------------------------------------------------------
-;; Which functionality to enable (use t or nil for true and false)
-;;----------------------------------------------------------------------------
-(setq *is-a-mac* (eq system-type 'darwin))
-(setq *win64* (eq system-type 'windows-nt))
-(setq *cygwin* (eq system-type 'cygwin) )
-(setq *linux* (or (eq system-type 'gnu/linux) (eq system-type 'linux)) )
-(setq *unix* (or *linux* (eq system-type 'usg-unix-v) (eq system-type 'berkeley-unix)) )
-(setq *emacs24* (>= emacs-major-version 24))
-(setq *emacs25* (>= emacs-major-version 25))
-(setq *emacs26* (>= emacs-major-version 26))
-(setq *no-memory* (cond
- (*is-a-mac*
- (< (string-to-number (nth 1 (split-string (shell-command-to-string "sysctl hw.physmem")))) 4000000000))
- (*linux* nil)
- (t nil)))
-
-;; @see https://www.reddit.com/r/emacs/comments/55ork0/is_emacs_251_noticeably_slower_than_245_on_windows/
-;; Emacs 25 does gc too frequently
-(when *emacs25*
- ;; (setq garbage-collection-messages t) ; for debug
- (setq best-gc-cons-threshold (* 64 1024 1024))
- (setq gc-cons-percentage 0.5)
-(run-with-idle-timer 5 t #'garbage-collect))
-
;;;------------------------------
;;; Features
;;;------------------------------
@@ -74,7 +38,7 @@
;; Utils
(require 'init-utils)
;; GUI
- (require 'init-nlinum)
+ (require 'init-linum)
(require 'init-gui)
(require 'init-editing-utils)
(require 'init-diminish)
@@ -127,8 +91,7 @@
(when (file-exists-p custom-file)
(load settings-file))
-(setq gc-cons-threshold best-gc-cons-threshold)
-
+;; Time Output
(when window-system
(let ((elapsed (float-time (time-subtract (current-time)
emacs-load-start-time))))
diff --git a/modules/init-linum.el b/modules/init-linum.el
new file mode 100644
index 0000000..8c48c9d
--- /dev/null
+++ b/modules/init-linum.el
@@ -0,0 +1,52 @@
+;;; init-nlinum.el --- .Emacs Configuration -*- lexical-binding: t -*-
+;;; Commentary:
+;;
+
+;;; Code:
+;;----------------------------------------------------------------------------
+;; Line numbers
+;;----------------------------------------------------------------------------
+;; Linum snippets from: https://www.emacswiki.org/emacs/LineNumbers
+
+(use-package linum
+ :config
+ (defun my-linum-get-format ()
+ "Defines LINUM-GET-FORMAT"
+ (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)))
+ (add-hook 'linum-before-numbering-hook 'my-linum-get-format)
+
+ (defun my-linum-format (line-number)
+ "Defines LINE-FORMAT"
+ (propertize (format my-linum-format-string line-number) 'face
+ (if (eq line-number my-current-line)
+ 'my-linum-hl
+ 'linum)))
+ (setq linum-format 'my-linum-format)
+
+ (defadvice linum-update (around my-linum-update)
+ "Defines LINUM-UPDATE for update lines"
+ (let ((my-current-line (line-number-at-pos)))
+ ad-do-it))
+ (ad-activate 'linum-update)
+
+ ;; Colors line active
+ ;; set in file init-theme.el
+ ;; fox example:
+ ;; (defface my-linum-hl
+ ;; '((t :background "gray20" :foreground "gold"))
+ ;; "Face for the currently active Line number"
+ ;; :group 'linum)
+ ;; )
+
+ :bind
+ (([f6] . linum-mode)))
+
+(provide 'init-linum)
+
+;; Local Variables:
+;; byte-compile-warnings: (not free-vars)
+;; End:
+;;; init-linum.el ends here
diff --git a/modules/init-nlinum.el b/modules/init-nlinum.el
deleted file mode 100644
index 622bd32..0000000
--- a/modules/init-nlinum.el
+++ /dev/null
@@ -1,118 +0,0 @@
-;;; init-nlinum.el --- .Emacs Configuration -*- lexical-binding: t -*-
-;;; Commentary:
-;;
-
-;;; Code:
-;;----------------------------------------------------------------------------
-;; Line numbers
-;;----------------------------------------------------------------------------
-;; Linum snippets from: https://www.emacswiki.org/emacs/LineNumbers
-(use-package nlinum
- :config
- (add-hook 'find-file-hook (lambda () (linum-mode 1)))
- (setq global-linum-mode t)
-)
-
-(use-package linum
- :config
- (linum-mode 1)
- :hook
- (apache-mode . linum-mode)
- (c-mode . linum-mode)
- (c++-mode . linum-mode)
- (elisp-mode . linum-mode)
- (html-mode . linum-mode)
- (js-mode . linum-mode)
- (js2-mode . linum-mode)
- (less-mode . linum-mode)
- (markdown-mode . linum-mode)
- (nginx-mode . linum-mode)
- (php-mode . linum-mode)
- (scss-mode . linum-mode)
- (sass-mode . linum-mode)
- (web-mode . linum-mode))
-
-(defun my-linum-get-format-string ()
- "Format the string of the column in the buffer.
-It helps to show the numbering plus a separation bar."
- (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)))
-
-(add-hook 'linum-before-numbering-hook 'my-linum-get-format-string)
-
-(defvar my-linum-current-line-number 0)
-
-(defun my-linum-format (line-number)
- "Defines LINE-NUMBER the numbering format of each.
-this helps maintain the format in the numbering"
- (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)
- "Defines LINUM-UPDATE for update lines.
-this helps maintain the format in the numbering"
- (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 ()
- "Funtions for position lines.
-this helps maintain the move visual."
- (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))
-
- (with-no-warnings
- (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 ()
- "Funtions for position lines.
-this helps maintain the move visual."
- (interactive)
- (with-no-warnings
- (goto-line (line-at-click)))
- (set-mark (point))
- (setq *linum-mdown-line*
- (line-number-at-pos)))
-
-(defun mu-select-linum ()
- "Funtions for position lines.
-this helps maintain the move visual."
- (interactive)
- (when *linum-mdown-line*
- (let (mu-line)
- ;; (goto-line (line-at-click))
- (setq mu-line (line-at-click))
- (with-no-warnings
- (goto-line (max *linum-mdown-line* mu-line)))
-
- (set-mark (line-end-position))
- (with-no-warnings
- (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)
-
-(provide 'init-nlinum)
-
-;; Local Variables:
-;; byte-compile-warnings: (not free-vars)
-;; End:
-;;; init-nlinum.el ends here