From 49e74cc3638d94de7a9ba9a0e9abc397ed938e73 Mon Sep 17 00:00:00 2001 From: Rodolphe Breard Date: Sat, 23 Mar 2013 15:41:47 +0100 Subject: [PATCH] emacs --- .emacs.d/init.el | 8 + .emacs.d/modes.el | 20 +++ .emacs.d/std_comment.el | 344 ++++++++++++++++++++++++++++++++++++++++ .gitignore | 2 + 4 files changed, 374 insertions(+) create mode 100755 .emacs.d/init.el create mode 100644 .emacs.d/modes.el create mode 100644 .emacs.d/std_comment.el create mode 100644 .gitignore diff --git a/.emacs.d/init.el b/.emacs.d/init.el new file mode 100755 index 0000000..286e8b5 --- /dev/null +++ b/.emacs.d/init.el @@ -0,0 +1,8 @@ +(add-to-list 'load-path "/usr/share/emacs/site-lisp") +(add-to-list 'load-path "~/.emacs.d") + +(load "modes.el") +(load "std_comment.el") + +(setq column-number-mode t) +(setq x-alt-keysym 'meta) diff --git a/.emacs.d/modes.el b/.emacs.d/modes.el new file mode 100644 index 0000000..3e12467 --- /dev/null +++ b/.emacs.d/modes.el @@ -0,0 +1,20 @@ +;; Python +(autoload 'python-mode "python-mode.el" "Python mode." t) +(setq auto-mode-alist (append '(("/*.\.python$" . python-mode)) auto-mode-alist)) +(setq auto-mode-alist (append '(("/*.\.py$" . python-mode)) auto-mode-alist)) + +;; LUA +(autoload 'lua-mode "lua-mode" "Lua editing mode." t) +(setq auto-mode-alist (cons '("\.lua$" . lua-mode) auto-mode-alist)) + +;; PHP +(autoload 'php-mode "php-mode.el" "Php mode." t) +(setq auto-mode-alist (append '(("/*.\.php[0-9]?$" . php-mode)) auto-mode-alist)) + +;; MarkDown +(autoload 'markdown-mode "markdown-mode.el" "Markdown mode." t) +(setq auto-mode-alist (cons '("\.markdown$" . markdown-mode) auto-mode-alist)) +(setq auto-mode-alist (cons '("\.md$" . markdown-mode) auto-mode-alist)) + +;; JSON +(setq auto-mode-alist (cons '("\.json$" . js-mode) auto-mode-alist)) diff --git a/.emacs.d/std_comment.el b/.emacs.d/std_comment.el new file mode 100644 index 0000000..e4bf3d4 --- /dev/null +++ b/.emacs.d/std_comment.el @@ -0,0 +1,344 @@ +;; +;; std_comment.el for Emacs in ~/.emacs.d +;; +;; Made by Frederic Denis +;; Improved by Rodolphe Breard +;; +;; Based on Comment routines by Isaac +;; + +(global-set-key "" 'do_insert_time) +(global-set-key "" 'std-file-header) + +(setq header-copyright "Copyright (c) ") +(if (setq user-nickname (getenv "USER_NICKNAME")) + t + (setq user-nickname (user-full-name)) + ) + +(setq std-c-alist '( (cs . "/*") (cc . " * ") (ce . " */") ) + std-css-alist '( (cs . "/*") (cc . "** ") (ce . "*/") ) + std-cpp-alist '( (cs . "//") (cc . "// ") (ce . "//") ) + std-pov-alist '( (cs . "//") (cc . "// ") (ce . "//") ) + std-python-alist '( (cs . "##") (cc . "## ") (ce . "##") ) + std-java-alist '( (cs . "//") (cc . "// ") (ce . "//") ) + std-javascript-alist '( (cs . "//") (cc . "// ") (ce . "//") ) + std-latex-alist '( (cs . "%%") (cc . "%% ") (ce . "%%") ) + std-lisp-alist '( (cs . ";;") (cc . ";; ") (ce . ";;") ) + std-xdefault-alist '( (cs . "!!") (cc . "!! ") (ce . "!!") ) + std-pascal-alist '( (cs . "{ ") (cc . " ") (ce . "}" ) ) + std-makefile-alist '( (cs . "##") (cc . "## ") (ce . "##") ) + std-markdown-alist '( (cs . "") ) + std-text-alist '( (cs . "##") (cc . "## ") (ce . "##") ) + std-fundamental-alist '( (cs . " ") (cc . " ") (ce . " ") ) + std-html-alist '( (cs . "")) + std-php-alist '( (cs . ".\n") + ) + +(setq license-agpl + '("This program is free software: you can redistribute it and/or modify\n" + "it under the terms of the GNU Affero General Public License as published by\n" + "the Free Software Foundation, either version 3 of the License, or\n" + "(at your option) any later version.\n" + "\n" + "This program is distributed in the hope that it will be useful,\n" + "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" + "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" + "GNU Affero General Public License for more details.\n" + "\n" + "You should have received a copy of the GNU Affero General Public License\n" + "along with this program. If not, see .\n" + "\n") + ) + +(setq license-lgpl + '("This library is free software; you can redistribute it and/or\n" + "modify it under the terms of the GNU Lesser General Public\n" + "License as published by the Free Software Foundation; either\n" + "version 3 of the License, or (at your option) any later version.\n" + "\n" + "This library is distributed in the hope that it will be useful,\n" + "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" + "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n" + "Lesser General Public License for more details.\n" + "\n" + "You should have received a copy of the GNU General Public License\n" + "along with this program. If not, see .\n") + ) + +(setq license-fdl + '("Permission is granted to copy, distribute and/or modify this document\n" + "under the terms of the GNU Free Documentation License, Version 1.3\n" + "or any later version published by the Free Software Foundation;\n" + "with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.\n" + "A copy of the license is included in the section entitled \"GNU\n" + "Free Documentation License\".\n") + ) + +(setq license-bsd + '("Redistribution and use in source and binary forms, with or without\n" + "modification, are permitted provided that the following conditions are\n" + "met:\n" + "\n" + " 1. Redistributions of source code must retain the above copyright\n" + " notice, this list of conditions and the following disclaimer.\n" + "\n" + " 2. Redistributions in binary form must reproduce the above copyright\n" + " notice, this list of conditions and the following disclaimer in the\n" + " documentation and/or other materials provided with the distribution.\n" + "\n" + " 3. The name of the author may not be used to endorse or promote\n" + " products derived from this software without specific prior written\n" + " permission.\n" + "\n" + "THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR\n" + "IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n" + "WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\n" + "DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,\n" + "INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\n" + "(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\n" + "SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\n" + "HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\n" + "STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING\n" + "IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n" + "POSSIBILITY OF SUCH DAMAGE.\n") + ) + +(setq license-isc + '("Permission to use, copy, modify, and/or distribute this software for any\n" + "purpose with or without fee is hereby granted, provided that the above\n" + "copyright notice and this permission notice appear in all copies.\n" + "\n" + "THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES\n" + "WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF\n" + "MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR\n" + "ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES\n" + "WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN\n" + "ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF\n" + "OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.\n") + ) + +(defun std-file-header () + "Puts a standard header at the beginning of the file.\n(According to mode)" + (interactive) + (goto-char (point-min)) + (let ((projname "toto")(location "titi")) + (setq license (read-from-minibuffer + (format "License ? : "))) + (setq location (getenv "PWD")) + + (insert-string (std-get 'cs)) + (newline) + (insert-string (concat (std-get 'cc) + header-copyright + (format-time-string "%Y" (current-time)) + " " + user-nickname)) + (newline) + (setq ltow nil) + (if (string= license "gpl") + (setq ltow license-gpl3)) + (if (string= license "gpl3") + (setq ltow license-gpl3)) + (if (string= license "gpl2") + (setq ltow license-gpl2)) + (if (string= license "agpl") + (setq ltow license-agpl)) + (if (string= license "lgpl") + (setq ltow license-lgpl)) + (if (string= license "fdl") + (setq ltow license-fdl)) + (if (string= license "bsd") + (setq ltow license-bsd)) + (if (string= license "isc") + (setq ltow license-isc)) + (if (string= license "beer") + (setq ltow license-beer)) + (if ltow + (progn + (insert-string (std-get 'cc)) + (newline) + (while ltow + (insert-string (concat (std-get 'cc) + (car ltow))) + (setq ltow (cdr ltow))) + ;(insert-string (std-get 'ce)) + ;(newline) + )) + (insert-string (std-get 'ce)) + (newline))) + + +(defun insert-std-vertical-comments () + "Inserts vertical comments (according to mode)." + (interactive) + (beginning-of-line) + (insert-string (std-get 'cs)) + (newline) + (let ((ok t)(comment "")) + (while ok + (setq comment (read-from-minibuffer + (format "Type comment (RETURN to quit) : "))) + (if (= 0 (length comment)) + (setq ok nil) + (progn + (insert-string (concat (std-get 'cc) comment)) + (newline))))) + (insert-string (std-get 'ce)) + (newline)) + +(defun std-toggle-comment () + "Toggles line comment on or off (according to mode)." + (interactive) + (save-excursion + (let (beg end) + (beginning-of-line) + (setq beg (point)) + (end-of-line) + (setq end (point)) + (save-restriction + (if (not (equal beg end)) + (progn + (narrow-to-region beg end) + (goto-char beg) + (if (search-forward (std-get 'cs) end t) + (progn + (beginning-of-line) + (replace-string (std-get 'cs) "") + (replace-string (std-get 'ce) "")) + (progn + (beginning-of-line) + (insert-string (std-get 'cs)) + (end-of-line) + (insert-string (std-get 'ce))))))))) + ;; (indent-according-to-mode) + (indent-for-tab-command) + (next-line 1)) + +;;;; Generating local keymaps for exotics modes. + +;;; In CPerl mode, C-c C-h is used to do some help. +;;; so it is C-c C-h h +;;; For working, it requires info pages about perl +(add-hook 'cperl-mode-hook + '(lambda () + (define-key cperl-mode-map "" + 'comment-region) + (define-key cperl-mode-map "h" + 'std-file-header))) + +;; for perl-mode +(add-hook 'perl-mode-hook + '(lambda () + (define-key perl-mode-map "" + 'comment-region))) + +;; for all kind of lisp code +(add-hook 'emacs-lisp-mode-hook + '(lambda () + (define-key emacs-lisp-mode-map "" + 'comment-region))) + +(add-hook 'lisp-mode-hook + '(lambda () + (define-key lisp-mode-map "" + 'comment-region))) + + + +;; for La(TeX)-mode +(add-hook 'tex-mode-hook + '(lambda () + (define-key tex-mode-map "" + 'comment-region))) + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a347f1f --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*~ +.emacs.d/auto-save-list/