Compare commits

..

1 Commits

Author SHA1 Message Date
Gergely Polonkai
9d100afe03 Start implementing Gerrit package 2016-10-25 18:25:08 +02:00
32 changed files with 9420 additions and 6379 deletions

35
.gitignore vendored
View File

@ -1,4 +1,3 @@
/customizations.el
*~ *~
/session* /session*
/tramp /tramp
@ -16,14 +15,6 @@
/url/ /url/
/hgs-cache /hgs-cache
/smex-items /smex-items
/var/
/anaconda-mode/
/.last-package-update-day
/eln-cache
/.lsp-session-v1
/.dap-breakpoints
/elpy
# All hail use-package! # All hail use-package!
/elpa/ /elpa/
@ -37,29 +28,3 @@
# Newsticker # Newsticker
/newsticker /newsticker
# The “compiled” version of the Org configuration
/configuration.el
/bookmarks
/org-caldav-*.el
# Forge database
/forge-database.sqlite
/forge-database-v*.sql
/forge-database-v*.sqlite
# request.el cookie jars
/request/curl-cookie-jar
# Quelpa stuff
/quelpa
# Transient history
/transient/history.el
# Mastodon token list
/mastodon.plstore
/org-roam.db
/.org-id-locations
/projects

View File

@ -3,72 +3,27 @@
(setq mc/cmds-to-run-for-all (setq mc/cmds-to-run-for-all
'( '(
avy-goto-char c-electric-brace
backward-sexp c-electric-semi&comma
c-electric-brace c-indent-line-or-region
c-electric-colon electric-newline-and-maybe-indent
c-electric-paren hungry-delete-forward
c-electric-semi&comma indent-for-tab-command
c-electric-star kill-region
c-indent-line-or-region org-cycle
delete-indentation org-end-of-line
downcase-region org-kill-line
drag-stuff-down org-self-insert-command
electric-newline-and-maybe-indent sp-backward-delete-char
forward-sexp sp-backward-kill-word
gpolonkai/duplicate-line sp-delete-char
gpolonkai/move-to-beginning-of-line ))
gpolonkai/move-to-end-of-line
gpolonkai/org-space-key
hungry-delete-backward
hungry-delete-forward
indent-for-tab-command
kill-region
kill-sexp
kill-visual-line
kmacro-end-or-call-macro
magit-status
org-cycle
org-delete-indentation
org-end-of-line
org-force-self-insert
org-kill-line
org-meta-return
org-return
org-self-insert-command
org-yank
overwrite-mode
sp-backward-delete-char
sp-backward-kill-word
sp-delete-char
sp-kill-hybrid-sexp
sp-kill-region
sp-kill-word
sp-remove-active-pair-overlay
sp-rewrap-sexp
sp-unwrap-sexp
toggle-char-case
upcase-region
wdired--self-insert
yaml-electric-dash-and-dot
))
(setq mc/cmds-to-run-once (setq mc/cmds-to-run-once
'( '(
ace-jump-done drag-stuff-right
ace-jump-move end-of-buffer
ace-mc-add-char helm-M-x
ace-mc-add-multiple-cursors helm-find-files
ace-mc-add-single-cursor smartparens-strict-mode
ace-mc-do-keyboard-reset ))
ace-mc-quick-exchange
counsel-M-x
drag-stuff-right
end-of-buffer
helm-M-x
helm-confirm-and-exit-minibuffer
helm-find-files
smartparens-strict-mode
suspend-frame
yaml-electric-backspace
))

File diff suppressed because it is too large Load Diff

View File

@ -1 +0,0 @@
alias git git --no-pager $*

File diff suppressed because it is too large Load Diff

View File

@ -1,2 +1 @@
03618 Thu Aug 16 09:29:39 2018 Gergely Polonkai <gergely@polonkai.eu>
02667 Wed Oct 5 09:52:44 2016 Gergely Polonkai <gergely@polonkai.eu> 02667 Wed Oct 5 09:52:44 2016 Gergely Polonkai <gergely@polonkai.eu>

View File

@ -1 +0,0 @@
00000 Thu Aug 16 09:43:46 2018 Gergely Polonkai <gergely@polonkai.eu>

30
gerrit/gerrit.el Normal file
View File

