Initial commit

This commit is contained in:
Némunaire 2012-10-13 21:35:28 +02:00
commit 99e3df82b7
28 changed files with 2639 additions and 0 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
*.elc

26
configs/coding-style.el Normal file
View file

@ -0,0 +1,26 @@
(add-to-list 'c-style-alist
'("epita"
(c-basic-offset . 2)
(c-comment-only-line-offset . 0)
(c-hanging-braces-alist . ((substatement-open before after)))
(c-offsets-alist . ((topmost-intro . 0)
(substatement . +)
(substatement-open . 0)
(case-label . +)
(access-label . -)
(inclass . ++)
(inline-open . 0)))))
(c-add-style
"e"
'("gnu"
(show-trailing-whitespace t)
(indent-tabs-mode . nil)
(tab-width . 8)
(c-offsets-alist .
((defun-block-intro . 3)
(statement-block-intro . 3)
(case-label . 1)
(statement-case-intro . 3)
(inclass . 3)
))))

114
configs/custom.el Normal file
View file

@ -0,0 +1,114 @@
;; Remove useless features
(menu-bar-mode nil)
;(tool-bar-mode nil)
;(scroll-bar-mode nil)
(setq inhibit-startup-message t)
;;Save backup files into a specific directory, not in the working directry
(defun make-backup-file-name (file)
(concat "~/.emacs.d/backup/" (file-name-nondirectory file) "~"))
;; Enable some minor mode changing mode line
(column-number-mode t) ; Show column number
(line-number-mode t) ; Show line number
(display-time-mode t) ; A clock in the mode line
;; Show matching parentheses
(show-paren-mode t)
(defadvice show-paren-function
(after show-matching-paren-offscreen activate)
"If the matching paren is offscreen, show the matching line in the
echo area. Has no effect if the character before point is not of
the syntax class ')'."
(interactive)
(if (not (minibuffer-prompt))
(let ((matching-text nil))
;; Only call `blink-matching-open' if the character before point
;; is a close parentheses type character. Otherwise, there's not
;; really any point, and `blink-matching-open' would just echo
;; "Mismatched parentheses", which gets really annoying.
(if (char-equal (char-syntax (char-before (point))) ?\))
(setq matching-text (blink-matching-open)))
(if (not (null matching-text))
(message matching-text)))))
;; Enable usefull modes
(global-font-lock-mode t) ; syntax highlighting
(setq font-lock-maximum-decoration t) ; max decoration for all modes
(auto-compression-mode t) ; Auto decompress compressed files.
(setq set-mark-command-repeat-pop t)
(autoload 'nuke-trailing-whitespace "whitespace" nil t)
(setq delete-old-versions t) ; delete oldversion file
(setq default-major-mode 'text-mode) ; change default major mode to text
(global-auto-revert-mode t) ; auto revert modified files
(dynamic-completion-mode) ; dynamic completion
;; setting for auto-close brackets for electric-pair-mode regardless of current major mode syntax table
(electric-pair-mode t)
(setq electric-pair-pairs '(
(?\" . ?\")
(?\{ . ?\})
) )
;; In linux, make copy/paste work with other apps
(setq x-select-enable-clipboard t)
;; Compilation window
(setq compilation-window-height 14)
(setq compilation-scroll-output t)
(require 'uniquify)
(setq uniquify-buffer-name-style 'post-forward-angle-brackets)
(setq-default ispell-program-name "aspell")
;; GDB use all existing window
(setq-default gdb-many-windows t)
;; Recognize test suite output
(require 'compile)
(add-to-list 'compilation-error-regexp-alist '("^\\(PASS\\|SKIP\\|XFAIL\\|TFAIL\\): \\(.*\\)$" 2 () () 0 2))
(add-to-list 'compilation-error-regexp-alist '("^\\(FAIL\\|XPASS\\): \\(.*\\)$" 2 () () 2 2))
(require 'flymake)
(add-hook 'find-file-hooks 'flymake-find-file-hook)
;;IswitchBuffer configuration
(iswitchb-mode t)
(setq iswitchb-buffer-ignore '("^\\*"))
(defun iswitchb-local-keys ()
(mapc (lambda (K)
(let* ((key (car K)) (fun (cdr K)))
(define-key iswitchb-mode-map (edmacro-parse-keys key) fun)))
'(("<right>" . iswitchb-next-match)
("<left>" . iswitchb-prev-match)
("<up>" . ignore )
("<down>" . ignore ))))
(add-hook 'iswitchb-define-mode-map-hook 'iswitchb-local-keys)
;; Save and restore window layout
(defvar winconf-ring ())
(defun push-winconf ()
(interactive)
(window-configuration-to-register ?%)
(push (get-register ?%) winconf-ring))
(defun pop-winconf ()
(interactive)
(set-register ?% (pop winconf-ring))
(jump-to-register ?%))
(defun restore-winconf ()
(interactive)
(set-register ?% (car winconf-ring))
(jump-to-register ?%))
;; highlight when > 80 cols
(defun eightycols nil
(defface line-overflow
'((t (:background "red" :foreground "black")))
"Face to use for `hl-line-face'.")
(highlight-regexp "^.\\{80,\\}$" 'line-overflow)
)
;(add-hook 'find-file-hook 'eightycols)

173
configs/editing.el Normal file
View file

@ -0,0 +1,173 @@
(defun c-switch-hh-cc ()
(interactive)
(let ((other
(let ((file (buffer-file-name)))
(if (string-match "\\.hh$" file)
(replace-regexp-in-string "\\.hh$" ".cc" file)
(replace-regexp-in-string "\\.cc$" ".hh" file)))))
(find-file other)))
(defun count-word (start end)
(let ((begin (min start end))(end (max start end)))
(save-excursion
(goto-char begin)
(re-search-forward "\\W*") ; skip blank
(setq i 0)
(while (< (point) end)
(re-search-forward "\\w+")
(when (<= (point) end)
(setq i (+ 1 i)))
(re-search-forward "\\W*"))))
i)
(defun stat-region (start end)
(interactive "r")
(let
((words (count-word start end)) (lines (count-lines start end)))
(message
(concat "Lines: "
(int-to-string lines)
" Words: "
(int-to-string words)))
)
)
(defun ruby-command (cmd &optional output-buffer error-buffer)
"Like shell-command, but using ruby."
(interactive (list (read-from-minibuffer "Ruby command: "
nil nil nil 'ruby-command-history)
current-prefix-arg
shell-command-default-error-buffer))
(shell-command (concat "ruby -e '" cmd "'") output-buffer error-buffer))
;; Shebangs
(defun insert-shebang (bin)
(interactive "sBin: ")
(save-excursion
(goto-char (point-min))
(insert "#!" bin "\n\n")))
(defun insert-shebang-if-empty (bin)
(when (buffer-empty-p)
(insert-shebang bin)))
;; C/C++
;; Comment boxing
(defun insert-header-guard ()
(interactive)
(save-excursion
(when (buffer-file-name)
(let*
((name (file-name-nondirectory buffer-file-name))
(macro (replace-regexp-in-string
"\\." "_"
(replace-regexp-in-string
"-" "_"
(upcase name)))))
(goto-char (point-min))
(insert "#ifndef " macro "_\n")
(insert "# define " macro "_\n\n")
(goto-char (point-max))
(insert "\n#endif /* !" macro "_ */\n")))))
(defun insert-header-inclusion ()
(interactive)
(when (buffer-file-name)
(let
((name
(replace-regexp-in-string ".c$" ".h"
(replace-regexp-in-string ".cc$" ".hh"
(file-name-nondirectory buffer-file-name)))))
(insert "#include \"" name "\"\n\n"))))
(defun sandbox ()
"Opens a C++ sandbox in current window."
(interactive)
(cd "/tmp")
(let ((file (make-temp-file "/tmp/" nil ".cc")))
(find-file file)
(insert "int main()\n{\n\n}\n")
(line-move -2)
(save-buffer)
(compile (concat "g++ -W -Wall -I /usr/include/qt4/ -I /usr/include/qt4/QtCore/ -L /usr/lib/qt4 -lQtCore " file " && ./a.out"))))
(defun c-insert-debug (&optional msg)
(interactive)
(when (not (looking-at "\\W*$"))
(beginning-of-line)
(insert "\n")
(line-move -1))
(c-indent-line)
(insert "std::cerr << \"\" << std::endl;")
(backward-char 15))
(defun c-insert-block (&optional r b a)
(interactive "P")
(unless b (setq b ""))
(unless a (setq a ""))
(if r
(progn
(save-excursion
(goto-char (rbegin))
(beginning-of-line)
(insert "\n")
(line-move -1)
(insert b "{")
(c-indent-line))
(save-excursion
(goto-char (- (rend) 1))
(end-of-line)
(insert "\n}" a)
(c-indent-line)
(line-move -1)
(end-of-line))
(indent-region (rbegin) (rend)))
(progn
(beginning-of-line)
(setq begin (point))
(insert b "{\n")
(end-of-line)
(insert "\n}" a)
(indent-region begin (point))
(line-move -1)
(end-of-line))))
(defun c-insert-braces (&optional r)
(interactive "P")
(c-insert-block r))
(defun c-insert-ns (name r)
(interactive "sName: \nP")
(c-insert-block r (concat "namespace " name "\n")))
(defun c-insert-switch (value r)
(interactive "sValue: \nP")
(c-insert-block r (concat "switch (" value ")\n")))
(defun c-insert-if (c r)
(interactive "sCondition: \nP")
(c-insert-block r (concat "if (" c ")\n")))
(defun c-insert-class (name)
(interactive "sName: ")
(c-insert-block () (concat "class " name "\n") ";")
(insert "public:")
(c-indent-line)
(insert "\n")
(c-indent-line)
(insert "\n")
(insert "\n")
(insert "private:")
(c-indent-line)
(insert "\n")
(c-indent-line)
(line-move -3)
(end-of-line))

28
configs/hooks.el Normal file
View file

@ -0,0 +1,28 @@
; Delete trailing whitespaces on save
(add-hook 'write-file-hooks 'delete-trailing-whitespace)
;; Mode to collapse code block
(add-hook 'c-mode-common-hook (lambda () (hs-minor-mode 1)))
(add-hook 'lisp-mode-hooks (lambda () (hs-minor-mode 1)))
(add-hook 'java-mode-hooks (lambda () (hs-minor-mode 1)))
(add-hook 'python-mode-hooks (lambda () (hs-minor-mode 1)))
; Auto insert C/C++ header guard
(add-hook 'find-file-hooks
(lambda ()
(when (and (memq major-mode '(c-mode c++-mode)) (equal (point-min) (point-max)) (string-match ".*\\.hh?" (buffer-file-name)))
(insert-header-guard)
(goto-line 3)
(insert "\n"))))
(add-hook 'find-file-hooks
(lambda ()
(when (and (memq major-mode '(c-mode c++-mode)) (equal (point-min) (point-max)) (string-match ".*\\.cc?" (buffer-file-name)))
(insert-header-inclusion))))
(add-hook 'sh-mode-hook
(lambda ()
(insert-shebang-if-empty "/bin/sh")))
(add-hook 'ruby-mode-hook
(lambda ()
(insert-shebang-if-empty "/usr/bin/ruby")))

77
configs/key-binding.el Normal file
View file

@ -0,0 +1,77 @@
;; Goto line #
(global-set-key [(meta g)] 'goto-line)
;; Move between windnow
(global-set-key [C-left] 'windmove-left)
(global-set-key [C-right] 'windmove-right)
(global-set-key [C-up] 'windmove-up)
(global-set-key [C-down] 'windmove-down)
;; Compile file
(global-set-key (kbd "C-c M-c") 'compile)
(global-set-key (kbd "C-c c") 'recompile)
(global-set-key (kbd "C-c e") 'next-error)
(global-set-key (kbd "C-c g") 'gdb)
;; Get some stat on region
(global-set-key [(meta =)] 'stat-region)
;; Move in buffer
(global-set-key [C-home] 'beginning-of-buffer)
(global-set-key [C-end] 'end-of-buffer)
(global-set-key [home] 'beginning-of-line)
(global-set-key [end] 'end-of-line)
(global-set-key (kbd "C-c h") 'replace-string)
(global-set-key (kbd "C-c j") 'replace-regexp)
(global-set-key (kbd "C-c o") 'bury-buffer)
(global-set-key (kbd "C-c k") 'kill-this-buffer)
(put 'narrow-to-region 'disabled nil)
;; Don't shift-selection
(setq shift-select-mode nil)
;; BINDINGS :: C/C++
(require 'cc-mode)
(define-key
c-mode-base-map
[(control c) (w)]
'c-switch-hh-cc) ; switch between .hh and .cc
(define-key
c-mode-base-map
[(control c) (f)]
'hs-hide-block) ; fold code
(define-key
c-mode-base-map
[(control c) (s)]
'hs-show-block) ; unfold code
(define-key
c-mode-base-map
[(control c) (control n)]
'c-insert-ns) ; insert namespace
(define-key
c-mode-base-map
[(control c) (control s)]
'c-insert-switch) ; insert switch
(define-key
c-mode-base-map
[(control c) (control i)]
'c-insert-if) ; insert if
(define-key
c-mode-base-map
[(control c) (control b)]
'c-insert-braces) ; insert braces
(define-key
c-mode-base-map
[(control c) (control f)]
'insert-fixme) ; insert fixme
(define-key
c-mode-base-map
[(control c) (control d)]
'c-insert-debug) ; insert debug
(define-key
c-mode-base-map
[(control c) (control l)]
'c-insert-class) ; insert class

13
configs/mail.el Normal file
View file

@ -0,0 +1,13 @@
(add-to-list 'auto-mode-alist '("/mutt" . mail-mode))
(add-hook 'mail-mode-hook 'turn-on-auto-fill)
(add-hook 'mail-mode-hook 'mail-abbrevs-setup)
;; colorizing multiply-quoted lines
(add-hook 'mail-mode-hook
(lambda ()
(font-lock-add-keywords nil
'(("^[ \t]*>[ \t]*>[ \t]*>.*$"
(0 'mail-multiply-quoted-text-face))
("^[ \t]*>[ \t]*>.*$"
(0 'mail-double-quoted-text-face))))))

30
configs/modes.el Normal file
View file

@ -0,0 +1,30 @@
;; Tiger mode
(autoload 'tiger-mode "tiger" "Load tiger-mode" t)
(add-to-list 'auto-mode-alist '("\\.ti[gh]$" . tiger-mode))
;; C++ mode
(add-to-list 'auto-mode-alist '("\\.l$" . c++-mode))
(add-to-list 'auto-mode-alist '("\\.y$" . c++-mode))
(add-to-list 'auto-mode-alist '("\\.ll$" . c++-mode))
(add-to-list 'auto-mode-alist '("\\.yy$" . c++-mode))
(add-to-list 'auto-mode-alist '("\\.xcc$" . c++-mode))
(add-to-list 'auto-mode-alist '("\\.xhh$" . c++-mode))
(add-to-list 'auto-mode-alist '("Drakefile$" . c++-mode))
;; SH mode
(add-to-list 'auto-mode-alist '("\\.pro$" . sh-mode)) ; Qt .pro files
(add-to-list 'auto-mode-alist '("configure$" . sh-mode))
;; Changelog mode
(add-to-list 'auto-mode-alist '("COMMIT_EDITMSG" . change-log-mode))
;; Edje-mode
(require 'edje-mode)
(add-to-list 'auto-mode-alist '("\\.edc$" . edje-mode))
;; Org-mode
(require 'org-install)
(add-to-list 'auto-mode-alist '("\\.org$" . org-mode))
(define-key global-map "\C-cl" 'org-store-link)
(define-key global-map "\C-ca" 'org-agenda)
(setq org-log-done t)

17
configs/perso.el Normal file
View file

@ -0,0 +1,17 @@
;; E-mail adress
(custom-set-variables '(user-mail-address "nemunaire@pomail.fr")
'(query-user-mail-address nil))
;; Ispell check default language
(ispell-change-dictionary "francais" t)
(defvar cpu-number 8
"Number of parallel processing units on this system")
(setq compile-command "make")
(setq c-default-style "epita")
;; Chargement de mes paramètres personnels
(if (file-exists-p "~/.private.el")
(load-file "~/.private.el"))

17
configs/project.el Normal file
View file

@ -0,0 +1,17 @@
(setq project-roots
`(("Django project"
:root-contains-files ("manage.py")
:filename-regex ,(regexify-ext-list '(py html css js sh))
:exclude-paths '("contrib"))))
(global-set-key (kbd "C-c p f") 'project-root-find-file)
(global-set-key (kbd "C-c p g") 'project-root-grep)
(global-set-key (kbd "C-c p a") 'project-root-ack)
(global-set-key (kbd "C-c p d") 'project-root-goto-root)
(global-set-key (kbd "C-c p l") 'project-root-browse-seen-projects)
(global-set-key (kbd "C-c p s")
(lambda () (interactive)
(with-project-root
(ansi-term (getenv "SHELL")
(concat (car project-details) "-shell")))

25
configs/tags.el Normal file
View file

@ -0,0 +1,25 @@
(defadvice find-tag (around refresh-etags activate)
"Rerun etags and reload tags if tag not found and redo find-tag.
If buffer is modified, ask about save before running etags."
(let ((extension (file-name-extension (buffer-file-name))))
(condition-case err
ad-do-it
(error (and (buffer-modified-p)
(not (ding))
(y-or-n-p "Buffer is modified, save it? ")
(save-buffer))
(er-refresh-etags extension)
ad-do-it))))
(defun er-refresh-etags (&optional extension)
"Run etags on all peer files in current dir and reload them silently."
(interactive)
(shell-command (format "etags *.%s" (or extension "el")))
(let ((tags-revert-without-query t)) ; don't query, revert silently
(visit-tags-table default-directory nil)))
(defun create-tags (dir-name)
"Create tags file."
(interactive "DDirectory: ")
(eshell-command
(format "find %s -type f -name \"*.[ch]\" | etags -" dir-name)))

57
init.el Normal file
View file

@ -0,0 +1,57 @@
;;
;; emacs configuration
;;
;; Made by Némunaire <nemunaire@nemunai.re>
(defun may-load (path)
"Load a file if it exists."
(when (file-readable-p path)
(load-file path)))
(defun reload ()
"Reload configuration file"
(interactive)
(load-file "~/.emacs.d/init.elc"))
;; Compile init file when it is modified
(defun byte-compile-current-buffer ()
"`byte-compile' current buffer if it's emacs-lisp-mode and compiled file exists."
(interactive)
(when (and (eq major-mode 'emacs-lisp-mode)
(file-exists-p (byte-compile-dest-file buffer-file-name)))
(byte-compile-file buffer-file-name)))
(add-hook 'after-save-hook 'byte-compile-current-buffer)
;; default emacs configuration directory
(defconst toc:emacs-config-dir "~/.emacs.d/configs/" "")
;; utility fonction to auto-load my package configurations
(defun toc:load-config-file (filelist)
(dolist (file filelist)
(message "Loading config file: %s..." file)
(load (expand-file-name
(concat toc:emacs-config-dir file)))
))
(add-to-list 'load-path "~/.emacs.d/stuff/")
(require 'my-autoload)
(require 'my-c-mode)
(require 'my-elisp)
(require 'my-font)
(require 'my-layout)
(require 'my-lisp-mode)
(require 'my-python-mode)
;; load my configuration files
(toc:load-config-file '("key-binding"
;; "project"
"editing"
"coding-style"
"tags"
"hooks"
"modes"
"mail"
"custom"
"perso"
))

512
stuff/edje-mode.el Normal file
View file

@ -0,0 +1,512 @@
;;; edje-mode-el -- Major mode for editing Edje files
;; Author: Gustavo Sverzut Barbieri <barbieri@gmail.com>
;; Created: 2007-07-23
;; Keywords: Edje major-mode
;; Url: http://barbieri-playground.googlecode.com/svn/dot-files/edje-mode.el
;; (if you find this file have problems, check that Url and request update)
;; Copyright (C) 2007 Gustavo Sverzut Barbieri <barbieri@gmail.com>
;; 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 2 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.
;; 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., 59 Temple Place, Suite 330, Boston,
;; MA 02111-1307 USA
;;; Commentary:
;;
;; This mode is based on tutorial from Scott Andrew Borton:
;; http://two-wugs.net/emacs/mode-tutorial.html
(defvar edje-mode-hook nil)
(defun number-or-nil-to-string (v &optional default)
(cond ((numberp v) (number-to-string v))
((stringp v) (if (string= v "") (number-to-string default) v))
(t (number-to-string default))))
(defun non-empty-string (s)
(and (not (eq 'nil s))
(not (string= "" s))))
(defun edje-new-program-action-signal-emit (source emission)
"Insert new program SIGNAL_EMIT"
(interactive "ssource: \nsemission: ")
(insert
(concat
" action: SIGNAL_EMIT \"" source "\" \"" emission "\";\n"
)))
(defun edje-new-program-action-state-set (state value target)
"Insert new program STATE_SET"
(interactive "sstate: \nsvalue (0.0): \nstarget: ")
(insert
(concat
" action: STATE_SET \"" state "\" "
(number-or-nil-to-string value 0.0) ";\n"
" target: \"" target "\";\n"
)))
(defun edje-new-program-action (action)
"Insert new program action"
(interactive "saction: ")
(setq action (upcase action))
(cond ((string= action "STATE_SET")
(edje-new-program-action-state-set "" 0.0 ""))
((string= action "SIGNAL_EMIT")
(edje-new-program-action-signal-emit "" ""))
))
(defun edje-new-program (name signal source action)
"Insert new program block"
(interactive "sname: \nssignal: \nssource: \nsaction: ")
(insert
(concat
"\n"
" program {\n"
" name: \"" name "\";\n"
(if (non-empty-string signal)
(concat " signal: \"" signal "\";\n"))
(if (non-empty-string source)
(concat " source: \"" source "\";\n"))
))
(edje-new-program-action action)
(insert
(concat
" }\n"
"\n"
)))
(defun edje-new-desc-relative (x y &optional defx defy)
"Insert new part description 'relative' line"
(interactive "sx: \nsy: ")
(insert
(concat
" relative: "
(number-or-nil-to-string x defx) " "
(number-or-nil-to-string y defy) ";\n"
)))
(defun edje-new-desc-offset (x y &optional defx defy)
"Insert new part description 'offset' line"
(interactive "sx: \nsy: ")
(insert
(concat
" offset: "
(number-or-nil-to-string x defx) " "
(number-or-nil-to-string y defy) ";\n"
)))
(defun edje-new-desc-inherit (name val)
"Insert new part description 'inherit' line"
(interactive "sname: \nsvalue: ")
(insert
(concat
" inherit: \"" name "\" "
(number-or-nil-to-string val 0.0) ";\n"
)))
(defun edje-new-desc-text (font size text)
"Insert new part description 'text' block"
(interactive "sfont: \nssize: \nstext: ")
(insert
(concat
" text {\n"
" font: \"" font "\";\n"
" size: " (number-or-nil-to-string size) ";\n"
" text: \"" text "\";\n"
" }\n"
)))
(defun edje-new-desc-image (name)
"Insert new part description 'image' block"
(interactive "sname: ")
(insert
(concat
" image {\n"
" normal: \"" name "\";\n"
" }\n"
)))
(defun edje-new-desc-color (r g b a &optional defr defg defb defa)
"Insert new part description 'color' line"
(interactive "sred: \nsgreen: \nsblue: \nsalpha: ")
(insert
(concat
" color: "
(number-or-nil-to-string r defr) " "
(number-or-nil-to-string g defg) " "
(number-or-nil-to-string b defb) " "
(number-or-nil-to-string a defa) ";\n"
)))
(defun edje-new-desc (name val &optional
r1_rx r1_ry
r2_rx r2_ry
r1_ox r1_oy
r2_ox r2_oy
part_type)
"Insert new part description block"
(interactive "sName: \nsValue: ")
(insert
(concat
" description {\n"
" state: \"" name "\" " (number-or-nil-to-string val 0.0) ";\n"))
(if (string= part_type "RECT") (edje-new-desc-color 255 255 255 255))
(insert " rel1 {\n")
(edje-new-desc-relative r1_rx r1_ry 0.0 0.0)
(edje-new-desc-offset r1_ox r1_oy 0 0)
(insert
(concat
" }\n"
" rel2 {\n"
))
(edje-new-desc-relative r2_rx r2_ry 1.0 1.0)
(edje-new-desc-offset r2_ox r2_oy -1 -1)
(insert " }\n")
(cond ((string= part_type "IMAGE") (edje-new-desc-image ""))
((string= part_type "TEXT") (edje-new-desc-text "" 10 "contents"))
)
(insert " }\n")
)
(defun edje-new-part (name type &optional
r1_rx r1_ry
r2_rx r2_ry
r1_ox r1_oy
r2_ox r2_oy)
"Insert new part"
(interactive "sName: \nsType: ")
(setq type (upcase type))
(insert
(concat
"\n"
" part {\n"
" name: \"" name "\";\n"
" type: " type ";\n"
" mouse_events: 0;\n"
))
(edje-new-desc "default" 0.0 r1_rx r1_ry r2_rx r2_ry r1_ox r1_oy r2_ox r2_oy type)
(insert
(concat
" }\n"
)))
(defun edje-setup-compile ()
(set (make-local-variable 'compile-command)
(concat "edje_cc " (buffer-file-name))
))
(defun edje-cc ()
"Runs edje_cc with current buffer."
(interactive)
(compile (edje-setup-compile)))
(defvar edje-mode-map
(let ((edje-mode-map (make-sparse-keymap)))
(define-key edje-mode-map "\C-j" 'newline-and-indent)
(define-key edje-mode-map "\C-cp" 'edje-new-part)
(define-key edje-mode-map "\C-cd" 'edje-new-desc)
(define-key edje-mode-map "\C-cr" 'edje-new-desc-relative)
(define-key edje-mode-map "\C-co" 'edje-new-desc-offset)
(define-key edje-mode-map "\C-ch" 'edje-new-desc-inherit)
(define-key edje-mode-map "\C-cc" 'edje-new-desc-color)
(define-key edje-mode-map "\C-ci" 'edje-new-desc-image)
(define-key edje-mode-map "\C-ct" 'edje-new-desc-text)
(define-key edje-mode-map "\C-cg" 'edje-new-program)
(define-key edje-mode-map "\C-ca" 'edje-new-program-action)
(define-key edje-mode-map "\C-cs" 'edje-new-program-action-state-set)
(define-key edje-mode-map "\C-ce" 'edje-new-program-action-signal-emit)
edje-mode-map)
"Keymap for Edje major mode")
(add-hook 'c-mode-hook 'edje-setup-compile)
(add-to-list 'auto-mode-alist '("\\.edc$" . edje-mode))
(defconst edje-font-lock-keywords-1
(eval-when-compile
(list
(list (concat "[ \t]*\\<"
(regexp-opt
'(
"collections"
"data"
"description"
"dragable"
"fill"
"fonts"
"group"
"image"
"images"
"origin"
"part"
"parts"
"program"
"programs"
"rel1"
"rel2"
"script"
"spectra"
"style"
"styles"
"text"
) t) "\\>\\([ \t]*{\\|\\.\\)")
'(1 font-lock-function-name-face))
))
"Major keywords")
(defconst edje-font-lock-keywords-2
(eval-when-compile
(append edje-font-lock-keywords-1
(list
(list
(concat "^\\([ \t]*\\|[ \t]*[a-z]+\\.\\|\\)\\<"
(regexp-opt
'("action"
"after"
"alias"
"align"
"angle"
"aspect"
"aspect_preference"
"base"
"border"
"clip_to"
"collections"
"color"
"color2"
"color3"
"color_class"
"color_classes"
"confine"
"data"
"description"
"dragable"
"effect"
"elipsis"
"events"
"fill"
"fit"
"fixed"
"font"
"fonts"
"gradient"
"group"
"ignore_flags"
"image"
"images"
"in"
"inherit"
"item"
"max"
"middle"
"min"
"mouse_events"
"name"
"normal"
"offset"
"origin"
"part"
"parts"
"pointer_mode"
"precise_is_inside"
"program"
"programs"
"rel1"
"rel2"
"relative"
"repeat_events"
"signal"
"size"
"smooth"
"source"
"spectra"
"spectrum"
"spread"
"state"
"step"
"style"
"styles"
"tag"
"target"
"text"
"text_class"
"text_source"
"to"
"to_x"
"to_y"
"transition"
"tween"
"type"
"use_alternate_font_metrics"
"visible"
"x"
"y"
) t) "\\>[ \t]*[:,]")
'(2 font-lock-keyword-face))
)))
"Minor keywords")
(defconst edje-font-lock-keywords-3
(eval-when-compile
(append edje-font-lock-keywords-2
(list
(list
(concat "\\<"
(regexp-opt
'(; image options (st_images_image)
"RAW"
"COMP"
"LOSSY"
"USER"
; part types (st_collections_group_parts_part_type)
"NONE"
"RECT"
"TEXT"
"IMAGE"
"SWALLOW"
"TEXTBLOCK"
"GRADIENT"
"GROUP"
; ignore flags (st_collections_group_parts_part_ignore_flags)
;"NONE"
"ON_HOLD"
; pointer mode (st_collections_group_parts_part_pointer_mode)
"AUTOGRAB"
"NOGRAB"
; aspect (st_collections_group_parts_part_description_aspect_preference)
"NONE"
"VERTICAL"
"HORIZONTAL"
"BOTH"
; text effect (st_collections_group_parts_part_effect)
"NONE"
"PLAIN"
"OUTLINE"
"SOFT_OUTLINE"
"SHADOW"
"SOFT_SHADOW"
"OUTLINE_SHADOW"
"OUTLINE_SOFT_SHADOW"
"FAR_SHADOW"
"FAR_SOFT_SHADOW"
"GLOW"
; image fill (st_collections_group_parts_part_description_fill_type)
"SCALE"
"TILE"
; program action (st_collections_group_programs_program_action)
"STATE_SET"
"ACTION_STOP"
"SIGNAL_EMIT"
"DRAG_VAL_SET"
"DRAG_VAL_STEP"
"DRAG_VAL_PAGE"
"SCRIPT"
; program transition (st_collections_group_programs_program_transition)
"LINEAR"
"SINUSOIDAL"
"ACCELERATE"
"DECELERATE"
) t) "\\>")
'(1 font-lock-builtin-face))
)))
"Enumerate values")
(defconst edje-font-lock-keywords-4
(eval-when-compile
(append edje-font-lock-keywords-3
(list
(list
(concat "[ \t]*#"
(regexp-opt
'("if"
"ifdef"
"ifndef"
"define"
"else"
"endif"
"include"
"undef") t) "[ \t]*")
'(1 font-lock-builtin-face))
)))
"CPP directives")
(defconst edje-font-lock-keywords-5
(eval-when-compile
(append edje-font-lock-keywords-4
(list
(list "[ \t]*#undef[ \t]+\\([a-zA-Z_][a-zA-Z0-9_]*\\)"
'(1 font-lock-variable-name-face))
(list "[ \t]*#define[ \t]+\\([a-zA-Z_][a-zA-Z0-9_]*\\)("
'(1 font-lock-function-name-face))
(list "[ \t]*#define[ \t]+\\([a-zA-Z_][a-zA-Z0-9_]*\\)"
'(1 font-lock-variable-name-face))
)))
"CPP directives that define constants")
(defvar edje-font-lock-keywords edje-font-lock-keywords-5)
(defvar edje-mode-syntax-table
(let ((edje-mode-syntax-table (make-syntax-table)))
; This is added so entity names with underscores can be more easily parsed
(modify-syntax-entry ?_ "w" edje-mode-syntax-table)
(modify-syntax-entry ?/ ". 124b" edje-mode-syntax-table)
(modify-syntax-entry ?* ". 23" edje-mode-syntax-table)
(modify-syntax-entry ?\n "> b" edje-mode-syntax-table)
edje-mode-syntax-table)
"Syntax table for edje-mode")
(c-add-style
"edje"
'("gnu"
(indent-tabs-mode . nil)
(tab-width . 8)
(c-basic-offset . 3)
(c-backslash-column . 72)
(c-hanging-braces-alist .
((block-open after)
(brace-list-open after)
(substatement-open after))
)
(c-offsets-alist .
((statement-block-intro . +)
(defun-open . 0)
(substatement-open . 0)
(defun-block-intro . +)
(block-open . 0)
(label . +)
))))
(define-derived-mode edje-mode c-mode "Edje"
"Major mode for editing Edje files"
(interactive)
(use-local-map edje-mode-map)
(set-syntax-table edje-mode-syntax-table)
(set (make-local-variable 'font-lock-defaults) '(edje-font-lock-keywords))
(set (make-local-variable 'require-final-newline) t)
(c-set-style "edje")
(run-hooks 'edje-mode-hook)
)
(provide 'edje-mode)
;;; edje-mode.el ends here

242
stuff/find-cmd.el Normal file
View file

@ -0,0 +1,242 @@
;;; find-cmd.el --- Build a valid find(1) command with sexps
;; Copyright (C) 2008, 2009 Free Software Foundation, Inc.
;; Author: Philip Jackson <phil@shellarchive.co.uk>
;; Version: 0.6
;; This file is part of GNU Emacs.
;; GNU Emacs 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.
;; GNU Emacs 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 GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; With this module you can build up a (hopefully) valid find(1)
;; string ready for the command line. For example:
;; (find-cmd '(prune (name ".svn" ".git" ".CVS"))
;; '(and (or (name "*.pl" "*.pm" "*.t")
;; (mtime "+1"))
;; (fstype "nfs" "ufs"))))
;; will become (un-wrapped):
;; "find '/home/phil/' \\( \\( -name '.svn' -or -name '.git' -or
;; -name '.CVS' \\) -prune -or -true \\) \\( \\( \\( -name '*.pl'
;; -or -name '*.pm' -or -name '*.t' \\) -or -mtime '+1' \\) -and \\(
;; -fstype 'nfs' -or -fstype 'ufs' \\) \\)"
;;; Code:
(defconst find-constituents
'((and . find-and)
(not . find-not)
(or . find-or)
(a . find-and)
(n . find-not)
(o . find-or)
(prune . find-prune)
;; switches
(L . (0))
(P . (0))
(H . (0))
;; generic tests
(amin . (1))
(anewer . (1))
(atime . (1))
(cmin . (1))
(cnewer . (1))
(ctime . (1))
(empty . (0))
(false . (0))
(fstype . (1))
(gid . (1))
(group . (1))
(ilname . (1))
(iname . (1))
(inum . (1))
(iwholename . (1))
(iregex . (1))
(links . (1))
(lname . (1))
(mmin . (1))
(mtime . (1))
(name . (1))
(newer . (1))
(nouser . (0))
(nogroup . (0))
(path . (1))
(perm . (0))
(regex . (1))
(wholename . (1))
(size . (1))
(true . (0))
(type . (1))
(uid . (1))
(used . (1))
(user . (1))
(xtype . (nil))
;; normal options (always true)
(depth . (0))
(maxdepth . (1))
(mindepth . (1))
(mount . (0))
(noleaf . (0))
(xdev . (0))
(ignore_readdir_race . (0))
(noignore_readdir_race . (0))
;; actions
(delete . (0))
(print0 . (0))
(printf . (1))
(fprintf . (2))
(print . (0))
(fprint0 . (1))
(fprint . (1))
(ls . (0))
(fls . (1))
(prune . (0))
(quit . (0))
;; these need to be terminated with a ;
(exec . (1 find-command t))
(ok . (1 find-command t))
(execdir . (1 find-command t))
(okdir . (1 find-command t)))
"Holds details of each of the find options. The car of each
alist is the name. The cdr is minimum args, the function used
to join many occurences of the argument together, and whether or
not to leave quotes off the string (non-nil means the string will
be quoted).")
;;;###autoload
(defun find-cmd (&rest subfinds)
"Initiate the building of a find command. For exmple:
\(find-cmd '\(prune \(name \".svn\" \".git\" \".CVS\"\)\)
'\(and \(or \(name \"*.pl\" \"*.pm\" \"*.t\"\)
\(mtime \"+1\"\)\)
\(fstype \"nfs\" \"ufs\"\)\)\)\)
`default-directory' is used as the initial search path. The
result is a string that should be ready for the command line."
(concat
"find " (shell-quote-argument (expand-file-name default-directory)) " "
(cond
((cdr subfinds)
(mapconcat 'find-to-string subfinds ""))
(t
(find-to-string (car subfinds))))))
(defun find-and (form)
"And FORMs together, so:
\(and \(mtime \"+1\"\) \(name \"something\"\)\)
will produce:
find . \\\( -mtime '+1' -and -name 'something' \\\)"
(if (< (length form) 2)
(find-to-string (car form))
(concat "\\( "
(mapconcat 'find-to-string form "-and ")
"\\) ")))
(defun find-or (form)
"Or FORMs together, so:
\(or \(mtime \"+1\"\) \(name \"something\"\)\)
will produce:
find . \\\( -mtime '+1' -or -name 'something' \\\)"
(if (< (length form) 2)
(find-to-string (car form))
(concat "\\( "
(mapconcat 'find-to-string form "-or ")
"\\) ")))
(defun find-not (form)
"Or FORMs together and prefix with a -not, so:
\(not \(mtime \"+1\"\) \(name \"something\"\)\)
will produce:
-not \\\( -mtime '+1' -or -name 'something' \\\)
If you wanted the FORMs -and(ed) together instead then this would
suffice:
\(not \(and \(mtime \"+1\"\) \(name \"something\"\)\)\)"
(concat "-not " (find-or (mapcar 'find-to-string form))))
(defun find-prune (form)
"-or together FORM(s) postfix '-prune' and then -or that with a
-true, so:
\(prune \(name \".svn\" \".git\"\)\) \(name \"*.pm\"\)
will produce (unwrapped):
\\\( \\\( \\\( -name '.svn' -or -name '.git' \\\) /
-prune -or -true \\\) -and -name '*.pm' \\\)"
(find-or
(list
(concat (find-or (mapcar 'find-to-string form)) (find-generic "prune"))
(find-generic "true"))))
(defun find-generic (option &optional oper argcount args dont-quote)
"This function allows an arbitrary string to be used as a
form. OPTION is the name of the form, OPER is the function used
to either OR or AND multiple results together. ARGCOUNT is the
minimum of args that OPTION can receive and ARGS are the
arguments for OPTION."
(when (and (numberp argcount) (< (length args) argcount))
(error "'%s' needs at least %d arguments" option argcount))
(let ((oper (or oper 'find-or)))
(if (and args (length args))
(funcall oper (mapcar (lambda (x)