Let there be light
init commit
This commit is contained in:
commit
fa348ac8c1
63
.myemacs
Normal file
63
.myemacs
Normal file
@ -0,0 +1,63 @@
|
||||
;******************************************************************************;
|
||||
; ;
|
||||
; ::: :::::::: ;
|
||||
; .myemacs :+: :+: :+: ;
|
||||
; +:+ +:+ +:+ ;
|
||||
; By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ ;
|
||||
; +#+#+#+#+#+ +#+ ;
|
||||
; Created: 2018/07/09 18:59:05 by tmaze #+# #+# ;
|
||||
; Updated: 2019/03/01 11:41:00 by tmaze ### ########.fr ;
|
||||
; ;
|
||||
;******************************************************************************;
|
||||
|
||||
(load "package")
|
||||
(require 'package)
|
||||
(let* ((no-ssl (and (memq system-type '(windows-nt ms-dos))
|
||||
(not (gnutls-available-p))))
|
||||
(proto (if no-ssl "http" "https")))
|
||||
(when no-ssl
|
||||
(warn "\
|
||||
Your version of Emacs does not support SSL connections,
|
||||
which is unsafe because it allows man-in-the-middle attacks.
|
||||
There are two things you can do about this warning:
|
||||
1. Install an Emacs version that does support SSL and be safe.
|
||||
2. Remove this warning from your init file so you won't see it again."))
|
||||
;; 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 (cons "gnu" (concat proto "://elpa.gnu.org/packages/")))))
|
||||
(package-initialize)
|
||||
|
||||
(setq package-initialize-at-startup nil)
|
||||
|
||||
(defvar tmaze/packages '(evil
|
||||
magit
|
||||
treemacs
|
||||
treemacs-magit
|
||||
jinja2-mode
|
||||
ox-twbs
|
||||
dakrone-theme)
|
||||
"Default packages")
|
||||
|
||||
(defun tmaze/packages-installed-p ()
|
||||
(cl-loop for pkg in tmaze/packages
|
||||
when (not (package-installed-p pkg)) do (cl-return nil)
|
||||
finally (cl-return t)))
|
||||
|
||||
(unless (tmaze/packages-installed-p)
|
||||
(message "%s" "Refreshing package database...")
|
||||
(package-refresh-contents)
|
||||
(dolist (pkg tmaze/packages)
|
||||
(when (not (package-installed-p pkg))
|
||||
(package-install pkg))))
|
||||
|
||||
(load-theme 'dakrone t)
|
||||
|
||||
(global-set-key (kbd "C-x g") 'magit-status)
|
||||
|
||||
(global-git-commit-mode)
|
||||
|
||||
(line-number-mode 1)
|
||||
(column-number-mode 1)
|
111
.zshrc
Normal file
111
.zshrc
Normal file
@ -0,0 +1,111 @@
|
||||
# If you come from bash you might have to change your $PATH.
|
||||
# export PATH=$HOME/bin:/usr/local/bin:$PATH
|
||||
|
||||
# Path to your oh-my-zsh installation.
|
||||
export ZSH=/Users/tmaze/.oh-my-zsh
|
||||
|
||||
# Set name of the theme to load. Optionally, if you set this to "random"
|
||||
# it'll load a random theme each time that oh-my-zsh is loaded.
|
||||
# See https://github.com/robbyrussell/oh-my-zsh/wiki/Themes
|
||||
ZSH_THEME="robbyrussell"
|
||||
|
||||
# Set list of themes to load
|
||||
# Setting this variable when ZSH_THEME=random
|
||||
# cause zsh load theme from this variable instead of
|
||||
# looking in ~/.oh-my-zsh/themes/
|
||||
# An empty array have no effect
|
||||
# ZSH_THEME_RANDOM_CANDIDATES=( "robbyrussell" "agnoster" )
|
||||
|
||||
# Uncomment the following line to use case-sensitive completion.
|
||||
# CASE_SENSITIVE="true"
|
||||
|
||||
# Uncomment the following line to use hyphen-insensitive completion. Case
|
||||
# sensitive completion must be off. _ and - will be interchangeable.
|
||||
# HYPHEN_INSENSITIVE="true"
|
||||
|
||||
# Uncomment the following line to disable bi-weekly auto-update checks.
|
||||
# DISABLE_AUTO_UPDATE="true"
|
||||
|
||||
# Uncomment the following line to change how often to auto-update (in days).
|
||||
# export UPDATE_ZSH_DAYS=13
|
||||
|
||||
# Uncomment the following line to disable colors in ls.
|
||||
# DISABLE_LS_COLORS="true"
|
||||
|
||||
# Uncomment the following line to disable auto-setting terminal title.
|
||||
# DISABLE_AUTO_TITLE="true"
|
||||
|
||||
# Uncomment the following line to enable command auto-correction.
|
||||
# ENABLE_CORRECTION="true"
|
||||
|
||||
# Uncomment the following line to display red dots whilst waiting for completion.
|
||||
# COMPLETION_WAITING_DOTS="true"
|
||||
|
||||
# Uncomment the following line if you want to disable marking untracked files
|
||||
# under VCS as dirty. This makes repository status check for large repositories
|
||||
# much, much faster.
|
||||
# DISABLE_UNTRACKED_FILES_DIRTY="true"
|
||||
|
||||
# Uncomment the following line if you want to change the command execution time
|
||||
# stamp shown in the history command output.
|
||||
# The optional three formats: "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd"
|
||||
# HIST_STAMPS="mm/dd/yyyy"
|
||||
|
||||
# Would you like to use another custom folder than $ZSH/custom?
|
||||
# ZSH_CUSTOM=/path/to/new-custom-folder
|
||||
|
||||
# Which plugins would you like to load? (plugins can be found in ~/.oh-my-zsh/plugins/*)
|
||||
# Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/
|
||||
# Example format: plugins=(rails git textmate ruby lighthouse)
|
||||
# Add wisely, as too many plugins slow down shell startup.
|
||||
plugins=(
|
||||
git
|
||||
osx
|
||||
)
|
||||
|
||||
source $ZSH/oh-my-zsh.sh
|
||||
|
||||
# User configuration
|
||||
|
||||
# export MANPATH="/usr/local/man:$MANPATH"
|
||||
|
||||
# You may need to manually set your language environment
|
||||
# export LANG=en_US.UTF-8
|
||||
|
||||
# Preferred editor for local and remote sessions
|
||||
# if [[ -n $SSH_CONNECTION ]]; then
|
||||
# export EDITOR='vim'
|
||||
# else
|
||||
# export EDITOR='mvim'
|
||||
# fi
|
||||
|
||||
# Compilation flags
|
||||
# export ARCHFLAGS="-arch x86_64"
|
||||
|
||||
# ssh
|
||||
# export SSH_KEY_PATH="~/.ssh/rsa_id"
|
||||
|
||||
# Set personal aliases, overriding those provided by oh-my-zsh libs,
|
||||
# plugins, and themes. Aliases can be placed here, though oh-my-zsh
|
||||
# users are encouraged to define aliases within the ZSH_CUSTOM folder.
|
||||
# For a full list of active aliases, run `alias`.
|
||||
#
|
||||
# Example aliases
|
||||
# alias zshconfig="mate ~/.zshrc"
|
||||
# alias ohmyzsh="mate ~/.oh-my-zsh"
|
||||
|
||||
export MAIL=tmaze@student.42.fr
|
||||
|
||||
alias clean='find . \( -name "#*#" -or -name "*~" \) -print -delete'
|
||||
alias resource='source $HOME/.zshrc'
|
||||
alias norm-err='norminette | grep -B 1 "Error"'
|
||||
alias emacs-26.1='~/.brew/bin/emacs'
|
||||
alias leaks-loop='~/leaks-loop.sh'
|
||||
|
||||
|
||||
# Load Homebrew config script
|
||||
source $HOME/.brewconfig.zsh
|
||||
export VAGRANT_HOME=/Volumes/Storage/goinfre/tmaze/vagrant
|
||||
|
||||
# Load goto
|
||||
source $HOME/gotoFonction/gotoFct.sh
|
43
Makefile
Normal file
43
Makefile
Normal file
@ -0,0 +1,43 @@
|
||||
#******************************************************************************#
|
||||
# #
|
||||
# ::: :::::::: #
|
||||
# Makefile :+: :+: :+: #
|
||||
# +:+ +:+ +:+ #
|
||||
# By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2019/03/01 10:47:54 by tmaze #+# #+# #
|
||||
# Updated: 2019/03/01 11:24:32 by tmaze ### ########.fr #
|
||||
# #
|
||||
#******************************************************************************#
|
||||
|
||||
.PHONY = all clean fclean re
|
||||
|
||||
EMACSF = comments.el \
|
||||
dockerfile-mode.el \
|
||||
header.el \
|
||||
init.el \
|
||||
list.el \
|
||||
string.el \
|
||||
yaml-mode.el \
|
||||
.myemacs
|
||||
|
||||
all: emacs zsh
|
||||
|
||||
~/.emacs.d:
|
||||
mkdir ~/.emacs.d
|
||||
|
||||
emacs: $(EMACSF) ~/.emacs.d
|
||||
cp ./*.el ~/.emacs.d
|
||||
cp ./.myemacs ~/.
|
||||
|
||||
zsh: .zshrc
|
||||
cp ./.zshrc ~/.
|
||||
|
||||
clean:
|
||||
rm -f ~/.emacs.d/*
|
||||
rm -f ~/.zshrc
|
||||
|
||||
fclean: clean
|
||||
rm -f ~/.emacs.d/
|
||||
|
||||
re: fclean all
|
210
comments.el
Normal file
210
comments.el
Normal file
@ -0,0 +1,210 @@
|
||||
;******************************************************************************;
|
||||
; ;
|
||||
; comments.el for automatic comments generation ;
|
||||
; Created on : Fri Oct 21 17:36:51 2011 ;
|
||||
; Made by : David "Thor" GIRON <thor@epitech.net> ;
|
||||
; ;
|
||||
;******************************************************************************;
|
||||
|
||||
|
||||
|
||||
(require 'string)
|
||||
|
||||
|
||||
(set 'line-std-width 80)
|
||||
|
||||
|
||||
|
||||
;******************************************************************************;
|
||||
; ;
|
||||
; Comments tokens primitives ;
|
||||
; ;
|
||||
;******************************************************************************;
|
||||
|
||||
(defun comments-start-token ()
|
||||
"Returns the comment start string of the current mode"
|
||||
comment-start
|
||||
)
|
||||
|
||||
(defun comments-end-token ()
|
||||
"Returns the comment end string of the current mode if any, or a
|
||||
reversed string of the comment start otherwise."
|
||||
(if (/= (length comment-end) 0)
|
||||
comment-end
|
||||
(string-reverse comment-start)
|
||||
)
|
||||
)
|
||||
|
||||
(defun comments-start-token-length ()
|
||||
"Returns the length of the comment start string of the current mode."
|
||||
(string-length (comments-start-token))
|
||||
)
|
||||
|
||||
(defun comments-end-token-length ()
|
||||
"Returns the length of the comment end string of the current mode."
|
||||
(string-length (comments-end-token))
|
||||
)
|
||||
|
||||
(defun comments-tokens-length ()
|
||||
"Returns the total length of the comments tokens."
|
||||
(+ (comments-start-token-length) (comments-end-token-length))
|
||||
)
|
||||
|
||||
|
||||
|
||||
;******************************************************************************;
|
||||
; ;
|
||||
; Padding primitives ;
|
||||
; ;
|
||||
;******************************************************************************;
|
||||
|
||||
(defun comments-compute-left-padding (s-text i-offset)
|
||||
"Returns a pair (lpad . rpad) for a left padded comments line."
|
||||
(let* ((i-len (+ (string-length s-text) i-offset))
|
||||
(i-rpad (- line-std-width i-len (comments-tokens-length))))
|
||||
(cons 0 i-rpad)
|
||||
)
|
||||
)
|
||||
|
||||
(defun comments-compute-center-padding (s-text)
|
||||
"Returns a pair (lpad . rpad) for a center padded comments line."
|
||||
(let* ((i-len (string-length s-text))
|
||||
(i-tpad (- line-std-width i-len (comments-tokens-length))))
|
||||
(if (= (% i-tpad 2) 0)
|
||||
(cons (/ i-tpad 2) (/ i-tpad 2))
|
||||
(cons (/ i-tpad 2) (+ (/ i-tpad 2) 1))
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
(defun comments-compute-right-padding (s-text i-offset)
|
||||
"Returns a pair (lpad . rpad) for a right padded comments line."
|
||||
(let* ((i-len (+ (string-length s-text) i-offset))
|
||||
(i-lpad (- line-std-width i-len (comments-tokens-length))))
|
||||
(cons i-lpad 0)
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
|
||||
;******************************************************************************;
|
||||
; ;
|
||||
; Contents producers ;
|
||||
; ;
|
||||
;******************************************************************************;
|
||||
|
||||
(defun comments-make-padded-line (s-text i-lpad i-rpad)
|
||||
"Returns a comments string padded on line-std-width columns."
|
||||
(concat (comments-start-token)
|
||||
(make-string i-lpad ? )
|
||||
s-text
|
||||
(make-string i-rpad ? )
|
||||
(comments-end-token)
|
||||
"\n"
|
||||
)
|
||||
)
|
||||
|
||||
(defun comments-make-left-padded-line (s-text i-offset)
|
||||
"Returns a comments string left padded on line-std-width columns."
|
||||
(let* ((pad (comments-compute-left-padding s-text i-offset)))
|
||||
(comments-make-padded-line
|
||||
(concat (make-string i-offset ? ) s-text)
|
||||
(car pad)
|
||||
(cdr pad))
|
||||
)
|
||||
)
|
||||
|
||||
(defun comments-make-center-padded-line (s-text)
|
||||
"Returns a comments string center padded on line-std-width columns."
|
||||
(let* ((pad (comments-compute-center-padding s-text)))
|
||||
(comments-make-padded-line s-text (car pad) (cdr pad))
|
||||
)
|
||||
)
|
||||
|
||||
(defun comments-make-right-padded-line (s-text i-offset)
|
||||
"Returns a comments string right padded on line-std-width columns."
|
||||
(let* ((pad (comments-compute-right-padding s-text i-offset)))
|
||||
(comments-make-padded-line
|
||||
(concat s-text (make-string i-offset ? ))
|
||||
(car pad)
|
||||
(cdr pad))
|
||||
)
|
||||
)
|
||||
|
||||
(defun comments-make-bar ()
|
||||
"Returns as a string a full comments bar of line-std-width."
|
||||
(concat (comments-start-token)
|
||||
(make-string (- line-std-width (comments-tokens-length)) ?*)
|
||||
(comments-end-token) "\n")
|
||||
)
|
||||
|
||||
(defun comments-make-empty-line ()
|
||||
"Returns as a string an empty comments line of line-std-width."
|
||||
(concat (comments-start-token)
|
||||
(make-string (- line-std-width (comments-tokens-length)) ? )
|
||||
(comments-end-token) "\n")
|
||||
)
|
||||
|
||||
|
||||
|
||||
;******************************************************************************;
|
||||
; ;
|
||||
; Interactives functions ;
|
||||
; ;
|
||||
;******************************************************************************;
|
||||
|
||||
(defun comments-insert-left-padded-line (s-text i-offset)
|
||||
"Inserts in the current buffer a comments string left padded on
|
||||
line-std-width columns."
|
||||
(interactive)
|
||||
(insert (comments-make-left-padded-line s-text i-offset))
|
||||
)
|
||||
|
||||
(defun comments-insert-center-padded-line (s-text)
|
||||
"Inserts in the current buffer a comments string center padded on
|
||||
line-std-width columns."
|
||||
(interactive)
|
||||
(insert (comments-make-center-padded-line s-text))
|
||||
)
|
||||
|
||||
(defun comments-insert-right-padded-line (s-text i-offset)
|
||||
"Inserts in the current buffer a comments string right padded on
|
||||
line-std-width columns."
|
||||
(interactive)
|
||||
(insert (comments-make-right-padded-line s-text i-offset))
|
||||
)
|
||||
|
||||
(defun comments-insert-bar ()
|
||||
"Inserts in the current buffer a line-std-width comments bar."
|
||||
(interactive)
|
||||
(insert (comments-make-bar))
|
||||
)
|
||||
|
||||
(defun comments-insert-empty-line ()
|
||||
"Inserts in the current buffer a line-std-width comments empty line."
|
||||
(interactive)
|
||||
(insert (comments-make-empty-line))
|
||||
)
|
||||
|
||||
(defun comments-insert-box (s-text)
|
||||
"Inserts a box of std-width with center padded 's-text'."
|
||||
(interactive "sBox content: ")
|
||||
(comments-insert-bar)
|
||||
(comments-insert-empty-line)
|
||||
(comments-insert-center-padded-line s-text)
|
||||
(comments-insert-empty-line)
|
||||
(comments-insert-bar)
|
||||
)
|
||||
|
||||
(defun comments-insert-small-box (s-text)
|
||||
"Inserts a small box of std-width with center padded 's-text'."
|
||||
(interactive "sBox content: ")
|
||||
(comments-insert-bar)
|
||||
(comments-insert-center-padded-line s-text)
|
||||
(comments-insert-bar)
|
||||
)
|
||||
|
||||
|
||||
|
||||
;******************************************************************************;
|
||||
(provide 'comments)
|
186
dockerfile-mode.el
Normal file
186
dockerfile-mode.el
Normal file
@ -0,0 +1,186 @@
|
||||
;;; dockerfile-mode.el --- Major mode for editing Docker's Dockerfiles -*- lexical-binding: t -*-
|
||||
|
||||
;; Copyright (c) 2013 Spotify AB
|
||||
;; Package-Requires: ((emacs "24") (s "1.12"))
|
||||
;; Homepage: https://github.com/spotify/dockerfile-mode
|
||||
;;
|
||||
;; Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
;; use this file except in compliance with the License. You may obtain a copy of
|
||||
;; the License at
|
||||
;;
|
||||
;; http://www.apache.org/licenses/LICENSE-2.0
|
||||
;;
|
||||
;; Unless required by applicable law or agreed to in writing, software
|
||||
;; distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
;; WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
;; License for the specific language governing permissions and limitations under
|
||||
;; the License.
|
||||
|
||||
;;; Commentary:
|
||||
|
||||
;; Provides a major mode `dockerfile-mode' for use with the standard
|
||||
;; `Dockerfile' file format. Additional convenience functions allow
|
||||
;; images to be built easily.
|
||||
|
||||
;;; Code:
|
||||
|
||||
(require 'sh-script)
|
||||
(require 'rx)
|
||||
(require 's)
|
||||
|
||||
|
||||
(declare-function cygwin-convert-file-name-to-windows "cygw32.c" (file &optional absolute-p))
|
||||
|
||||
(defgroup dockerfile nil
|
||||
"dockerfile code editing commands for Emacs."
|
||||
:link '(custom-group-link :tag "Font Lock Faces group" font-lock-faces)
|
||||
:prefix "dockerfile-"
|
||||
:group 'languages)
|
||||
|
||||
(defcustom dockerfile-mode-hook nil
|
||||
"*Hook called by `dockerfile-mode'."
|
||||
:type 'hook
|
||||
:group 'dockerfile)
|
||||
|
||||
(defcustom dockerfile-use-sudo nil
|
||||
"Runs docker builder command with sudo."
|
||||
:type 'boolean
|
||||
:group 'dockerfile)
|
||||
|
||||
(defcustom dockerfile-build-args nil
|
||||
"List of --build-arg to pass to docker build.
|
||||
Each element of the list will be passed as a separate
|
||||
--build-arg to the docker build command."
|
||||
:type '(repeat string)
|
||||
:group 'dockerfile)
|
||||
|
||||
(defface dockerfile-image-name
|
||||
'((t (:inherit (font-lock-type-face bold))))
|
||||
"Face to highlight the base image name after FROM instruction.")
|
||||
|
||||
(defface dockerfile-image-alias
|
||||
'((t (:inherit (font-lock-constant-face bold))))
|
||||
"Face to highlight the base image alias inf FROM ... AS <alias> construct.")
|
||||
|
||||
(defvar dockerfile-font-lock-keywords
|
||||
`(,(cons (rx (or line-start "onbuild ")
|
||||
(group (or "from" "maintainer" "run" "cmd" "expose" "env" "arg"
|
||||
"add" "copy" "entrypoint" "volume" "user" "workdir" "onbuild"
|
||||
"label" "stopsignal" "shell" "healthcheck"))
|
||||
word-boundary)
|
||||
font-lock-keyword-face)
|
||||
(,(rx "FROM " (group (+? nonl)) (or " " eol) (? "as " (group (1+ nonl))))
|
||||
(1 'dockerfile-image-name)
|
||||
(2 'dockerfile-image-alias nil t))
|
||||
,@(sh-font-lock-keywords)
|
||||
,@(sh-font-lock-keywords-2)
|
||||
,@(sh-font-lock-keywords-1))
|
||||
"Default `font-lock-keywords' for `dockerfile mode'.")
|
||||
|
||||
(defvar dockerfile-mode-map
|
||||
(let ((map (make-sparse-keymap))
|
||||
(menu-map (make-sparse-keymap)))
|
||||
(define-key map "\C-c\C-b" 'dockerfile-build-buffer)
|
||||
(define-key map "\C-c\M-b" 'dockerfile-build-no-cache-buffer)
|
||||
(define-key map "\C-c\C-z" 'dockerfile-test-function)
|
||||
(define-key map "\C-c\C-c" 'comment-region)
|
||||
(define-key map [menu-bar dockerfile-mode] (cons "Dockerfile" menu-map))
|
||||
(define-key menu-map [dfc]
|
||||
'(menu-item "Comment Region" comment-region
|
||||
:help "Comment Region"))
|
||||
(define-key menu-map [dfb]
|
||||
'(menu-item "Build" dockerfile-build-buffer
|
||||
:help "Send the Dockerfile to docker build"))
|
||||
(define-key menu-map [dfb]
|
||||
'(menu-item "Build without cache" dockerfile-build-no-cache-buffer
|
||||
:help "Send the Dockerfile to docker build without cache"))
|
||||
map))
|
||||
|
||||
(defvar dockerfile-mode-syntax-table
|
||||
(let ((table (make-syntax-table)))
|
||||
(modify-syntax-entry ?# "<" table)
|
||||
(modify-syntax-entry ?\n ">" table)
|
||||
(modify-syntax-entry ?' "\"" table)
|
||||
(modify-syntax-entry ?= "." table)
|
||||
table)
|
||||
"Syntax table for `dockerfile-mode'.")
|
||||
|
||||
(define-abbrev-table 'dockerfile-mode-abbrev-table nil
|
||||
"Abbrev table used while in `dockerfile-mode'.")
|
||||
|
||||
(unless dockerfile-mode-abbrev-table
|
||||
(define-abbrev-table 'dockerfile-mode-abbrev-table ()))
|
||||
|
||||
(defun dockerfile-build-arg-string ()
|
||||
"Create a --build-arg string for each element in `dockerfile-build-args'."
|
||||
(mapconcat (lambda (arg) (concat "--build-arg " (shell-quote-argument arg)))
|
||||
dockerfile-build-args " "))
|
||||
|
||||
(defun dockerfile-standard-filename (file)
|
||||
"Convert the FILE name to OS standard.
|
||||
If in Cygwin environment, uses Cygwin specific function to convert the
|
||||
file name. Otherwise, uses Emacs' standard conversion function."
|
||||
(if (fboundp 'cygwin-convert-file-name-to-windows)
|
||||
(s-replace "\\" "\\\\" (cygwin-convert-file-name-to-windows file))
|
||||
(convert-standard-filename file)))
|
||||
|
||||
(defvar dockerfile-image-name nil
|
||||
"Name of the dockerfile currently being used.
|
||||
This can be set in file or directory-local variables.")
|
||||
(define-obsolete-variable-alias 'docker-image-name 'dockerfile-image-name)
|
||||
|
||||
(defvar dockerfile-image-name-history nil
|
||||
"History of image names read by `dockerfile-read-image-name'.")
|
||||
|
||||
(defun dockerfile-read-image-name ()
|
||||
"Read a docker image name."
|
||||
(read-string "Image name: " dockerfile-image-name 'dockerfile-image-name-history))
|
||||
|
||||
|
||||
;;;###autoload
|
||||
(defun dockerfile-build-buffer (image-name &optional no-cache)
|
||||
"Build an image called IMAGE-NAME based upon the buffer.
|
||||
If prefix arg NO-CACHE is set, don't cache the image."
|
||||
(interactive (list (dockerfile-read-image-name) prefix-arg))
|
||||
(save-buffer)
|
||||
(if (stringp image-name)
|
||||
(compilation-start
|
||||
(format
|
||||
"%sdocker build %s -t %s %s -f %s %s"
|
||||
(if dockerfile-use-sudo "sudo " "")
|
||||
(if no-cache "--no-cache" "")
|
||||
(shell-quote-argument image-name)
|
||||
(dockerfile-build-arg-string)
|
||||
(shell-quote-argument (dockerfile-standard-filename (buffer-file-name)))
|
||||
(shell-quote-argument (dockerfile-standard-filename default-directory)))
|
||||
nil
|
||||
(lambda (_) (format "*docker-build-output: %s *" image-name)))
|
||||
(print "dockerfile-image-name must be a string, consider surrounding it with double quotes")))
|
||||
|
||||
;;;###autoload
|
||||
(defun dockerfile-build-no-cache-buffer (image-name)
|
||||
"Build an image called IMAGE-NAME based upon the buffer without cache."
|
||||
(interactive (list (dockerfile-read-image-name)))
|
||||
(dockerfile-build-buffer image-name t))
|
||||
|
||||
;;;###autoload
|
||||
(define-derived-mode dockerfile-mode prog-mode "Dockerfile"
|
||||
"A major mode to edit Dockerfiles.
|
||||
\\{dockerfile-mode-map}
|
||||
"
|
||||
(set-syntax-table dockerfile-mode-syntax-table)
|
||||
(set (make-local-variable 'require-final-newline) mode-require-final-newline)
|
||||
(set (make-local-variable 'comment-start) "#")
|
||||
(set (make-local-variable 'comment-end) "")
|
||||
(set (make-local-variable 'comment-start-skip) "#+ *")
|
||||
(set (make-local-variable 'parse-sexp-ignore-comments) t)
|
||||
(set (make-local-variable 'font-lock-defaults)
|
||||
'(dockerfile-font-lock-keywords nil t))
|
||||
(setq local-abbrev-table dockerfile-mode-abbrev-table))
|
||||
|
||||
;;;###autoload
|
||||
(add-to-list 'auto-mode-alist '("Dockerfile\\(?:\\..*\\)?\\'" . dockerfile-mode))
|
||||
|
||||
(provide 'dockerfile-mode)
|
||||
|
||||
;;; dockerfile-mode.el ends here
|
265
header.el
Normal file
265
header.el
Normal file
@ -0,0 +1,265 @@
|
||||
;*******************************************************************************;
|
||||
; ;
|
||||
; 42_header.el for 42 Emacs header ;
|
||||
; Created on : Tue Jun 18 10:46:22 2013 ;
|
||||
; Made by : David "Thor" GIRON <thor@42.fr> ;
|
||||
; ;
|
||||
;*******************************************************************************;
|
||||
|
||||
|
||||
|
||||
(require 'string)
|
||||
(require 'list)
|
||||
(require 'comments)
|
||||
|
||||
|
||||
|
||||
;******************************************************************************;
|
||||
; ;
|
||||
; ::: :::::::: ;
|
||||
; filename_____________________________.ext :+: :+: :+: ;
|
||||
; +:+ +:+ +:+ ;
|
||||
; By: login____ <mail_______@student.42.fr> +#+ +:+ +#+ ;
|
||||
; +#+#+#+#+#+ +#+ ;
|
||||
; Created: yyyy/mm/dd 15:27:11 by login____ #+# #+# ;
|
||||
; Updated: 2018/06/17 04:23:01 by suvitiel ### ########.fr ;
|
||||
; ;
|
||||
;******************************************************************************;
|
||||
|
||||
|
||||
|
||||
(global-set-key (kbd "C-c C-h") 'header-insert)
|
||||
(setq write-file-hooks (cons 'header-update write-file-hooks))
|
||||
|
||||
|
||||
(set 'user-login "tmaze")
|
||||
|
||||
|
||||
|
||||
|
||||
(set 'user-mail (let ((mail (getenv "MAIL")))
|
||||
(if (string= mail nil)
|
||||
"tmaze@student.42.fr"
|
||||
mail)
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
(set 'left-std-margin 5)
|
||||
(set 'right-std-margin 5)
|
||||
(set 'info-std-width 41)
|
||||
|
||||
|
||||
(set 'ft-1 " ::: ::::::::")
|
||||
(set 'ft-2 " :+: :+: :+:")
|
||||
(set 'ft-3 " +:+ +:+ +:+ ")
|
||||
(set 'ft-4 " +#+ +:+ +#+ ")
|
||||
(set 'ft-5 "+#+#+#+#+#+ +#+ ")
|
||||
(set 'ft-6 " #+# #+# ")
|
||||
(set 'ft-7 " ### ########.fr ")
|
||||
(set 'ft-std-width 25)
|
||||
|
||||
|
||||
|
||||
;*******************************************************************************;
|
||||
|
||||
|
||||
(defun header-chop-str (str n)
|
||||
(if (> (length str) n)
|
||||
(let* ((max (- n 3))
|
||||
(new (substring str 0 max)))
|
||||
(concat new "..."))
|
||||
str)
|
||||
)
|
||||
|
||||
(defun header-make-left-margin ()
|
||||
"Creates the header comments start token and left margin"
|
||||
(let ((fill (string-fill (- left-std-margin (comments-start-token-length)))))
|
||||
(concat (comments-start-token) fill))
|
||||
)
|
||||
|
||||
(defun header-make-right-margin ()
|
||||
"Creates the header right margin and comments end token"
|
||||
(let ((fill (string-fill (- right-std-margin (comments-end-token-length)))))
|
||||
(concat fill (comments-end-token)))
|
||||
)
|
||||
|
||||
(defun header-make-central-gap (left-chunk right-chunk)
|
||||
"Creates the gap between the left infos block and the right logo"
|
||||
(string-fill (- line-std-width
|
||||
(string-length left-chunk)
|
||||
(string-length right-chunk)))
|
||||
)
|
||||
|
||||
(defun header-make-file-name ()
|
||||
"Creates the 'file.ext' entry of the header."
|
||||
(let* ((filename (header-chop-str (file-name-nondirectory (buffer-file-name))
|
||||
info-std-width))
|
||||
(fill (string-fill (- info-std-width (string-length filename)))))
|
||||
(concat filename fill))
|
||||
)
|
||||
|
||||
(defun header-make-by ()
|
||||
"Creates the 'By: login <mail>' entry of the header."
|
||||
(let* ((mail-span (- info-std-width (+ (length user-login) 7)))
|
||||
(by (concat "By: " user-login " <" (header-chop-str user-mail mail-span) ">"))
|
||||
(fill (string-fill (- info-std-width (string-length by)))))
|
||||
(concat by fill))
|
||||
)
|
||||
|
||||
(defun header-make-creation-date ()
|
||||
"Creates the 'Created: yyyy/mm/dd hh:mm:ss' entry of the header.'"
|
||||
(concat "Created: " (format-time-string "%Y/%m/%d %T") " by " user-login)
|
||||
)
|
||||
|
||||
(defun header-make-update-date ()
|
||||
"Creates the 'Updated: yyyy/mm/dd hh:mm:ss' entry of the header.'"
|
||||
(concat "Updated: " (format-time-string "%Y/%m/%d %T") " by " user-login)
|
||||
)
|
||||
|
||||
|
||||
;*******************************************************************************;
|
||||
|
||||
|
||||
|
||||
(defun header-insert-line-01 ()
|
||||
"Line 1 of the header"
|
||||
(comments-insert-bar)
|
||||
)
|
||||
|
||||
(defun header-insert-line-02 ()
|
||||
"Line 2 of the header"
|
||||
(comments-insert-empty-line)
|
||||
)
|
||||
|
||||
(defun header-insert-line-03 ()
|
||||
"Line 3 of the header"
|
||||
(let* ((left-margin (header-make-left-margin))
|
||||
(right-margin (header-make-right-margin))
|
||||
(central-gap (header-make-central-gap
|
||||
left-margin
|
||||
(concat ft-1 right-margin))))
|
||||
(insert (concat left-margin central-gap ft-1 right-margin))
|
||||
)
|
||||
)
|
||||
|
||||
(defun header-insert-line-04 ()
|
||||
"Line 4 of the header"
|
||||
(let* ((left-margin (header-make-left-margin))
|
||||
(right-margin (header-make-right-margin))
|
||||
(filename (header-make-file-name))
|
||||
(central-gap (header-make-central-gap (concat left-margin filename)
|
||||
(concat ft-2 right-margin))))
|
||||
(insert (concat left-margin filename central-gap ft-2 right-margin))
|
||||
)
|
||||
)
|
||||
|
||||
(defun header-insert-line-05 ()
|
||||
"Line 5 of the header"
|
||||
(let* ((left-margin (header-make-left-margin))
|
||||
(right-margin (header-make-right-margin))
|
||||
(central-gap (header-make-central-gap left-margin
|
||||
(concat ft-3 right-margin))))
|
||||
(insert (concat left-margin central-gap ft-3 right-margin))
|
||||
)
|
||||
)
|
||||
|
||||
(defun header-insert-line-06 ()
|
||||
"Line 6 of the header"
|
||||
(let* ((left-margin (header-make-left-margin))
|
||||
(right-margin (header-make-right-margin))
|
||||
(by (header-make-by))
|
||||
(central-gap (header-make-central-gap (concat left-margin by)
|
||||
(concat ft-4 right-margin))))
|
||||
(insert (concat left-margin by central-gap ft-4 right-margin))
|
||||
)
|
||||
)
|
||||
|
||||
(defun header-insert-line-07 ()
|
||||
"Line 7 of the header"
|
||||
(let* ((left-margin (header-make-left-margin))
|
||||
(right-margin (header-make-right-margin))
|
||||
(central-gap (header-make-central-gap left-margin
|
||||
(concat ft-5 right-margin))))
|
||||
(insert (concat left-margin central-gap ft-5 right-margin))
|
||||
)
|
||||
)
|
||||
|
||||
(defun header-insert-line-08 ()
|
||||
"Line 8 of the header"
|
||||
(let* ((left-margin (header-make-left-margin))
|
||||
(right-margin (header-make-right-margin))
|
||||
(created (header-make-creation-date))
|
||||
(central-gap (header-make-central-gap (concat left-margin created)
|
||||
(concat ft-6 right-margin))))
|
||||
(insert (concat left-margin created central-gap ft-6 right-margin))
|
||||
)
|
||||
)
|
||||
|
||||
(defun header-insert-line-09 ()
|
||||
"Line 9 of the header"
|
||||
(let* ((left-margin (header-make-left-margin))
|
||||
(right-margin (header-make-right-margin))
|
||||
(updated (header-make-update-date))
|
||||
(central-gap (header-make-central-gap (concat left-margin updated)
|
||||
(concat ft-7 right-margin))))
|
||||
(insert (concat left-margin updated central-gap ft-7 right-margin))
|
||||
)
|
||||
)
|
||||
|
||||
(defun header-insert-line-10 ()
|
||||
"Line 10 of the header"
|
||||
(comments-insert-empty-line)
|
||||
)
|
||||
|
||||
(defun header-insert-line-11 ()
|
||||
"Line 11 of the header"
|
||||
(comments-insert-bar)
|
||||
)
|
||||
|
||||
|
||||
|
||||
;*******************************************************************************;
|
||||
|
||||
|
||||
|
||||
(defun header-insert ()
|
||||
"Creates a header for the current source file."
|
||||
(interactive)
|
||||
(save-excursion
|
||||
(goto-char (point-min))
|
||||
(header-insert-line-01)
|
||||
(header-insert-line-02)
|
||||
(header-insert-line-03) (newline)
|
||||
(header-insert-line-04) (newline)
|
||||
(header-insert-line-05) (newline)
|
||||
(header-insert-line-06) (newline)
|
||||
(header-insert-line-07) (newline)
|
||||
(header-insert-line-08) (newline)
|
||||
(header-insert-line-09) (newline)
|
||||
(header-insert-line-10)
|
||||
(header-insert-line-11)
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
(defun header-update ()
|
||||
"Updates the header for the current source file."
|
||||
(interactive)
|
||||
(save-excursion
|
||||
(if (buffer-modified-p)
|
||||
(progn
|
||||
(goto-char (point-min))
|
||||
(if (search-forward "Updated" nil t)
|
||||
(progn
|
||||
(delete-region
|
||||
(progn (beginning-of-line) (point))
|
||||
(progn (end-of-line) (point)))
|
||||
(header-insert-line-09)
|
||||
(message "Header up to date."))))))
|
||||
nil)
|
||||
|
||||
|
||||
|
||||
;******************************************************************************;
|
||||
(provide 'header)
|
50
init.el
Normal file
50
init.el
Normal file
@ -0,0 +1,50 @@
|
||||
;*******************************************************************************;
|
||||
; ;
|
||||
; ::: :::::::: ;
|
||||
; dotemacs :+: :+: :+: ;
|
||||
; +:+ +:+ +:+ ;
|
||||
; by: thor <thor@42.fr> +#+ +:+ +#+ ;
|
||||
; +#+#+#+#+#+ +#+ ;
|
||||
; Created: 2013/06/18 14:01:14 by thor #+# #+# ;
|
||||
; Updated: 2018/07/16 15:57:40 by tmaze ### ########.fr ;
|
||||
; ;
|
||||
;*******************************************************************************;
|
||||
|
||||
; Load general features files
|
||||
|
||||
;; Added by Package.el. This must come before configurations of
|
||||
;; installed packages. Don't delete this line. If you don't want it,
|
||||
;; just comment it out by adding a semicolon to the start of the line.
|
||||
;; You may delete these explanatory comments.
|
||||
(package-initialize)
|
||||
|
||||
(setq config_files "/usr/share/emacs/site-lisp/")
|
||||
(setq load-path (append (list nil config_files) load-path))
|
||||
|
||||
(load "~/.emacs.d/list.el")
|
||||
(load "~/.emacs.d/string.el")
|
||||
(load "~/.emacs.d/comments.el")
|
||||
(load "~/.emacs.d/header.el")
|
||||
|
||||
(autoload 'php-mode "php-mode" "Major mode for editing PHP code" t)
|
||||
(add-to-list 'auto-mode-alist '("\\.php[34]?\\'\\|\\.phtml\\'" . php-mode))
|
||||
|
||||
; Set default emacs configuration
|
||||
(set-language-environment "UTF-8")
|
||||
(if (version< emacs-version "23")
|
||||
(setq-default font-lock-global-modes nil))
|
||||
(setq-default line-number-mode nil)
|
||||
(setq-default tab-width 4)
|
||||
(setq-default indent-tabs-mode t)
|
||||
(global-set-key (kbd "DEL") 'backward-delete-char)
|
||||
(setq-default c-backspace-function 'backward-delete-char)
|
||||
(setq-default c-basic-offset 4)
|
||||
(setq-default c-default-style "linux")
|
||||
(setq-default tab-stop-list '(4 8 12 16 20 24 28 32 36 40 44 48 52 56 60
|
||||
64 68 72 76 80 84 88 92 96 100 104 108 112 116 120))
|
||||
|
||||
; Load user configuration
|
||||
(if (file-exists-p "~/.myemacs") (load-file "~/.myemacs"))
|
||||
|
||||
|
||||
;*******************************************************************************;
|
31
list.el
Normal file
31
list.el
Normal file
@ -0,0 +1,31 @@
|
||||
;******************************************************************************;
|
||||
; ;
|
||||
; list.el for list ;
|
||||
; Created on : Thu Oct 20 10:02:03 2011 ;
|
||||
; Made by : David "Thor" GIRON <thor@epitech.net> ;
|
||||
; ;
|
||||
;******************************************************************************;
|
||||
|
||||
|
||||
|
||||
(defun list-map (f l)
|
||||
"Map function 'f' over list 'l' and returns the result list."
|
||||
(mapcar f l
|
||||
)
|
||||
)
|
||||
|
||||
(defun list-iter (f l)
|
||||
"Map procedure 'f' over list 'l' and returns nil."
|
||||
(mapc f l)
|
||||
nil
|
||||
)
|
||||
|
||||
(defun list-fold (f s l)
|
||||
"Returns f (... (f (f s e1) e2) ...) en."
|
||||
(reduce f l :initial-value s)
|
||||
)
|
||||
|
||||
|
||||
|
||||
;******************************************************************************;
|
||||
(provide 'list)
|
86
string.el
Normal file
86
string.el
Normal file
@ -0,0 +1,86 @@
|
||||
;******************************************************************************;
|
||||
; ;
|
||||
; string.el for string ;
|
||||
; Created on : Thu Oct 20 15:36:57 2011 ;
|
||||
; Made by : David "Thor" GIRON <thor@epitech.net> ;
|
||||
; ;
|
||||
;******************************************************************************;
|
||||
|
||||
|
||||
|
||||
(require 'list)
|
||||
|
||||
|
||||
|
||||
(defun string-reverse (s)
|
||||
"Returns the reversed string of 's'."
|
||||
(concat (reverse (string-to-list s)))
|
||||
)
|
||||
|
||||
(defun string-length (s)
|
||||
"Returns the length of string 's'."
|
||||
(length s)
|
||||
)
|
||||
|
||||
(defun string-fill (len)
|
||||
(make-string len ? )
|
||||
)
|
||||
|
||||
(defun string-compare (s1 s2)
|
||||
"Compares 's1' and 's2'. Returns :
|
||||
- -1 if 's1' is shorter than 's2'
|
||||
- 0 if 's1' and 's2' are equal
|
||||
- 1 if 's1' is longer than 's2'"
|
||||
(let ((len1 (string-length s1))
|
||||
(len2 (string-length s2)))
|
||||
(cond
|
||||
((= len1 len2) 0)
|
||||
((< len1 len2) -1)
|
||||
((> len1 len2) 1)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
(defun string-longest (s1 s2)
|
||||
"Returns the length of the longest string"
|
||||
(let ((res (string-compare s1 s2)))
|
||||
(cond
|
||||
((= res 1 ) (string-length s1))
|
||||
((= res 0 ) (string-length s1))
|
||||
((= res -1) (string-length s2))
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
(defun string-pick-longest (s1 s2)
|
||||
"Returns the longest string between 's1' and 's2', or 's1' otherwise."
|
||||
(let ((res (string-compare s1 s2)))
|
||||
(cond
|
||||
((= res 1 ) s1)
|
||||
((= res 0 ) s1)
|
||||
((= res -1) s2)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
(defun string-longest-from-list (l)
|
||||
"Returns the length of longest string of the strings list 'l'."
|
||||
(list-fold
|
||||
(lambda (acc s) (if (> acc (string-length s)) acc (string-length s)))
|
||||
0
|
||||
l)
|
||||
)
|
||||
|
||||
|
||||
(defun string-pick-longest-from-list (l)
|
||||
"Returns the longest string of the strings list 'l'."
|
||||
(list-fold
|
||||
(lambda (s1 s2) (string-pick-longest s1 s2))
|
||||
""
|
||||
l)
|
||||
)
|
||||
|
||||
|
||||
|
||||
;******************************************************************************;
|
||||
(provide 'string)
|
471
yaml-mode.el
Normal file
471
yaml-mode.el
Normal file
@ -0,0 +1,471 @@
|
||||
;;; yaml-mode.el --- Major mode for editing YAML files
|
||||
|
||||
;; Copyright (C) 2010-2014 Yoshiki Kurihara
|
||||
|
||||
;; Author: Yoshiki Kurihara <clouder@gmail.com>
|
||||
;; Marshall T. Vandegrift <llasram@gmail.com>
|
||||
;; Maintainer: Vasilij Schneidermann <v.schneidermann@gmail.com>
|
||||
;; Package-Requires: ((emacs "24.1"))
|
||||
;; Keywords: data yaml
|
||||
;; Version: 0.0.13
|
||||
|
||||
;; This file is not part of Emacs
|
||||
|
||||
;; This file 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 2, or (at your option)
|
||||
;; any later version.
|
||||
|
||||
;; This file 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.
|
||||
|
||||
;; You should have received a copy of the GNU General Public License along
|
||||
;; with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
;; 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
;;; Commentary:
|
||||
|
||||
;; This is a major mode for editing files in the YAML data
|
||||
;; serialization format. It was initially developed by Yoshiki
|
||||
;; Kurihara and many features were added by Marshall Vandegrift. As
|
||||
;; YAML and Python share the fact that indentation determines
|
||||
;; structure, this mode provides indentation and indentation command
|
||||
;; behavior very similar to that of python-mode.
|
||||
|
||||
;;; Installation:
|
||||
|
||||
;; To install, just drop this file into a directory in your
|
||||
;; `load-path' and (optionally) byte-compile it. To automatically
|
||||
;; handle files ending in '.yml', add something like:
|
||||
;;
|
||||
;; (require 'yaml-mode)
|
||||
;; (add-to-list 'auto-mode-alist '("\\.yml\\'" . yaml-mode))
|
||||
;;
|
||||
;; to your .emacs file.
|
||||
;;
|
||||
;; Unlike python-mode, this mode follows the Emacs convention of not
|
||||
;; binding the ENTER key to `newline-and-indent'. To get this
|
||||
;; behavior, add the key definition to `yaml-mode-hook':
|
||||
;;
|
||||
;; (add-hook 'yaml-mode-hook
|
||||
;; '(lambda ()
|
||||
;; (define-key yaml-mode-map "\C-m" 'newline-and-indent)))
|
||||
|
||||
;;; Known Bugs:
|
||||
|
||||
;; YAML is easy to write but complex to parse, and this mode doesn't
|
||||
;; even really try. Indentation and highlighting will break on
|
||||
;; abnormally complicated structures.
|
||||
|
||||
;;; Code:
|
||||
|
||||
|
||||
;; User definable variables
|
||||
|
||||
;;;###autoload
|
||||
(defgroup yaml nil
|
||||
"Support for the YAML serialization format"
|
||||
:group 'languages
|
||||
:prefix "yaml-")
|
||||
|
||||
(defcustom yaml-mode-hook nil
|
||||
"*Hook run by `yaml-mode'."
|
||||
:type 'hook
|
||||
:group 'yaml)
|
||||
|
||||
(defcustom yaml-indent-offset 2
|
||||
"*Amount of offset per level of indentation."
|
||||
:type 'integer
|
||||
:safe 'natnump
|
||||
:group 'yaml)
|
||||
|
||||
(defcustom yaml-backspace-function 'backward-delete-char-untabify
|
||||
"*Function called by `yaml-electric-backspace' when deleting backwards.
|
||||
It will receive one argument, the numeric prefix value."
|
||||
:type 'function
|
||||
:group 'yaml)
|
||||
|
||||
(defcustom yaml-block-literal-search-lines 100
|
||||
"*Maximum number of lines to search for start of block literals."
|
||||
:type 'integer
|
||||
:group 'yaml)
|
||||
|
||||
(defcustom yaml-block-literal-electric-alist
|
||||
'((?| . "") (?> . "-"))
|
||||
"*Characters for which to provide electric behavior.
|
||||
The association list key should be a key code and the associated value
|
||||
should be a string containing additional characters to insert when
|
||||
that key is pressed to begin a block literal."
|
||||
:type 'alist
|
||||
:group 'yaml)
|
||||
|
||||
(defface yaml-tab-face
|
||||
'((((class color)) (:background "red" :foreground "red" :bold t))
|
||||
(t (:reverse-video t)))
|
||||
"Face to use for highlighting tabs in YAML files."
|
||||
:group 'faces
|
||||
:group 'yaml)
|
||||
|
||||
(defcustom yaml-imenu-generic-expression
|
||||
'((nil "^\\(:?[a-zA-Z_-]+\\):" 1))
|
||||
"The imenu regex to parse an outline of the yaml file."
|
||||
:type 'string
|
||||
:group 'yaml)
|
||||
|
||||
|
||||
;; Constants
|
||||
|
||||
(defconst yaml-mode-version "0.0.13" "Version of `yaml-mode'.")
|
||||
|
||||
(defconst yaml-blank-line-re "^ *$"
|
||||
"Regexp matching a line containing only (valid) whitespace.")
|
||||
|
||||
(defconst yaml-directive-re "^\\(?:--- \\)? *%\\(\\w+\\)"
|
||||
"Regexp matching a line contatining a YAML directive.")
|
||||
|
||||
(defconst yaml-document-delimiter-re "^\\(?:---\\|[.][.][.]\\)"
|
||||
"Rexexp matching a YAML document delimiter line.")
|
||||
|
||||
(defconst yaml-node-anchor-alias-re "[&*][a-zA-Z0-9_-]+"
|
||||
"Regexp matching a YAML node anchor or alias.")
|
||||
|
||||
(defconst yaml-tag-re "!!?[^ \n]+"
|
||||
"Rexexp matching a YAML tag.")
|
||||
|
||||
(defconst yaml-bare-scalar-re
|
||||
"\\(?:[^-:,#!\n{\\[ ]\\|[^#!\n{\\[ ]\\S-\\)[^#\n]*?"
|
||||
"Rexexp matching a YAML bare scalar.")
|
||||
|
||||
(defconst yaml-hash-key-re
|
||||
(concat "\\(?:^\\(?:--- \\)?\\|{\\|\\(?:[-,] +\\)+\\) *"
|
||||
"\\(?:" yaml-tag-re " +\\)?"
|
||||
"\\(" yaml-bare-scalar-re "\\) *:"
|
||||
"\\(?: +\\|$\\)")
|
||||
"Regexp matching a single YAML hash key.")
|
||||
|
||||
(defconst yaml-scalar-context-re
|
||||
(concat "\\(?:^\\(?:--- \\)?\\|{\\|\\(?: *[-,] +\\)+\\) *"
|
||||
"\\(?:" yaml-bare-scalar-re " *: \\)?")
|
||||
"Regexp indicating the beginning of a scalar context.")
|
||||
|
||||
(defconst yaml-nested-map-re
|
||||
(concat ".*: *\\(?:&.*\\|{ *\\|" yaml-tag-re " *\\)?$")
|
||||
"Regexp matching a line beginning a YAML nested structure.")
|
||||
|
||||
(defconst yaml-block-literal-base-re " *[>|][-+0-9]* *\\(?:\n\\|\\'\\)"
|
||||
"Regexp matching the substring start of a block literal.")
|
||||
|
||||
(defconst yaml-block-literal-re
|
||||
(concat yaml-scalar-context-re
|
||||
"\\(?:" yaml-tag-re "\\)?"
|
||||
yaml-block-literal-base-re)
|
||||
"Regexp matching a line beginning a YAML block literal.")
|
||||
|
||||
(defconst yaml-nested-sequence-re
|
||||
(concat "^\\(?:\\(?: *- +\\)+\\|\\(:? *-$\\)\\)"
|
||||
"\\(?:" yaml-bare-scalar-re " *:\\(?: +.*\\)?\\)?$")
|
||||
"Regexp matching a line containing one or more nested YAML sequences.")
|
||||
|
||||
(defconst yaml-constant-scalars-re
|
||||
(concat "\\(?:^\\|\\(?::\\|-\\|,\\|{\\|\\[\\) +\\) *"
|
||||
(regexp-opt
|
||||
'("~" "null" "Null" "NULL"
|
||||
".nan" ".NaN" ".NAN"
|
||||
".inf" ".Inf" ".INF"
|
||||
"-.inf" "-.Inf" "-.INF"
|
||||
"y" "Y" "yes" "Yes" "YES" "n" "N" "no" "No" "NO"
|
||||
"true" "True" "TRUE" "false" "False" "FALSE"
|
||||
"on" "On" "ON" "off" "Off" "OFF") t)
|
||||
" *$")
|
||||
"Regexp matching certain scalar constants in scalar context.")
|
||||
|
||||
|
||||
;; Mode setup
|
||||
|
||||
(defvar yaml-mode-map
|
||||
(let ((map (make-sparse-keymap)))
|
||||
(define-key map "|" 'yaml-electric-bar-and-angle)
|
||||
(define-key map ">" 'yaml-electric-bar-and-angle)
|
||||
(define-key map "-" 'yaml-electric-dash-and-dot)
|
||||
(define-key map "." 'yaml-electric-dash-and-dot)
|
||||
(define-key map (kbd "DEL") 'yaml-electric-backspace)
|
||||
map)
|
||||
"Keymap used in `yaml-mode' buffers.")
|
||||
|
||||
(defvar yaml-mode-syntax-table
|
||||
(let ((syntax-table (make-syntax-table)))
|
||||
(modify-syntax-entry ?\' "\"" syntax-table)
|
||||
(modify-syntax-entry ?\" "\"" syntax-table)
|
||||
(modify-syntax-entry ?# "<" syntax-table)
|
||||
(modify-syntax-entry ?\n ">" syntax-table)
|
||||
(modify-syntax-entry ?\\ "\\" syntax-table)
|
||||
(modify-syntax-entry ?- "_" syntax-table)
|
||||
(modify-syntax-entry ?_ "_" syntax-table)
|
||||
(modify-syntax-entry ?& "." syntax-table)
|
||||
(modify-syntax-entry ?* "." syntax-table)
|
||||
(modify-syntax-entry ?\( "." syntax-table)
|
||||
(modify-syntax-entry ?\) "." syntax-table)
|
||||
(modify-syntax-entry ?\{ "(}" syntax-table)
|
||||
(modify-syntax-entry ?\} "){" syntax-table)
|
||||
(modify-syntax-entry ?\[ "(]" syntax-table)
|
||||
(modify-syntax-entry ?\] ")[" syntax-table)
|
||||
syntax-table)
|
||||
"Syntax table in use in `yaml-mode' buffers.")
|
||||
|
||||
;;;###autoload
|
||||
(define-derived-mode yaml-mode text-mode "YAML"
|
||||
"Simple mode to edit YAML.
|
||||
|
||||
\\{yaml-mode-map}"
|
||||
:syntax-table yaml-mode-syntax-table
|
||||
(set (make-local-variable 'comment-start) "# ")
|
||||
(set (make-local-variable 'comment-start-skip) "#+ *")
|
||||
(set (make-local-variable 'indent-line-function) 'yaml-indent-line)
|
||||
(set (make-local-variable 'indent-tabs-mode) nil)
|
||||
(set (make-local-variable 'fill-paragraph-function) 'yaml-fill-paragraph)
|
||||
|
||||
(set (make-local-variable 'syntax-propertize-function)
|
||||
'yaml-mode-syntax-propertize-function)
|
||||
(setq font-lock-defaults '(yaml-font-lock-keywords)))
|
||||
|
||||
|
||||
;; Font-lock support
|
||||
|
||||
(defvar yaml-font-lock-keywords
|
||||
`((yaml-font-lock-block-literals 0 font-lock-string-face)
|
||||
(,yaml-constant-scalars-re . (1 font-lock-constant-face))
|
||||
(,yaml-tag-re . (0 font-lock-type-face))
|
||||
(,yaml-node-anchor-alias-re . (0 font-lock-function-name-face))
|
||||
(,yaml-hash-key-re . (1 font-lock-variable-name-face))
|
||||
(,yaml-document-delimiter-re . (0 font-lock-comment-face))
|
||||
(,yaml-directive-re . (1 font-lock-builtin-face))
|
||||
("^[\t]+" 0 'yaml-tab-face t))
|
||||
"Additional expressions to highlight in YAML mode.")
|
||||
|
||||
(defun yaml-mode-syntax-propertize-function (beg end)
|
||||
"Override buffer's syntax table for special syntactic constructs."
|
||||
;; Unhighlight foo#bar tokens between BEG and END.
|
||||
(save-excursion
|
||||
(goto-char beg)
|
||||
(while (search-forward "#" end t)
|
||||
(save-excursion
|
||||
(forward-char -1)
|
||||
;; both ^# and [ \t]# are comments
|
||||
(when (and (not (bolp))
|
||||
(not (memq (preceding-char) '(?\s ?\t))))
|
||||
(put-text-property (point) (1+ (point))
|
||||
'syntax-table (string-to-syntax "_"))))))
|
||||
|
||||
;; If quote is detected as a syntactic string start but appeared
|
||||
;; after a non-whitespace character, then mark it as syntactic word.
|
||||
(save-excursion
|
||||
(goto-char beg)
|
||||
(while (re-search-forward "['\"]" end t)
|
||||
(when (get-text-property (point) 'yaml-block-literal)
|
||||
(put-text-property (1- (point)) (point)
|
||||
'syntax-table (string-to-syntax "w")))
|
||||
(when (nth 8 (syntax-ppss))
|
||||
(save-excursion
|
||||
(forward-char -1)
|
||||
(cond ((and (char-equal ?' (char-before (point)))
|
||||
(char-equal ?' (char-after (point)))
|
||||
(put-text-property (1- (point)) (1+ (point))
|
||||
'syntax-table (string-to-syntax "w"))))
|
||||
((and (not (bolp))
|
||||
(char-equal ?w (char-syntax (char-before (point)))))
|
||||
(put-text-property (point) (1+ (point))
|
||||
'syntax-table (string-to-syntax "w")))))))))
|
||||
|
||||
(defun yaml-font-lock-block-literals (bound)
|
||||
"Find lines within block literals.
|
||||
Find the next line of the first (if any) block literal after point and
|
||||
prior to BOUND. Returns the beginning and end of the block literal
|
||||
line in the match data, as consumed by `font-lock-keywords' matcher
|
||||
functions. The function begins by searching backwards to determine
|
||||
whether or not the current line is within a block literal. This could
|
||||
be time-consuming in large buffers, so the number of lines searched is
|
||||
artificially limitted to the value of
|
||||
`yaml-block-literal-search-lines'."
|
||||
(if (eolp) (goto-char (1+ (point))))
|
||||
(unless (or (eobp) (>= (point) bound))
|
||||
(let ((begin (point))
|
||||
(end (min (1+ (point-at-eol)) bound)))
|
||||
(goto-char (point-at-bol))
|
||||
(while (and (looking-at yaml-blank-line-re)
|
||||
(not (bobp)))
|
||||
(forward-line -1))
|
||||
(let ((nlines yaml-block-literal-search-lines)
|
||||
(min-level (current-indentation)))
|
||||
(forward-line -1)
|
||||
(while (and (/= nlines 0)
|
||||
(/= min-level 0)
|
||||
(not (looking-at yaml-block-literal-re))
|
||||
(not (bobp)))
|
||||
(setq nlines (1- nlines))
|
||||
(unless (looking-at yaml-blank-line-re)
|
||||
(setq min-level (min min-level (current-indentation))))
|
||||
(forward-line -1))
|
||||
(cond
|
||||
((and (< (current-indentation) min-level)
|
||||
(looking-at yaml-block-literal-re))
|
||||
(goto-char end)
|
||||
(put-text-property begin end 'yaml-block-literal t)
|
||||
(set-match-data (list begin end))
|
||||
t)
|
||||
((progn
|
||||
(goto-char begin)
|
||||
(re-search-forward (concat yaml-block-literal-re
|
||||
" *\\(.*\\)\n")
|
||||
bound t))
|
||||
(let ((range (nthcdr 2 (match-data))))
|
||||
(put-text-property (car range) (cadr range) 'yaml-block-literal t)
|
||||
(set-match-data range))
|
||||
t))))))
|
||||
|
||||
|
||||
;; Indentation and electric keys
|
||||
|
||||
(defun yaml-compute-indentation ()
|
||||
"Calculate the maximum sensible indentation for the current line."
|
||||
(save-excursion
|
||||
(beginning-of-line)
|
||||
(if (looking-at yaml-document-delimiter-re) 0
|
||||
(forward-line -1)
|
||||
(while (and (looking-at yaml-blank-line-re)
|
||||
(> (point) (point-min)))
|
||||
(forward-line -1))
|
||||
(+ (current-indentation)
|
||||
(if (looking-at yaml-nested-map-re) yaml-indent-offset 0)
|
||||
(if (looking-at yaml-nested-sequence-re) yaml-indent-offset 0)
|
||||
(if (looking-at yaml-block-literal-re) yaml-indent-offset 0)))))
|
||||
|
||||
(defun yaml-indent-line ()
|
||||
"Indent the current line.
|
||||
The first time this command is used, the line will be indented to the
|
||||
maximum sensible indentation. Each immediately subsequent usage will
|
||||
back-dent the line by `yaml-indent-offset' spaces. On reaching column
|
||||
0, it will cycle back to the maximum sensible indentation."
|
||||
(interactive "*")
|
||||
(let ((ci (current-indentation))
|
||||
(cc (current-column))
|
||||
(need (yaml-compute-indentation)))
|
||||
(save-excursion
|
||||
(beginning-of-line)
|
||||
(delete-horizontal-space)
|
||||
(if (and (equal last-command this-command) (/= ci 0))
|
||||
(indent-to (* (/ (- ci 1) yaml-indent-offset) yaml-indent-offset))
|
||||
(indent-to need)))
|
||||
(if (< (current-column) (current-indentation))
|
||||
(forward-to-indentation 0))))
|
||||
|
||||
(defun yaml-electric-backspace (arg)
|
||||
"Delete characters or back-dent the current line.
|
||||
If invoked following only whitespace on a line, will back-dent to the
|
||||
immediately previous multiple of `yaml-indent-offset' spaces."
|
||||
(interactive "*p")
|
||||
(if (or (/= (current-indentation) (current-column)) (bolp))
|
||||
(funcall yaml-backspace-function arg)
|
||||
(let ((ci (current-column)))
|
||||
(beginning-of-line)
|
||||
(delete-horizontal-space)
|
||||
(indent-to (* (/ (- ci (* arg yaml-indent-offset))
|
||||
yaml-indent-offset)
|
||||
yaml-indent-offset)))))
|
||||
|
||||
(defun yaml-electric-bar-and-angle (arg)
|
||||
"Insert the bound key and possibly begin a block literal.
|
||||
Inserts the bound key. If inserting the bound key causes the current
|
||||
line to match the initial line of a block literal, then inserts the
|
||||
matching string from `yaml-block-literal-electric-alist', a newline,
|
||||
and indents appropriately."
|
||||
(interactive "*P")
|
||||
(self-insert-command (prefix-numeric-value arg))
|
||||
(let ((extra-chars
|
||||
(assoc last-command-event
|
||||
yaml-block-literal-electric-alist)))
|
||||
(cond
|
||||
((and extra-chars (not arg) (eolp)
|
||||
(save-excursion
|
||||
(beginning-of-line)
|
||||
(looking-at yaml-block-literal-re)))
|
||||
(insert (cdr extra-chars))
|
||||
(newline-and-indent)))))
|
||||
|
||||
(defun yaml-electric-dash-and-dot (arg)
|
||||
"Insert the bound key and possibly de-dent line.
|
||||
Inserts the bound key. If inserting the bound key causes the current
|
||||
line to match a document delimiter, de-dent the line to the left
|
||||
margin."
|
||||
(interactive "*P")
|
||||
(self-insert-command (prefix-numeric-value arg))
|
||||
(save-excursion
|
||||
(beginning-of-line)
|
||||
(when (and (not arg) (looking-at yaml-document-delimiter-re))
|
||||
(delete-horizontal-space))))
|
||||
|
||||
(defun yaml-narrow-to-block-literal ()
|
||||
"Narrow the buffer to block literal if the point is in it,
|
||||
otherwise do nothing."
|
||||
(interactive)
|
||||
(save-excursion
|
||||
(goto-char (point-at-bol))
|
||||
(while (and (looking-at-p yaml-blank-line-re) (not (bobp)))
|
||||
(forward-line -1))
|
||||
(let ((nlines yaml-block-literal-search-lines)
|
||||
(min-level (current-indentation))
|
||||
beg)
|
||||
(forward-line -1)
|
||||
(while (and (/= nlines 0)
|
||||
(/= min-level 0)
|
||||
(not (looking-at-p yaml-block-literal-re))
|
||||
(not (bobp)))
|
||||
(setq nlines (1- nlines))
|
||||
(unless (looking-at-p yaml-blank-line-re)
|
||||
(setq min-level (min min-level (current-indentation))))
|
||||
(forward-line -1))
|
||||
(when (and (< (current-indentation) min-level)
|
||||
(looking-at-p yaml-block-literal-re))
|
||||
(setq min-level (current-indentation))
|
||||
(forward-line)
|
||||
(setq beg (point))
|
||||
(while (and (not (eobp))
|
||||
(or (looking-at-p yaml-blank-line-re)
|
||||
(> (current-indentation) min-level)))
|
||||
(forward-line))
|
||||
(narrow-to-region beg (point))))))
|
||||
|
||||
(defun yaml-fill-paragraph (&optional justify region)
|
||||
"Fill paragraph.
|
||||
Outside of comments, this behaves as `fill-paragraph' except that
|
||||
filling does not cross boundaries of block literals. Inside comments,
|
||||
this will do usual adaptive fill behaviors."
|
||||
(interactive "*P")
|
||||
(save-restriction
|
||||
(yaml-narrow-to-block-literal)
|
||||
(let ((fill-paragraph-function nil))
|
||||
(or (fill-comment-paragraph justify)
|
||||
(fill-paragraph justify region)))))
|
||||
|
||||
(defun yaml-set-imenu-generic-expression ()
|
||||
(make-local-variable 'imenu-generic-expression)
|
||||
(make-local-variable 'imenu-create-index-function)
|
||||
(setq imenu-create-index-function 'imenu-default-create-index-function)
|
||||
(setq imenu-generic-expression yaml-imenu-generic-expression))
|
||||
|
||||
(add-hook 'yaml-mode-hook 'yaml-set-imenu-generic-expression)
|
||||
|
||||
|
||||
(defun yaml-mode-version ()
|
||||
"Display version of `yaml-mode'."
|
||||
(interactive)
|
||||
(message "yaml-mode %s" yaml-mode-version)
|
||||
yaml-mode-version)
|
||||
|
||||
;;;###autoload
|
||||
(add-to-list 'auto-mode-alist '("\\.\\(e?ya?\\|ra\\)ml\\'" . yaml-mode))
|
||||
|
||||
(provide 'yaml-mode)
|
||||
|
||||
;;; yaml-mode.el ends here
|
Loading…
x
Reference in New Issue
Block a user