@ -0,0 +1,30 @@
(eval-when-compile (require 'cl))
(require 'request)
(defun gerrit-json-read ()
"Gerrit puts five extra chars (\")]}'\n\")at the beginning of
each JSON response for security reasons. All this function does
is it strips those chars before calling `json-read'"
(goto-line 2)
(beginning-of-line)
(json-read))
(let ((username "epolger")
(password "EsthaiTh6Fu"))
(request
"https://gerrit.ericsson.se/a/changes/?q=status:open+owner:self"
:parser 'gerrit-json-read
:headers '(("Authorization"
(concat ("Basic "
(base64-encode-string (concat username
":"
password))))))
:success (function* (lambda (&key data &allow-other-keys)
(message "Success!")
(message "%s" data)))
:error (function* (lambda (&key error-thrown &allow-other-keys&rest _)
(message "Got error: %s" error-thrown)))
:complete (lambda (&rest _) (message "Finished!"))
:status-code '((401 . (lambda (&rest _) (message "Got 401"))))))

937
init.el
View File

@ -1,16 +1,929 @@
;;; init --- Summary
;;; Commentary:
;;; Code:
(setq custom-file (concat user-emacs-directory "customizations.el"))
(load custom-file)
;; Initialize the package system and use-package ;; Initialize the package system and use-package
(setq load-prefer-newer t) (setq load-prefer-newer t)
(require 'package)
(add-to-list 'package-archives
'("gnu" . "http://elpa.gnu.org/packages/"))
(add-to-list 'package-archives
'("melpa" . "https://melpa.org/packages/"))
(add-to-list 'package-archives
'("marmalade" . "http://marmalade-repo.org/packages/"))
(package-initialize)
;; I started moving my configuration to this Org file. Its easier to document this way. (unless (package-installed-p 'use-package)
(org-babel-load-file (expand-file-name "configuration.org" user-emacs-directory)) (package-refresh-contents)
(package-install 'use-package))
;;; init.el ends here ;; Set up my personal keymap early so I can use it in use-package
;; calls
(define-prefix-command 'gpolonkai/pers-map)
(define-key ctl-x-map "t" 'gpolonkai/pers-map)
;; Add path to my custom lisp functions
(add-to-list 'load-path (concat
user-emacs-directory
(convert-standard-filename "lisp/")))
;; Custom stuff
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(background-color "#7f7f7f")
'(background-mode dark)
'(blink-cursor-mode t)
'(column-number-mode t)
'(cursor-color "#5c5cff")
'(cursor-type (quote bar))
'(custom-enabled-themes (quote (tango-dark)))
'(custom-safe-themes
(quote
("84d2f9eeb3f82d619ca4bfffe5f157282f4779732f48a5ac1484d94d5ff5b279"
"c74e83f8aa4c78a121b52146eadb792c9facc5b1f02c917e3dbb454fca931223"
"3c83b3676d796422704082049fc38b6966bcad960f896669dfc21a7a37a748fa"
"a27c00821ccfd5a78b01e4f35dc056706dd9ede09a8b90c6955ae6a390eb1c1e"
"1e7e097ec8cb1f8c3a912d7e1e0331caeed49fef6cff220be63bd2a6ba4cc365"
"fc5fcb6f1f1c1bc01305694c59a1a861b008c534cae8d0e48e4d5e81ad718bc6"
default)))
'(echo-keystrokes 0.1)
'(foreground-color "#5c5cff")
'(indent-tabs-mode nil)
'(indicate-empty-lines t)
'(inhibit-startup-echo-area-message (user-login-name))
'(inhibit-startup-screen t)
'(initial-scratch-message nil)
'(package-selected-packages
(quote
(ace-window
ag
alert
avy
beacon
cheatsheet
coffee-mode
command-log-mode
company
company-c-headers
company-emoji
company-restclient
company-shell
diminish
drag-stuff
electric-case
electric-spacing
emamux
flycheck
flycheck-pkg-config
focus
ggtags
git-gutter
git-messenger
git-timemachine
gitconfig-mode
gitignore-mode
gnugo
gobgen
google
goto-last-change
helm
helm-ag
helm-chrome
helm-company
helm-descbinds
helm-describe-modes
helm-flycheck
helm-flyspell
helm-github-stars
helm-google
helm-gtags
helm-projectile
helm-smex
helm-swoop
helm-unicode
hungarian-holidays
hungry-delete
hyde
id-manager
identica-mode
jinja2-mode
js2-mode
json-mode
magit
magit-gerrit
magithub
markdown-mode
mc-extras
multiple-cursors
ng2-mode
nyan-mode
nyan-prompt
org
org-bullets
org-jekyll
org-projectile
org-random-todo
org-rtm
origami
plantuml-mode
projectile
rainbow-delimiters
rainbow-mode
restclient
restclient-helm
sass-mode
smart-mode-line
smart-mode-line-powerline-theme
smartparens
spinner
sx
typescript-mode
use-package
vala-mode
vala-snippets
wakatime-mode
xlicense
yaml-mode
yasnippet
zone-nyan)))
'(sgml-basic-offset 4)
'(show-trailing-whitespace t)
'(tab-width 4))
;; Custom face settings
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(aw-leading-char-face ((t (:inherit ace-jump-face-foreground :height 3.0))))
'(hl-line ((t (:inherit nil :background "gray25"))))
'(trailing-whitespace ((t (:inherit nil :background "red1"))))
'(whitespace-line ((t (:inherit nil :background "orange")))))
(set-face-attribute 'default t :font "Hack-10")
(set-frame-font "Hack-10" nil t)
;; UI hacks: turn off the scroll bar (thats why Nyan-cat is here),
;; the toolbar (I dont really use it), and the menu bar (I rarely use
;; it, and in those rare occasions I can simply turn it on)
(if (fboundp 'scroll-bar-mode) (scroll-bar-mode -1))
(if (fboundp 'tool-bar-mode) (tool-bar-mode -1))
(if (fboundp 'menu-bar-mode) (menu-bar-mode -1))
;; Some personal stuff
(setq user-mail-address "gergely@polonkai.eu")
;; Load some custom libraries
(require 'thingatpt)
(use-package helm
:ensure t
:init
(require 'helm-config)
(setq helm-M-x-fuzzy-match t
helm-buffers-fuzzy-matching t
helm-recentf-fuzzy-match t)
:config
(helm-mode t)
:bind
(("M-x" . helm-M-x)
("C-x C-f" . helm-find-files)
("C-x b" . helm-mini)))
(use-package helm-swoop
:ensure t
:bind
(("M-i" . helm-swoop)))
(use-package ggtags
:ensure t
:config
(add-hook 'c-mode-hook
(lambda ()
(ggtags-mode t)))
(add-hook 'c-mode-common-hook
(lambda ()
(when (derived-mode-p 'c-mode 'c++-mode 'java-mode)
(ggtags-mode t)))))
(use-package helm-gtags
:ensure t
:init
(setq-default helm-gtags-auto-update t
helm-gtags-ignore-case t
helm-gtags-path-style 'relative)
:config
(add-hook 'c-mode-hook
(lambda ()
(helm-gtags-mode t)))
:bind
(:map helm-gtags-mode-map
("M-t" . helm-gtags-find-tag)
("M-r" . helm-gtags-find-rtag)
("M-s" . helm-gtags-find-symbol)
("M-g M-p" . helm-gtags-parse-file)
("C-c <" . helm-gtags-previous-history)
("C-c >" . helm-gtags-next-history)
("M-," . helm-gtags-pop-stack)))
;; Whitespace mode
;;
;; It is turned on by default, and can be toggled with F10
(use-package whitespace
:demand
:config
(global-whitespace-mode 1)
:bind
(([f10] . whitespace-mode)
([(shift f10)] . global-whitespace-mode)))
;; Multiple cursors
(use-package multiple-cursors
:ensure t
:config
(add-hook 'multiple-cursors-mode-enabled-hook
(lambda ()
(setq blink-matching-paren nil)))
(add-hook 'multiple-cursors-mode-disabled-hook
(lambda ()
(setq blink-matching-paren t)))
:bind (("C-S-c C-S-c" . mc/edit-lines)
("C->" . mc/mark-next-like-this)
("C-<" . mc/mark-previous-like-this)
("C-c C-<" . mc/mark-all-like-this)))
(use-package eshell
:config
(add-hook 'eshell-mode-hook
(lambda () (local-set-key (kbd "C-d") #'eshell-C-d)))
:bind
(:map gpolonkai/pers-map
("e" . eshell)))
;; Save place
(use-package saveplace
:config
(setq-default save-place t)
(setq save-place-file (expand-file-name ".places" user-emacs-directory)))
;; Nyanyanyanyanya
(use-package nyan-mode
:ensure t
:init
(setq-default nyan-animate-nyancat t
nyan-wavy-trail t)
:config
(nyan-mode t))
(when (display-graphic-p)
(use-package nyan-prompt
:ensure t
:config
(add-hook 'eshell-load-hook 'nyan-prompt-enable)))
;; Zone!
(use-package zone-nyan
:ensure t
:init
(setq zone-programs [zone-nyan])
(setq-default zone-nyan-hide-progress t))
(use-package zone
:config
(zone-when-idle 60))
;; Magit and friends
(use-package magit
:ensure t
:init
(setq magit-auto-revert-mode nil)
(setq magit-last-seen-setup-instructions "1.4.0")
:bind
(("C-x g" . magit-status)))
(use-package magithub
:ensure t)
(use-package magit-gerrit
:ensure t
:init
(setq-default magit-gerrit-remote "gerrit"))
(use-package origami
:ensure t
:demand
:config
(define-prefix-command 'origami-mode-map)
(global-set-key (kbd "C-x C-z") 'origami-mode-map)
(global-origami-mode)
:bind
(:map origami-mode-map
("o" . origami-open-node)
("O" . origami-open-node-recursively)
("c" . origami-close-node)
("C" . origami-close-node-recursively)
("a" . origami-toggle-node)
("A" . origami-recursively-toggle-node)
("R" . origami-open-all-nodes)
("M" . origami-close-all-nodes)
("v" . origami-show-only-node)
("k" . origami-previous-fold)
("j" . origami-forward-fold)
("x" . origami-reset)))
(use-package helm-ag
:ensure t
:bind
(("C-x M-a" . helm-do-ag)))
(use-package smartparens
:ensure t
:demand
:config
(show-smartparens-global-mode t)
(add-hook 'prog-mode-hook
'turn-on-smartparens-strict-mode)
(add-hook 'markdown-mode-hook
'turn-on-smartparens-strict-mode)
:bind
(([f9] . smartparens-strict-mode)))
(use-package smart-mode-line
:ensure t
:config
(sml/setup))
(use-package company
:ensure t
:config
(global-company-mode))
(use-package helm-company
:ensure t
:after
company
helm
:bind
(:map company-mode-map
("C-S-j" . helm-company)
:map company-active-map
("C-S-j" . helm-company)))
(use-package projectile
:ensure t
:config
(projectile-global-mode t))
(use-package helm-projectile
:ensure t
:init
(setq projectile-completion-system 'helm)
:config
(helm-projectile-on))
(use-package drag-stuff
:ensure t
:config
(drag-stuff-global-mode t))
;; Git gutter
(use-package git-gutter
:ensure t
:config
(global-git-gutter-mode t))
;; Org mode
(use-package org
:ensure t
:demand
:init
(require 'xdg-paths)
(setq-default org-crypt-key "B0740C4C"
org-default-notes-file (concat user-documents-directory
(convert-standard-filename
"/orgmode/notes.org"))
org-directory (concat user-documents-directory
(convert-standard-filename "/orgmode/"))
org-agenda-files (concat user-documents-directory
(convert-standard-filename
"/orgmode/agenda_files"))
org-ellipsis "…#"
org-startup-folded 'content
org-mobile-directory (concat user-documents-directory
(convert-standard-filename
"/orgmode/mobile/"))
org-mobile-inbox-for-pull (concat
user-documents-directory
(convert-standard-filename
"/orgmode/from-mobile.org"))
org-log-done 'time)
:config
(unless (boundp 'org-capture-templates)
(setq org-capture-templates nil))
(add-to-list 'org-capture-templates
'("p" "Blog post"
entry (file+datetree (concat org-directory "blog.org"))
"* %^{Title} :blog:\n :PROPERTIES:\n :on: %T\n :END:\n %i%?"))
(setq org-time-stamp-formats '("<%Y-%m-%d>" . "<%Y-%m-%d %H:%M>"))
:bind
(:map gpolonkai/pers-map
("a" . org-agenda-list)
:map org-mode-map
("SPC" . org-space-key)))
(use-package org-bullets
:ensure t
:init
(add-hook 'org-mode-hook
(lambda ()
(if (display-graphic-p) org-bullets-mode))))
;; Waka-waka
(use-package wakatime-mode
:ensure t
:init
(setq-default wakatime-cli-path "/usr/local/bin/wakatime")
:config
(global-wakatime-mode t))
(use-package ace-window
:ensure t
:init
(setq aw-keys '(?a ?o ?e ?u ?i ?d ?h ?t ?n)
aw-background nil)
:bind
(("M-P" . ace-window)))
(use-package avy
:ensure t
:demand
:config
(avy-setup-default)
:bind
(("C-:" . avy-goto-char)
("C-'" . avy-goto-char-2)
("M-g f" . avy-goto-line)
("M-g w" . avy-goto-word-1)
("M-g e" . avy-goto-word-0)))
(use-package diminish
:ensure t
:defer t)
(use-package focus
:ensure t
:bind
(([f8] . focus-mode)))
(use-package coffee-mode
:ensure t)
(use-package command-log-mode
:ensure t)
(use-package company-c-headers
:ensure t)
(use-package company-shell
:ensure t)
(use-package electric-case
:ensure t
:config
(add-hook 'c-mode-hook ''electric-case-c-init))
(use-package electric-spacing
:ensure t
:bind
(([f7] . electric-spacing-mode)))
(use-package emamux
:ensure t)
(use-package flycheck
:ensure t)
(use-package flycheck-pkg-config
:ensure t)
(use-package git-messenger
:ensure t)
(use-package git-timemachine
:ensure t
:bind
(([f6] . git-timemachine-toggle)))
(use-package gitconfig-mode
:ensure t)
(use-package gitignore-mode
:ensure t)
(use-package gnugo
:ensure t)
(use-package gobgen
:ensure t)
(use-package goto-last-change
:ensure t
:bind
(("M-g /" . goto-last-change)))
(use-package helm-chrome
:ensure t)
(use-package helm-flycheck
:ensure t)
(use-package helm-flyspell
:ensure t
:demand
:bind
(:map flyspell-mode-map
("C-M-i" . helm-flyspell-correct)))
(use-package helm-github-stars
:ensure t
:init
(setq-default helm-github-stars-username "gergelypolonkai"))
(use-package helm-google
:ensure t)
(use-package hyde
:ensure t)
(use-package id-manager
:ensure t)
(use-package identica-mode
:ensure t)
(use-package jinja2-mode
:ensure t)
(use-package js2-mode
:ensure t)
(use-package json-mode
:ensure t)
(use-package markdown-mode
:ensure t)
(use-package mc-extras
:ensure t)
(use-package ng2-mode
:ensure t)
(use-package org-projectile
:ensure t)
(use-package sass-mode
:ensure t)
(use-package smart-mode-line-powerline-theme
:ensure t
:init
(setq-default sml/theme 'powerline))
(use-package spinner
:ensure t)
(use-package sx
:ensure t
:demand
:bind
(:map gpolonkai/pers-map
("qi" . sx-inbox)
("qs" . sx-search)))
(use-package typescript-mode
:ensure t)
(use-package vala-mode
:ensure t
:init
(add-to-list 'auto-mode-alist '("\\.vala\\'" . vala-mode)))
(use-package xlicense
:ensure t)
(use-package yaml-mode
:ensure t
:init
(add-to-list 'auto-mode-alist '("\\.yml\\'" . yaml-mode)))
(use-package helm-smex
:ensure t
:bind
(("M-X" . helm-smex)))
(use-package ediff
:ensure t
:init
(setq-default ediff-merge-split-window-function 'split-window-horizontally
ediff-split-window-function 'split-window-vertically
ediff-window-setup-function 'ediff-setup-windows-plain))
(use-package plantuml-mode
:ensure t
:init
(setq plantuml-jar-path
(expand-file-name
;; Make sure we have a download location even if XDG is not
;; working
(cond
((xdg-user-dir "DOWNLOAD")
(concat (xdg-user-dir "DOWNLOAD") "/plantuml.jar"))
(t
"~/Downloads/plantuml.jar"))))
(defvaralias 'org-plantuml-jar-path 'plantuml-jar-path)
:config
(org-babel-do-load-languages
'org-babel-load-languages
'((plantuml . t))))
(use-package org-random-todo
:ensure t
:config
;; Dont bug me too often…
(setq org-random-todo-how-often 3600))
(use-package calendar
:init
(setq calendar-week-start-day 1
calendar-latitude 47.4
calendar-longitude 19.0
calendar-location-name "Budapest, Hungary"
calendar-time-zone 60
calendar-standard-time-zone-name "CET"
calendar-daylight-time-zone-name "CEST"))
(use-package yasnippet
:ensure t
:config
(yas-global-mode 1))
(use-package vala-snippets
:ensure t
:after
yasnippet)
(use-package hungarian-holidays
:ensure t
:config
(hungarian-holidays-add))
(use-package beacon
:ensure t
:demand
:config
(beacon-mode 1)
:bind
(:map gpolonkai/pers-map
("b" . beacon-blink)))
(use-package flyspell
:config
(add-hook 'prog-mode-hook
'flyspell-prog-mode)
(add-hook 'text-mode-hook
'flyspell-mode))
(use-package helm-descbinds
:ensure t)
(use-package helm-describe-modes
:ensure t)
(use-package paren
:config
(show-paren-mode t))
(use-package autorevert
:config
(global-auto-revert-mode 1))
(use-package rainbow-delimiters
:ensure t
:config
(add-hook 'prog-mode-hook
#'rainbow-delimiters-mode))
(use-package rainbow-mode
:ensure t)
(use-package hungry-delete
:ensure t
:config
(global-hungry-delete-mode))
(use-package hl-line
:config
(global-hl-line-mode))
(use-package eww
:config
(setq eww-search-prefix "https://www.google.com/?q="))
(use-package electric
:config
;; This seems to be the default, but lets make sure…
(electric-indent-mode 1))
(use-package restclient
:ensure t)
(use-package company-restclient
:ensure t)
(use-package restclient-helm
:ensure t)
(use-package alert
:ensure t
:config
(setq alert-default-style 'notifications))
(use-package newsticker
:demand
:config
(setq newsticker-url-list '(("(or emacs irrelevant)"
"http://oremacs.com/atom.xml"
nil nil nil)
("think"
"http://batsov.com/atom.xml"
nil nil nil)
("Endless Parentheses"
"http://endlessparentheses.com/atom.xml"
nil nil nil)
("Irreal"
"http://irreal.org/blog/?feed=rss2"
nil nil nil)
;; The followint may supersede previous entries
("Planet Emacs"
"http://planet.emacsen.org/atom.xml"
nil nil nil)))
:bind
(:map gpolonkai/pers-map
("n" . newsticker-show-news)))
(use-package cheatsheet
:ensure t)
(use-package nxml
:config
(setq nxml-attribute-indent 4
nxml-child-indent 2
nxml-outline-child-indent 4))
(use-package savehist
:config
(savehist-mode 1))
;; Before this can be used, make sure the Symbola font is installed:
;; https://zhm.github.io/symbola/
(defun --set-emoji-font (frame)
"Adjust the font setting of FRAME so Emacs can display Emoji properly."
(when (fboundp 'set-fontset-font)
(if (eq system-type 'darwin)
;; For NS/Cocoa
(set-fontset-font t 'symbol
(font-spec :family "Apple Color Emoji")
frame 'prepend)
;; For Linux
(set-fontset-font t 'symbol
(font-spec :family "Symbola")
frame 'prepend))))
(use-package company-emoji
:ensure t
:after
company
:init
(--set-emoji-font nil)
:config
(add-to-list 'company-backends 'company-emoji)
(add-hook 'after-make-frame-functions
'--set-emoji-font))
;; Load my own functions
(load "gnu-c-header.el")
(load "toggle-window-split.el")
(load "round-number-to-decimals.el")
(load "transpose-windows.el")
(load "zim.el")
(load "clearcase.el")
(load "enclose-string.el")
(load "buf-manipulation.el")
(load "package-manip")
(load "text-manip")
(load "frame-manip")
;; Define aliases
(defalias 'yes-or-no-p 'y-or-n-p)
;; `c-mode' settings
(add-hook 'c-mode-hook
(lambda ()
(which-func-mode)))
(add-hook 'c-mode-common-hook
(lambda ()
(local-set-key (kbd "C-c o") 'ff-find-other-file)
(c-set-style "PERSONAL")
(setq tab-width 4
indent-tabs-mode nil)
(c-toggle-auto-newline 1)))
(add-hook 'c-initialization-hook
(lambda ()
(define-key c-mode-base-map (kbd "C-m") 'c-context-line-break)))
(defvaralias 'c-basic-offset 'tab-width)
(defvaralias 'cperl-indent-level 'tab-width)
(defconst my-c-style
'((c-tab-always-indent . t)
(c-comment-only-line-offset . 4)
(c-hanging-braces-alist . ((substatement-open after)
(brace-list-open)))
(c-hanging-colons-alist . ((member-init-intro before)
(inher-intro)
(case-label after)
(label after)
(access-label after)))
(c-cleanup-list . (scope-operator
empty-defun-braces
defun-close-semi))
(c-offsets-alist . ((arglist-close . +)
(arglist-intro . ++)
(substatement-open . 0)
(case-label . 4)
(block-open . 0)
(knr-argdecl-intro . -)
(comment-intro . 0)))
(c-echo-syntactic-information-p . t))
"My C Programming Style")
(c-add-style "PERSONAL" my-c-style)
(setq c-offset-alist '((member-init-intro . ++)))
;; Custom key bindings
(global-set-key (kbd "C-x _") 'maximize-window)
(global-set-key (kbd "C-c C-y") 'duplicate-line)
(global-set-key (kbd "M-(") 'æ-enclose-region)
(global-set-key (kbd "C-x w") 'webjump)
(global-set-key (kbd "<C-return>") 'open-line-below)
(global-set-key (kbd "<C-S-return>") 'open-line-above)
(global-set-key (kbd "C-x C-r") 'rename-current-buffer-file)
(global-set-key (kbd "C-x C-d") 'delete-current-buffer-file)
(global-set-key (kbd "C-x ~") 'toggle-char-case)
(define-key isearch-mode-map (kbd "<C-return>") #'isearch-exit-other-end)
(define-key gpolonkai/pers-map (kbd "m") 'hidden-mode-line-mode)
;; Kudos goes to
;; http://endlessparentheses.com/leave-the-cursor-at-start-of-match-after-isearch.html
(defun isearch-exit-other-end ()
"Exit isearch, at the opposite end of the string"
(interactive)
(isearch-exit)
(goto-char isearch-other-end))
;; Set up some global minor modes
(global-prettify-symbols-mode t)
;; Enable some functions
(put 'downcase-region 'disabled nil)
(put 'upcase-region 'disabled nil)
;; text-mode settings
(add-hook 'text-mode-hook (lambda () (visual-line-mode t)))
;; Add some symbols to be prettified
(setq prettify-symbols-alist
'(("lambda" . 955) ; λ
("->" . 8594) ; →
("=>" . 8658) ; ⇒
("map" . 8614))) ; ↦
;; …and some pairs to complete
;; TODO: maybe add-to-list is a better way to do it
(setq insert-pair-alist
'(
(40 41) ; ()
(91 93) ; []
(123 125) ; {}
(60 62) ; <>
(34 34) ; ""
(39 39) ; ''
(96 39) ; `'
(8220 8221) ; “”
(8222 8221) ; „”
(8216 8217) ;
(8249 8250) ;
(8250 8249) ;
(171 187) ; «»
(187 171) ; »«
))
;; Check for package upgrades every Monday so I dont forget.
(check-for-package-upgrades-on-day 1)

129
lisp/buf-manipulation.el Normal file
View File

@ -0,0 +1,129 @@
;; Some custom functions for buffer content manipulation
(defun delete-current-line ()
"Kill the whole line on which point is"
(interactive)
(beginning-of-line)
(kill-line 1))
(defun copy-func-prototype ()
"Copy the current function's prototype to the kill-ring"
(interactive)
(save-excursion
(beginning-of-defun)
(setq protocopy-begin (point))
(forward-list)
(setq protocopy-end (point))
(kill-ring-save protocopy-begin protocopy-end)))
(defun duplicate-line()
"Duplicate line at point."
(interactive)
(save-excursion
(move-beginning-of-line 1)
(kill-line)
(yank)
(open-line 1)
(next-line 1)
(yank)))
(defun toggle-char-case (arg-move-point)
"Toggle the case of the char after point. Based on Xah's toggle letter
case defun version 2015-12-22
URL `http://ergoemacs.org/emacs/modernization_upcase-word.html'
Version 2016-02-16"
(interactive "P")
(let ((case-fold-search nil))
(cond
((looking-at "[[:lower:]]") (upcase-region (point) (1+ (point))))
((looking-at "[[:upper:]]") (downcase-region (point) (1+ (point)))))
(cond
(arg-move-point (right-char)))))
; Copied from http://whattheemacsd.com/editing-defuns.el-01.html
(defun open-line-below ()
"Open a new line below point."
(interactive)
(end-of-line)
(newline)
(indent-for-tab-command))
(defun open-line-above ()
"Open a new line above point."
(interactive)
(beginning-of-line)
(newline)
(forward-line -1)
(indent-for-tab-command))
; Copied from http://whattheemacsd.com/file-defuns.el-01.html
(defun rename-current-buffer-file ()
"Renames current buffer and file it is visiting."
(interactive)
(let ((name (buffer-name))
(filename (buffer-file-name)))
(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)))
(if (get-buffer new-name)
(error "A buffer named '%s' already exists!" new-name)
(rename-file filename new-name 1)
(rename-buffer new-name)
(set-visited-file-name new-name)
; TODO: this is suspicious for me…
(set-buffer-modified-p nil)
(message "File '%s' successfully renamed to '%s'"
name (file-name-nondirectory new-name)))))))
; Copied from http://whattheemacsd.com/file-defuns.el-02.html
(defun delete-current-buffer-file ()
"Removes file connected to current buffer and kills the
buffer."
(interactive)
(let ((filename (buffer-file-name))
(name (buffer-name))
(buffer (current-buffer)))
(if (not (and filename (file-exists-p filename)))
(kill-buffer buffer)
(when (yes-or-no-p "Are you sure you want to remove this file? ")
(delete-file filename)
(kill-buffer buffer)
(message "File '%s' successfully removed" filename)))))
; delete-char or close eshell
; Copied from https://ryuslash.org/posts/C-d-to-close-eshell.html
(defun eshell-C-d ()
"Either call `delete-char' interactively or quit."
(interactive)
(condition-case err
(call-interactively #'delete-char)
(error (if (and (eq (car err) 'end-of-buffer)
(looking-back eshell-prompt-regexp))
(kill-buffer)
(signal (car err) (cdr err))))))
(defun æ-kill-or-copy-whole-line (kill)
"Kill or copy the whole line point is on.
If KILL is non-nil, the line gets killed. Otherwise, it gets just
copied to the kill-ring."
(interactive "P")
(if kill
(kill-whole-line)
(let ((beginning (progn (beginning-of-line) (point)))
(end (progn (end-of-line) (point))))
(copy-region-as-kill beginning end))))

7968
lisp/clearcase.el Normal file

File diff suppressed because it is too large Load Diff

34
lisp/enclose-string.el Normal file
View File

@ -0,0 +1,34 @@
(defun æ-enclose-region (character &optional start end)
"Enclose region in CHARACTER. If region is empty, simply inserts
CHARACTER two times and moves point between them.
If character is present in `insert-pair-alist', this function
will enclose region in the corresponding pair. In this case,
CHARACTER must be the opening member of the pair."
(interactive "cWhat character? \nr")
(setq open character close character)
(let ((pair (assq character insert-pair-alist)))
(if pair
(if (nth 2 pair)
(setq open (nth 1 pair) close (nth 2 pair))
(setq open (nth 0 pair) close (nth 1 pair)))))
(unless (and open close)
(setq open character)
(setq close character))
(unless (use-region-p)
(setq start (point) end (point)))
(save-excursion
(goto-char end)
(insert-char close)
(goto-char start)
(insert-char open))
(unless (use-region-p)
(forward-char)))

View File

@ -1,94 +0,0 @@
;;; flycheck-swagger-tools --- Flycheck checker for swagger-tools.
;; Copyright (C) 2017 Marc-André Goyette
;; Author: Marc-André Goyette <goyette.marcandre@gmail.com>
;; URL: https://github.com/magoyette/flycheck-swagger-tools
;; Version: 0.1.0
;; Package-Requires: ((emacs "25"))
;; Keywords: swagger
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; For a full copy of the GNU General Public License
;; see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; flycheck-swagger-tools provides a Flycheck checker for swagger-tools.
;; This allows to validate Swagger YAML and JSON files.
;; The checker can be activating by requiring this package.
;; (require 'flycheck-swagger-tools)
;; By default, only the first 4000 characters of a file are scanned to
;; find the swagger 2.0 element. To avoid stack overflow in Emacs
;; multi-line regex, this value is necessary. The defcustom
;; swagger-tools-predicate-regexp-match-limit can be used to change this
;; limit. That could be necessary for YAML files with long initial comments.
;;; Code:
(require 'flycheck)
(defgroup swagger-tools nil
"Validate swagger files with swagger-tools."
:group 'swagger
:prefix "swagger-tools-")
(defcustom swagger-tools-predicate-regexp-match-limit 4000
"Defines the number of characters that will be scanned at the beginning of a
buffer to find the swagger 2.0 element."
:type 'integer
:group 'swagger-tools)
;;;###autoload
(flycheck-define-checker swagger-tools
"A checker that uses swagger tools to validate Swagger2 JSON and YAML files.
See URL `https://github.com/apigee-127/swagger-tools'."
:command ("swagger-tools" "validate" source)
:predicate
(lambda ()
(string-match
"\\(.\\|\n\\)*\\([[:space:]]\\|\"\\|\\'\\)*swagger\\([[:space:]]\\|\"\\|\\'\\)*:[[:space:]]*[\"\\']2.0[\"\\'].*"
;; Need to avoid stack overflow for multi-line regex
(buffer-substring 1 (min (buffer-size)
swagger-tools-predicate-regexp-match-limit))))
:error-patterns
((warning line-start " " (message (one-or-more not-newline)
"is not used"
(one-or-more not-newline))
line-end)
;; js-yaml error with position
(error line-start " error: " (message) " at line " line ", column " column ":" line-end)
;; js-yaml error without position
(error line-start " error: " (message) ": " (one-or-more not-newline) line-end)
;; swagger-tools error (always contain a # symbol in the message)
(error line-start
" "
(message (optional (one-or-more not-newline))
(one-or-more "#")
(one-or-more not-newline))
line-end))
:error-filter
;; Add line number 1 if the error has no line number
(lambda (errors)
(let ((errors (flycheck-sanitize-errors errors)))
(dolist (err errors)
(unless (flycheck-error-line err)
(setf (flycheck-error-line err) 1)))
errors))
:modes (json-mode openapi-yaml-mode yaml-mode))
(add-to-list 'flycheck-checkers 'swagger-tools)
(provide 'flycheck-swagger-tools)
;;; flycheck-swagger-tools.el ends here

24
lisp/frame-manip.el Normal file
View File

@ -0,0 +1,24 @@
;; Copied from http://emacs-doctor.com/emacs-strip-tease.html
(defvar hidden-mode-line-mode nil)
(defvar hide-mode-line nil)
(define-minor-mode hidden-mode-line-mode
"Minor mode to hide the mode-line in the current buffer."
:init-value nil
:global nil
:variable hidden-mode-line-mode
:group 'editing-basics
(if hidden-mode-line-mode
(setq hide-mode-line mode-line-format
mode-line-format nil)
(setq mode-line-format hide-mode-line
hide-mode-line nil))
(force-mode-line-update)
(redraw-display)
(when (and (called-interactively-p 'interactive)
hidden-mode-line-mode)
(run-with-idle-timer
0 nil 'message
(concat "Hidden Mode Line Mode enabled. "
"Use M-x hidden-mode-line-mode to make mode-line appear."))))

65
lisp/gnu-c-header.el Normal file
View File

@ -0,0 +1,65 @@
;;; gnu-c-header.el --- function to add a header to the C files licensed under the GPL
;; Author: Gergely Polonkai <gergely@polonkai.eu>
;; Copyright: public domain
;; URL: http://gergely.polonkai.eu/blog/2014/09/26/emacs-adding-gnu-c-headers
;; Keywords: gnu, c, header, helper, utilities
;;; Commentary:
;;; Code:
(defun file-name-base-with-extension (&optional filename)
"Return the base name of the FILENAME without its directory path.
FILENAME defaults to `buffer-file-name'."
(file-name-nondirectory (or filename (buffer-file-name))))
(defun add-gnu-c-header (progname purpose)
"Add a GNU GPL header to the current buffer"
(interactive "sProgram name (ie: MyProgram): \nsPurpose of the file (ie: string utility functions): ")
(save-excursion
(goto-char (point-min))
(insert (concat
"/* "
(file-name-base-with-extension buffer-file-name)
" - "
purpose
" for "
progname
"\n"
" *\n"
" * Copyright (C) "
(format-time-string "%Y" (current-time))
" "
(user-full-name)
"\n"
" *\n"))
(let ((start (point)))
(insert (concat
" * "
progname
" is \n * free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version."))
(let ((end (point)))
(fill-region start end)))
(insert (concat
"\n"
" *\n"))
(let ((start (point)))
(insert (concat
" * "
progname
" is \n * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details."))
(let ((end (point)))
(fill-region start end)))
(insert (concat
"\n"
" *\n"))
(let ((start (point)))
(insert " * You \n * should have received a copy of the GNU General Public License along with this software; if not, see <http://www.gnu.org/licenses/>.")
(let ((end (point)))
(fill-region start end)))
(insert (concat
"\n"
" */\n"))
))
(provide 'gnu-c-header)
;;; gnu-c-header.el ends here

View File

@ -1,27 +0,0 @@
;;; gp-mouse --- Extra mouse functionality
;;; Commentary:
;;; Code:
(require 'mouse)
(defun gpolonkai/event-in-current-window-p (event)
"Check if EVENT happened in the current window."
(let ((current-window (selected-window))
(event-window (posn-window (event-start event))))
(eq current-window event-window)))
(defun gpolonkai/mouse-set-point (click &optional promote-to-region)
"Set mouse position.
If CLICK happened in an inactive window, select that window without setting point"
(interactive "e\np")
(if (gpolonkai/event-in-current-window-p click)
(call-interactively 'mouse-set-point)
(call-interactively 'mouse-select-window)))
(global-set-key [mouse-1] 'mouse-select-window-or-set-point)
(global-unset-key [down-mouse-1])
(provide 'gp-mouse)
;;; gp-mouse.el ends here

View File

@ -1,70 +0,0 @@
;;; minari.el --- Calculate Minari dates
;;; Commentary:
;;
;;; Code:
(defconst minari-special-day-names
'("Hëður" "Rideyy" "Morkh" "Morkh+" "Khmerd" "Chamog")
"Names of the special (monthless) days of the year.")
(defconst minari-weekday-names
'("Rounn" "Mïrdu" "Hëmi" "Drak" "Þodon" "Charm")
"Names of weekdays.")
(defconst minari-month-names
'("Mëbel" "Dirann" "Ma"
"Gerub" "Þrei" "Dimoc"
"Xentor" "Mëðïr" "Draþ"
"Quaden" "Ridïmel" "Rodom")
"Names of months.")
(defun minari-today-string ()
"Calculate today's date according to the Minari Calendar."
(let ((today (decode-time (current-time))))
;; FIXME: Im not sure about this one… If I increment by 11, I get a
;; wrong date according to my GNOME Shell extension. If I increment by
;; 10, the date is OK, but by calculating it in my head, its bad.
(incf (nth 3 today) 10)
(let* ((minari-leap (date-leap-year-p (nth 5 today)))
(doy (time-to-day-in-year (apply 'encode-time today)))
(minari-year (- (nth 5 today) 1873))
(minari-month 0)
(minari-doy 0)
(minari-day 0)
(minari-weekday 0)
(minari-special-day -1))
(cond
((eq doy 0) (setq minari-special-day 0))
((eq doy 91) (setq minari-special-day 1))
((eq doy 182) (setq minari-special-day 2))
((and (eq doy 183) minari-leap) (setq minari-special-day 3))
((and (eq doy 273) (not minari-leap)) (setq minari-special-day 4))
((and (eq doy 274) minari-leap) (setq minari-special-day 4))
((and (eq doy 364) (not minari-leap)) (setq minari-special-day 5))
((and (eq doy 365) minari-leap) (setq minari-special-day 5))
(t (let ((decr 0)
(minari-doy doy))
(when (> minari-doy 0) (incf decr))
(when (> minari-doy 91) (incf decr))
(when (> minari-doy 182) (incf decr))
(when (and (> minari-doy 183) minari-leap) (incf decr))
(when (and (> minari-doy 273) (not minari-leap)) (incf decr))
(when (and (> minari-doy 274) minari-leap) (incf decr))
(setq minari-doy (- minari-doy (- decr 1))
minari-month (round (fceiling (/ minari-doy 30.0)))
minari-day (% minari-doy 30))
(when (eq minari-day 0) (setq minari-day 30))
(setq minari-weekday (% minari-day 6)))))
(if (eq -1 minari-special-day)
(format "%d %s %s (%s)"
minari-year
(nth (- minari-month 1) minari-month-names)
minari-day
(nth minari-weekday minari-weekday-names))
(nth (- minari-special-day 1) minari-special-day-names)))))
(provide 'minari)
;;; minari.el ends here

View File

@ -1,17 +0,0 @@
(setq-default
mode-line-format
("%e"
mode-line-front-space
mode-line-mule-info
mode-line-client
mode-line-modified
mode-line-remote
mode-line-frame-identification
mode-line-buffer-identification
" "
mode-line-position
(vc-mode vc-mode)
" "
mode-line-modes
mode-line-misc-info
mode-line-end-spaces))

102
lisp/package-manip.el Normal file
View File

@ -0,0 +1,102 @@
;;; package-manip.el --- Utility functions to check if package upgrades are available
;;; Commentary:
;; I should add one.
;; Credits go to http://emacs.stackexchange.com/a/16407/507
;;; Code:
(defun package-upgrade-all ()
"Upgrade all packages automatically without showing *Packages* buffer."
(interactive)
(package-refresh-contents)
(let (upgrades)
(cl-flet ((get-version (name where)
(let ((pkg (cadr (assq name where))))
(when pkg
(package-desc-version pkg)))))
(dolist (package (mapcar #'car package-alist))
(let ((in-archive (get-version package package-archive-contents)))
(when (and in-archive
(version-list-< (get-version package package-alist)
in-archive))
(push (cadr (assq package package-archive-contents))
upgrades)))))
(if upgrades
(when (yes-or-no-p
(message "Upgrade %d package%s (%s)? "
(length upgrades)
(if (= (length upgrades) 1) "" "s")
(mapconcat #'package-desc-full-name upgrades ", ")))
(save-window-excursion
(dolist (package-desc upgrades)
(let ((old-package (cadr (assq (package-desc-name package-desc)
package-alist))))
(package-install package-desc)
(package-delete old-package)))))
(message "All packages are up to date"))))
(defun check-todays-package-upgrade-p (&optional no-save)
"Check if automatic package upgrade has been performed today.
This function reads the date of the last check from the
\"last-package-upgrade\" file. Where this file is looked for is
guessed as follows:
If `user-emacs-cache-directory' is set (e.g. by the
`xdg-paths.el' package available from
https://github.com/tomprince/xdg-paths-el), the timestamp file is
opened from there. Otherwise, it will be read from
`user-emacs-directory'
If NO-SAVE is 'nil', the current date will be saved to the
timestamp file.
The return value of this function will be 't' if the timestamp
file contains todays date, 'nil' otherwise."
(let ((tsfile-location (if (boundp 'user-emacs-cache-directory)
user-emacs-cache-directory
user-emacs-directory)))
(unless (and (file-exists-p tsfile-location)
(file-accessible-directory-p tsfile-location))
(make-directory tsfile-location t))
(let ((timestamp-today t)
(timestamp-buffer (find-file-literally
(expand-file-name "last-package-upgrade"
tsfile-location))))
(with-current-buffer timestamp-buffer
(goto-char 0)
(unless (looking-at-p (format-time-string "%Y-%m-%d"))
(unless no-save
(erase-buffer)
(insert (format-time-string "%Y-%m-%d"))
(save-buffer 0))
(setq timestamp-today nil))
(kill-buffer)
timestamp-today))))
(defun check-for-package-upgrades-on-day (&optional day-number)
"Check for package upgrades if today is DAY-NUMBER.
DAY-NUMBER can be anything between 0 and 7, inclusive. Both 0
and 7 denote Sunday to make both types of users happy.
If DAY-NUMBER is 'nil', it defaults to today's day."
(let ((actual-day-number (cond
((eq day-number nil) (string-to-number (format-time-string "%u")))
((eq day-number 0) 7)
(t day-number))))
(when (and (eq day-number (string-to-number (format-time-string "%u")))
(not (check-todays-package-upgrade-p t)))
(message "Calling")
(when (call-interactively 'package-upgrade-all)
(message "Called")
(check-todays-package-upgrade-p nil)))))
(provide 'package-manip)
;;; package-manip.el ends here

View File

@ -0,0 +1,19 @@
(defun get-number-at-point ()
(interactive)
(skip-chars-backward "0123456789.-")
(or (looking-at "[0123456789.-]+")
(error "No number at point"))
(string-to-number (match-string 0)))
(defun round-number-at-point-to-decimals (decimal-count)
(interactive "NDecimal count: ")
(let ((mult (expt 10 decimal-count)))
(replace-match (number-to-string
(/
(fround
(*
mult
(get-number-at-point)))
mult)))))
(global-set-key (kbd "C-c r") 'round-number-at-point-to-decimals)

7
lisp/text-manip.el Normal file
View File

@ -0,0 +1,7 @@
(defun org-space-key (&optional arg)
"Insert two spaces after a period."
(interactive "p")
(when (looking-back "[.!?…]")
(call-interactively 'self-insert-command arg))
(call-interactively 'self-insert-command arg))

View File

@ -0,0 +1,27 @@
(defun toggle-window-split ()
(interactive)
(if (= (count-windows) 2)
(let* ((this-win-buffer (window-buffer))
(next-win-buffer (window-buffer (next-window)))
(this-win-edges (window-edges (selected-window)))
(next-win-edges (window-edges (next-window)))
(this-win-2nd (not (and (<= (car this-win-edges)
(car next-win-edges))
(<= (cadr this-win-edges)
(cadr next-win-edges)))))
(splitter
(if (= (car this-win-edges)
(car (window-edges (next-window))))
'split-window-horizontally
'split-window-vertically)))
(delete-other-windows)
(let ((first-win (selected-window)))
(funcall splitter)
(if this-win-2nd (other-window 1))
(set-window-buffer (selected-window) this-win-buffer)
(set-window-buffer (next-window) next-win-buffer)
(select-window first-win)
(if this-win-2nd (other-window 1))))
(error "This works only for two windows!")))
(global-set-key (kbd "C-x |") 'toggle-window-split)

11
lisp/transpose-windows.el Normal file
View File

@ -0,0 +1,11 @@
(defun transpose-windows (arg)
"Transpose the buffers shown in two windows."
(interactive "p")
(let ((selector (if (>= arg 0) 'next-window 'previous-window)))
(while (/= arg 0)
(let ((this-win (window-buffer))
(next-win (window-buffer (funcall selector))))
(set-window-buffer (selected-window) next-win)
(set-window-buffer (funcall selector) this-win)
(select-window (funcall selector)))
(setq arg (if (plusp arg) (1- arg) (1+ arg))))))

View File

@ -40,7 +40,7 @@
;;; user-documents-directory ~/Documents ;;; user-documents-directory ~/Documents
;;; ;;;
;;; Some convenience functions are defined to locate files in these ;;; Some convenience functions are defined to locate files in these
;;; directories and to add user Lisp to load-path. ;;; directories and to add user lisp to load-path.
;;; ;;;
;;; Some advantages are: ;;; Some advantages are:
;;; ;;;
@ -114,28 +114,28 @@
;;; Code: ;;; Code:
(eval-when-compile (eval-when-compile
(require 'cl-lib)) (require 'cl))
;;; Directories definition. ;;; Directories definition.
(defvar user-emacs-config-directory nil (defvar user-emacs-config-directory nil
"The directory where the Emacs user configuration files are stored at.") "The directory where the emacs user configuration files are stored at.")
(defvar user-emacs-data-directory nil (defvar user-emacs-data-directory nil
"The directory where the Emacs user data and Lisp files are stored at. "The directory where the emacs user data and lisp files are stored at.
\\[user-emacs-directory] is set to this directory.") \\[user-emacs-directory] is set to this directory.")
(defvar user-emacs-cache-directory nil (defvar user-emacs-cache-directory nil
"The directory where the Emacs user expendable files are stored at. "The directory where the emacs user expendable files are stored at.
Files stored here should not be missed when deleted, apart a Files stored here should not be missed when deleted, apart a
temporary loss in speed.") temporary loss in speed.")
(defvar user-emacs-lisp-directory nil (defvar user-emacs-lisp-directory nil
"The directory where the user Lisp packages are stored at. "The directory where the user lisp packages are stored at.
This directory is added to \\[load-path].") This directory is added to \\[load-path].")
@ -146,73 +146,72 @@ This directory is added to \\[load-path].")
(defun xdg-user-dir (dirname) (defun xdg-user-dir (dirname)
"Given DIRNAME, run 'xdg-user-dir DIRNAME' and return the result in a string. "Given NAME, run 'xdg-user-dir NAME' and return the result in a string.
If the command fails, return NIL." If the command fails, return NIL."
(let ((command (concat "xdg-user-dir " dirname))) (let ((command (concat "xdg-user-dir " dirname)))
(if (zerop (shell-command command)) (if (zerop (shell-command command))
(substring (shell-command-to-string command) 0 -1) (substring (shell-command-to-string command) 0 -1)
nil))) nil)))
(defun locate-user-file (filename &optional type) (defun locate-user-file (filename &optional type)
"Given a file FILENAME, locate it in the user files. "Given a file, locate it in the user files.
If TYPE is NIL or 'data, the file will be located in user-emacs-data-directory. If TYPE is NIL or 'data, the file will be located in user-emacs-data-directory.
If `config', it will be located in user-emacs-config-directory. If 'config, it will be located in user-emacs-config-directory.
If `cache', it will be located in user-emacs-cache-directory. If 'cache, it will be located in user-emacs-cache-directory.
If `lisp', it will be located in user-emacs-lisp-directory. If 'lisp, it will be located in user-emacs-lisp-directory.
If `documents', it will be located in user-documents-directory. If 'documents, it will be located in user-documents-directory.
If the category is wrong, an error will be signaled." If the category is wrong, an error will be signaled.
"
(expand-file-name filename (expand-file-name filename
(cond (case type
((or (not type) (eq type 'data)) user-emacs-data-directory) ((nil data) user-emacs-data-directory)
((eq type 'config) user-emacs-config-directory) ('config user-emacs-config-directory)
((eq type 'lisp) user-emacs-lisp-directory) ('lisp user-emacs-lisp-directory)
((eq type 'cache) user-emacs-cache-directory) ('cache user-emacs-cache-directory)
((eq type 'documents) user-documents-directory) ('documents user-documents-directory)
(t (error "The category %s is not valid" type))))) (t (error "The category %s is not valid" type)))))
(defun locate-user-config-file (filename) (defun locate-user-config-file (filename)
"Given a file FILENAME, locate it in `user-emacs-config-directory`." "Given a file, locate it in `user-emacs-config-directory`."
(locate-user-file filename 'config)) (locate-user-file filename 'config))
(defun locate-user-lisp (filename) (defun locate-user-lisp (filename)
"Given a file FILENAME, locate it in `user-emacs-lisp-directory`." "Given a file, locate it in `user-emacs-lisp-directory`."
(locate-user-file filename 'lisp)) (locate-user-file filename 'lisp))
(defun add-to-path (directory &optional append) (defun add-to-path (directory &optional append)
"Given DIRECTORY, it it exists and is a directory, add it to `load-path`. "Given DIRECTORY, it it exists and is indeed a directory, add
it to `load-path`."
APPEND is passed verbatim to `add-to-list'."
(interactive "D") (interactive "D")
(if (file-directory-p directory) (if (file-directory-p directory)
(add-to-list 'load-path directory append) (add-to-list 'load-path directory append)
(error "The directory \"%s\" does not exist or isn't a directory" directory))) (error "The directory \"%s\" does not exist or isn't a directory." directory)))
(defun add-user-lisp-to-path (directory &optional append) (defun add-user-lisp-to-path (directory &optional append)
"Given DIRECTORY, if it exists and is a directory, add it to `load-path`. "Given DIRECTORY, it it exists and is indeed a directory, add
it to `load-path`."
APPEND is passed directly to `add-to-path'."
(interactive "D") (interactive "D")
(add-to-path (locate-user-lisp directory) append)) (add-to-path (locate-user-lisp directory) append))
;; Set the default variables if they have no name. ;; Set the default variables if they have no name.
(cl-macrolet ((setq-if-null (variable value) (macrolet ((setq-if-null (variable value)
`(if (null ,variable) `(if (null ,variable)
(setf ,variable ,value))) (setf ,variable ,value)))
(getdir (variable fallback) (getdir (variable fallback)
`(expand-file-name "emacs/" (or (getenv ,variable) ,fallback)))) `(expand-file-name "emacs/" (or (getenv ,variable) ,fallback))))
(setq-if-null user-emacs-config-directory (getdir "XDG_CONFIG_HOME" "~/.config/")) (setq-if-null user-emacs-config-directory (getdir "XDG_CONFIG_HOME" "~/.config/"))
(setq-if-null user-emacs-data-directory (getdir "XDG_DATA_HOME" "~/.local/share/")) (setq-if-null user-emacs-data-directory (getdir "XDG_DATA_HOME" "~/.local/share/"))
(setq-if-null user-emacs-cache-directory (getdir "XDG_CACHE_HOME" "~/.cache/")) (setq-if-null user-emacs-cache-directory (getdir "XDG_CACHE_HOME" "~/.cache/"))
@ -220,10 +219,12 @@ APPEND is passed directly to `add-to-path'."
(setq-if-null user-documents-directory (or (xdg-user-dir "DOCUMENTS") "~/Documents"))) (setq-if-null user-documents-directory (or (xdg-user-dir "DOCUMENTS") "~/Documents")))
;; Set the user-emacs-directory to user-emacs-data-directory.
;(setf user-emacs-directory user-emacs-data-directory)
;; Add the user lisp directory to path. ;; Add the user lisp directory to path.
(add-to-list 'load-path user-emacs-lisp-directory) (add-to-list 'load-path user-emacs-lisp-directory)
(provide 'xdg-paths) (provide 'xdg-paths)
;;; xdg-paths.el ends here

19
lisp/zim.el Normal file
View File

@ -0,0 +1,19 @@
(defun zim-timestamp ()
(with-temp-buffer
(insert (format-time-string "%Y-%m-%dT%H:%M:%S%z"))
(forward-char -2)
(insert ":")
(buffer-string)))
(defun insert-zim-timestamp ()
(interactive)
(insert (zim-timestamp)))
(defun insert-zim-header ()
(interactive)
(save-excursion
(goto-char (point-min))
(insert
(concat "Content-Type: text/x-zim-wiki\n"
"Wiki-Format: zim 0.4\n"
"Creation-Date: " (zim-timestamp) "\n\n"))))

View File

@ -1,11 +0,0 @@
# -*- mode: snippet -*-
# name: GObject H boilerplate
# key: gobh
# --
# include <glib-object.h>
G_BEGIN_DECLS
$0
G_END_DECLS

View File

@ -1,10 +0,0 @@
# -*- mode: snippet -*-
# name: Protect with ifdef
# key: defprot
# --
#ifndef ${1:name}
# define $1
$0
#endif /* $1 */

View File

@ -1,19 +0,0 @@
# -*- mode: snippet -*-
# name: agpl-header
# key: agpl
# --
# ${1:project_name}
# Copyright (C) ${2:year} ${3:author_name}
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

View File

@ -1,10 +0,0 @@
# -*- mode: snippet -*-
# name: flask_sqlalchemy_model
# key: model
# --
class ${1:name}(db.Model):
__tablename__ = '${2:tablename}'
id = db.Column(db.Integer, primary_key=True)
$0

View File

@ -1,9 +0,0 @@
# -*- mode: snippet -*-
# name: New unittest
# key: testdef
# --
def test_${1:name}(self):
"""${2:docstring}
"""
$0self.assertTrue(False)

View File

@ -1,14 +0,0 @@
# -*- mode: snippet -*-
# name: Translatable Flask-SQLAlchemy model
# key: tmodel
# --
class ${1:name}(Translatable, db.Model):
__tablename__ = '${2:tablename}s'
id = db.Column(db.Integer, primary_key=True)
class $1Translation(translation_base($1)):
__tablename__ = '$2_translations'
$0

View File

@ -1,5 +0,0 @@
# -*- mode: snippet -*-
# name: Viewport Meta tag
# key: vp
# --
<meta name="viewport" content="width=device-width, initial-scale=1.0">