Emacs tips and tricks
Forum rules
Share your brain ;)
Share your brain ;)
Re: Emacs tips and tricks
^ Cool stuff. I always use writeroom-mode, never tried olivetti-mode.
- franksinistra
- Ivana Fukalot
- Posts: 1093
- Joined: Mon Jan 27, 2014 2:03 am
- Location: 印尼国
Re: Emacs tips and tricks
^^^ MB, i think there's a client for yun baidu in python
EDIT: i think it's this one? https://github.com/houtianze/bypy
EDIT: i think it's this one? https://github.com/houtianze/bypy
rice no more.
Re: Emacs tips and tricks
Been using Docker a lot for work lately, couldn't resist a bit of Emacs integration: https://manuel-uberti.github.io/emacs/2 ... 19/docker/
- franksinistra
- Ivana Fukalot
- Posts: 1093
- Joined: Mon Jan 27, 2014 2:03 am
- Location: 印尼国
Re: Emacs tips and tricks
I recently ditched spaceline and spaceline-all-the-icons and decided to modify emacs standard mode-line instead. I use all-the-icons for it, anyway here's my code (sorry for the mess):
EDIT: Forgot preview.
Code: Select all
;; Parts of the code are taken from https://github.com/domtronn/all-the-icons.el/wiki/Mode-Line
;; Requires all-the-icons packages and fonts.
;; franksinistra -- 2017
(provide 'pretty-modeline)
(defun mode-line-fill-right (face reserve)
"Leave reserve space to the right of the mode-line)
(unless reserve
(setq reserve 20))
(when (and window-system (eq 'right (get-scroll-bar-mode)))
(setq reserve (- reserve 3)))
(propertize " "
'display `((space :align-to (- (+ right right-fringe right-margin) ,reserve)))))
(defun mode-line-fill-center (face reserve)
"Return empty space to the center of remaining space."
(unless reserve
(setq reserve 20))
(when (and window-system (eq 'right (get-scroll-bar-mode)))
(setq reserve (- reserve 3)))
(propertize " "
'display `((space :align-to (- (+ center (.5 . right-margin)) ,reserve
(.5 . left-margin))))))
;; Set length and padding
(defconst RIGHT_PADDING 1)
(defun reserve-left/middle ()
(/ (length (format-mode-line mode-line-align-middle)) 2))
(defun reserve-middle/right ()
(+ RIGHT_PADDING (length (format-mode-line mode-line-align-right))))
;; Mode-line functions, requires all-the-icons package and fonts
(defun custom-modeline-mode-icon ()
"Display major-mode associated with buffer"
(let ((icon (all-the-icons-icon-for-buffer)))
(unless (symbolp icon)
(propertize icon 'help-echo (format "Major-mode: ` %s'" major-mode)
'display '(raise 0.0)
'face `(:height 1.2 :family ,(all-the-icons-icon-family-for-buffer))))))
;;;; VC icons for modeline
(defun -custom-modeline-github-vc ()
(let ((branch (mapconcat 'concat (cdr (split-string vc-mode "[:-]")) "-")))
(concat
(propertize (format " %s" (all-the-icons-alltheicon "git")) 'face `(:height 1.2) 'display '(raise -0.1))
" · "
(propertize (format "%s" (all-the-icons-octicon "git-branch"))
'face `(:height 1.3 :family ,(all-the-icons-octicon-family))
'display '(raise -0.1))
(propertize (format " %s" branch) 'face `(:height 0.9)))))
(defun -custom-modeline-svn-vc ()
(let ((revision (cadr (split-string vc-mode "-"))))
(concat
(propertize (format " %s" (all-the-icons-faicon "cloud")) 'face `(:height 1.2) 'display '(raise -0.1))
(propertize (format " · %s" revision) 'face `(:height 0.9)))))
(defun custom-modeline-icon-vc ()
(when vc-mode
(cond
((string-match "Git[:-]" vc-mode) (-custom-modeline-github-vc))
((string-match "SVN-" vc-mode) (-custom-modeline-svn-vc))
(t (format "%s" vc-mode)))))
;;;; Flycheck icons for modeline
(defun custom-modeline-flycheck-status ()
(let* ((text (pcase flycheck-last-status-change
(`finished (if flycheck-current-errors
(let ((count (let-alist (flycheck-count-errors flycheck-current-errors)
(+ (or .warning 0) (or .error 0)))))
(format "✖ %s Issue%s" count (unless (eq 1 count) "s")))
"✔ No Issues"))
(`running "⟲ Running")
(`no-checker "⚠ No Checker")
(`not-checked "✖ Disabled")
(`errored "⚠ Error")
(`interrupted "⛔ Interrupted")
(`suspicious ""))))
(propertize text
'help-echo "Show Flycheck Errors"
'mouse-face '(:box 1)
'local-map (make-mode-line-mouse-map
'mouse-1 (lambda () (interactive) (flycheck-list-errors))))))
;; Set-up mode-line formats based on location
(setq mode-line-align-left
'(""
"%2 "
(:eval (custom-modeline-mode-icon))
"%2 "
(:propertize "%b" face mode-line-buffer-id)
"%2 "
(:eval (when (bound-and-true-p flycheck-mode)
(custom-modeline-flycheck-status)))
" "))
(setq mode-line-align-middle
'(""
(:eval (custom-modeline-icon-vc))
"%3 "
(:eval
(when (eql (buffer-modified-p) t)
;; propertize adds metadata to text, so you can add colours and formatting, amongst other things
(propertize (all-the-icons-faicon "chain-broken")
'face `(:family ,(all-the-icons-faicon-family)
:height 1.2))))
" "
(:eval
(when (eql buffer-read-only t)
(propertize (all-the-icons-faicon "lock")
'face `(:family ,(all-the-icons-faicon-family)
:height 1.2))))
""))
(setq mode-line-align-right
'(""
mode-line-misc-info
"%2 "
(:eval (format "%%l/%d : %%c " (line-number-at-pos (point-max))))))
(setq-default mode-line-format
"Set-up mode-line"
(list
mode-line-align-left
'(:eval (mode-line-fill-center 'mode-line
(reserve-left/middle)))
mode-line-align-middle
'(:eval
(mode-line-fill-right 'mode-line
(reserve-middle/right)))
mode-line-align-right))
rice no more.
Re: Emacs tips and tricks
^ I too ditched all the packages related to mode line and crafted my own:
Code: Select all
;;; The mode-line
(line-number-mode)
(column-number-mode)
;; Show buffer position percentage starting from top
(validate-setq mode-line-percent-position '(-3 "%o"))
;; Increase mode-line size with a border (box) of the same colour and
;; reduce font size by tweaking height
(set-face-attribute 'mode-line nil
:inverse-video nil
:height 0.9
:box '(:line-width 6 :color "#373b41" :style nil))
(set-face-attribute 'mode-line-inactive nil
:inverse-video nil
:height 0.9
:box '(:line-width 8 :color "#282a2e" :style nil))
(defvar mu-eyebrowse-mode-line
'(:propertize
(:eval
(when (bound-and-true-p eyebrowse-mode)
(let* ((num (eyebrowse--get 'current-slot))
(tag (when num
(nth 2 (assoc num (eyebrowse--get 'window-configs)))))
(str (concat
" "
(if (and tag (< 0 (length tag))) tag
(when num (int-to-string num)))
" ")))
str))))
"Mode line format for Eyebrowse.")
(put 'mu-eyebrowse-mode-line 'risky-local-variable t)
(defvar mu-projectile-mode-line
'(:propertize
(:eval (when (ignore-errors (projectile-project-root))
(concat " " (projectile-project-name))))
face font-lock-constant-face)
"Mode line format for Projectile.")
(put 'mu-projectile-mode-line 'risky-local-variable t)
(defvar mu-vc-mode-line
'(" " (:propertize
;; Strip the backend name from the VC status information
(:eval (let ((backend (symbol-name (vc-backend (buffer-file-name)))))
(substring vc-mode (+ (length backend) 2))))
face font-lock-keyword-face))
"Mode line format for VC Mode.")
(put 'mu-vc-mode-line 'risky-local-variable t)
(setq-default mode-line-format
'("%e" mode-line-front-space
mu-eyebrowse-mode-line ; Current workspace
"· "
;; Standard info about the current buffer
mode-line-mule-info
mode-line-client
mode-line-modified
mode-line-remote
mode-line-frame-identification
mode-line-buffer-identification " " mode-line-position
;; Some specific information about the current buffer:
mu-projectile-mode-line ; Project information
(vc-mode mu-vc-mode-line) ; VC information
(multiple-cursors-mode mc/mode-line) ; Number of cursors
;; And the modes
" " mode-line-modes mode-line-end-spaces))
- franksinistra
- Ivana Fukalot
- Posts: 1093
- Joined: Mon Jan 27, 2014 2:03 am
- Location: 印尼国
Re: Emacs tips and tricks
^ Very nice! Just wonder what is that font? It looks insanely crisp
rice no more.
Re: Emacs tips and tricks
^ Iosevka (PragmataPro-style)
Re: Emacs tips and tricks
Some tricks to work with log files (local and remote): https://manuel-uberti.github.io/emacs/2017/11/11/logs/
Re: Emacs tips and tricks
Speaking of mode line, a nice package recently found: https://github.com/tarsius/minions
Re: Emacs tips and tricks
^ and with moody and some fancy stuff.
Re: Emacs tips and tricks
If you use ripgrep (you should!) and ivy/counsel (what are you waiting for!?), this is something I "lifted" from Steve Purcell configuration and it has been proving to be a fantastic time-saver:
Code: Select all
(defun mu-counsel-search-project (initial-input &optional use-current-dir)
"Search using `counsel-rg' from the project root for INITIAL-INPUT.
If there is no project root, or if the prefix argument
USE-CURRENT-DIR is set, then search from the current directory
instead."
(interactive (list (thing-at-point 'symbol)
current-prefix-arg))
(let ((current-prefix-arg)
(dir (if use-current-dir
default-directory
(condition-case err
(projectile-project-root)
(error default-directory)))))
(funcall 'counsel-rg initial-input dir)))
(bind-key* "M-?" #'mu-counsel-search-project)
- wuxmedia
- Grasshopper
- Posts: 6445
- Joined: Wed Oct 17, 2012 11:32 am
- Location: Back in Blighty
- Contact:
Re: Emacs tips and tricks
ripgrep <- I get paid by the hour dude, if that search takes a few seconds more then so be it :D
Re: Emacs tips and tricks
A light theme I created just for the sake of updating an existing one to recent Emacs versions: https://github.com/manuel-uberti/doneburn-theme
- wuxmedia
- Grasshopper
- Posts: 6445
- Joined: Wed Oct 17, 2012 11:32 am
- Location: Back in Blighty
- Contact:
Re: Emacs tips and tricks
nice github contibution pattern :D
Re: Emacs tips and tricks
Emacs 26.1 is out, unless you're one of the bleeding edgers.
Re: Emacs tips and tricks
Folding code like a pro: https://github.com/tarsius/bicycle
Re: Emacs tips and tricks
I have done quite a lot of SQL lately. Spoiled as I am by the REPL-driven development enabled by Intero and CIDER, I could not resist having something for sql-mode as well:
This is bound to C-c C-z, and joy follows.
Code: Select all
(defun mu-sql-switch-to-sqli ()
"Switch to SQLi buffer."
(interactive)
(unless (and sql-buffer
(buffer-live-p (get-buffer sql-buffer)))
(sql-set-sqli-buffer))
(pop-to-buffer sql-buffer))
Re: Emacs tips and tricks
https://github.com/manuel-uberti/slow-keys
I ported another hidden thingy from Chris Done to a package of its own. Why? Because I was bored during lunch break yesterday. :)
Anyways, this seemed pretty useless and annoying to me at first, until I realised I do type too quickly especially when I am under pressure. This leads to typos and doesn't help calming me down to think a problem thoroughly.
Slowing down my typing helps me step back a bit, relax, and give my mind (and my hands) the time to figure out whatever I am trying to do.
I ported another hidden thingy from Chris Done to a package of its own. Why? Because I was bored during lunch break yesterday. :)
Anyways, this seemed pretty useless and annoying to me at first, until I realised I do type too quickly especially when I am under pressure. This leads to typos and doesn't help calming me down to think a problem thoroughly.
Slowing down my typing helps me step back a bit, relax, and give my mind (and my hands) the time to figure out whatever I am trying to do.
Re: Emacs tips and tricks
Code: Select all
(defun mu--start-with-p (symbol)
"Check if there is a SYMBOL at (point)."
(interactive)
(equal symbol (buffer-substring-no-properties (point) (+ 1 (point)))))
(defun mu--live-delete-and-extract-sexp ()
"Delete the sexp and return it."
(interactive)
(let* ((begin (point)))
(forward-sexp)
(let* ((result (buffer-substring-no-properties begin (point))))
(delete-region begin (point))
result)))
(defun mu--wrap-with-symbols (opening closing)
"Wrap current coll within OPENING and CLOSING."
(interactive)
(insert opening
(substring (mu--live-delete-and-extract-sexp) 1 -1)
closing))
(defun mu-live-cycle-clj-coll ()
"Convert the coll at (point) from (x) -> {x} -> [x] -> (x)."
(interactive)
(let* ((original-point (point)))
(while (and (> (point) 1)
(not (mu--start-with-p "("))
(not (mu--start-with-p "{"))
(not (mu--start-with-p "[")))
(backward-char))
(cond
((mu--start-with-p "(")
(mu--wrap-with-symbols "{" "}"))
((mu--start-with-p "{")
(mu--wrap-with-symbols "[" "]"))
((mu--start-with-p "[")
(mu--wrap-with-symbols "(" ")"))
((equal 1 (point))
(message "Beginning of file reached, this was probably a mistake.")))
(goto-char original-point)))
Re: Emacs tips and tricks
A little bored tonight (wife's out, you know the deal), so I reworked my configuration (again!): https://github.com/manuel-uberti/.emacs ... er/init.el
One huge init file is pretty easy to maintain with what Emacs offers (swiper-isearch, counsel-rg, imenu-anywhere...).
One huge init file is pretty easy to maintain with what Emacs offers (swiper-isearch, counsel-rg, imenu-anywhere...).