From: Christoph Egger Date: Fri, 6 Nov 2015 13:53:42 +0000 (+0100) Subject: Import elisp libraries X-Git-Url: https://git.siccegge.de//index.cgi?a=commitdiff_plain;ds=inline;h=150a2864e2a975b540a16c12d06e0ba00ae59553;p=dotfiles%2Femacs.git Import elisp libraries --- diff --git a/lisp/dpaste.el b/lisp/dpaste.el new file mode 100644 index 0000000..66efe16 --- /dev/null +++ b/lisp/dpaste.el @@ -0,0 +1,100 @@ +;;; pastebin.el --- A simple interface to the www.pastebin.com webservice + +;;; Copyright (C) 2008 by Tapsell-Ferrier Limited + +;;; 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, 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; see the file COPYING. If not, write to the +;;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +;;; Boston, MA 02110-1301 USA + +;;; Commentary: +;;; +;;; Load this file and run: +;;; +;;; M-x pastebin-buffer +;;; +;;; to send the whole buffer or select a region and run +;;; +;;; M-x pastebin +;;; +;;; to send just the region. +;;; +;;; In either case the url that pastebin generates is left on the kill +;;; ring and the paste buffer. + + +;;; Code: + +(defvar dpastebin-type-assoc + '((emacs-lisp-mode . "887") + (scheme-mode . "887") + (python-mode . "795") + (nxml-mode . "840"))) + +(defvar dpastebin-retrieved nil) + +(defvar dpastebin-expire-history '()) + +(defun dpastebin-buffer (&optional expire) + "Send the whole buffer to paste.q0a.de." + (interactive (if current-prefix-arg + (list (read-string "pastebin expire:" nil 'dpastebin-expire-history)))) + (dpastebin (point-min) (point-max) expire)) + +(defun dpastebin (start end &optional expire) + "An interface to the pastebin code snippet www service. + +See pastebin.com for more information about pastebin. + +Called interactively pastebin uses the current region for +preference for sending... if the mark is NOT set then the entire +buffer is sent. + +Argument START is the start of region. +Argument END is the end of region. + +If PREFIX is used pastebin prompts for a prefix to be used as the +virtual host to use. For example use 'emacs' for 'emacs.pastebin.com'." + (interactive + (let ((pastebin-expire + (if current-prefix-arg + (read-string "pastebin expire:" nil 'dpastebin-expire-history)))) + (if (mark) + (list (region-beginning) (region-end) pastebin-expire) + (list (point-min) (point-max) pastebin-expire)))) + ;; Main function + (let* ((data (buffer-substring-no-properties start end)) + (pastebin-url (format "http://paste.debian.net")) + (url-request-method "POST") + (url-request-extra-headers + '(("Content-Type" . "multipart/form-data"))) + (url-request-data + (concat (format "paste=Send&lang=%s&expiry=%s&poster=%s&code=%s" + (assoc-default major-mode dpastebin-type-assoc nil "878") + (or expire "d") + (user-full-name) + (url-hexify-string data)))) + (content-buf (url-retrieve pastebin-url + (lambda (arg) + (cond + ((equal :error (car arg)) + (message (cdr arg))) + ((equal :redirect (car arg)) + (setq pastebin-retrieved (cadr arg)) + (with-temp-buffer + (insert pastebin-retrieved) + (clipboard-kill-ring-save (point-min) (point-max))))))))) + (car kill-ring))) + +(provide 'debian-pastebin) +;;; pastebin.el ends here diff --git a/lisp/smart-tabs-mode.el b/lisp/smart-tabs-mode.el new file mode 100644 index 0000000..5a0c952 --- /dev/null +++ b/lisp/smart-tabs-mode.el @@ -0,0 +1,320 @@ +;;; smart-tabs-mode.el --- Intelligently indent with tabs, align with spaces! + +;; Copyright © 2011 John Croisant +;; Copyright © 2011 Joel C. Salomon +;; Copyright © 2012 Alan Pearce +;; Copyright © 2012 Daniel Dehennin +;; Copyright © 2013 Matt Renaud + +;; Author: John Croisant +;; Alan Pearce +;; Daniel Dehennin +;; Matt Renaud +;; Maintainer: Joel C. Salomon +;; URL: http://www.emacswiki.org/emacs/SmartTabs +;; Created: 19 Sep 2011 +;; Version: 1.0 +;; Keywords: languages + +;; This file is not part of GNU Emacs. + +;;; License: + +;; 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 of the License, 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 file. If not, see . + +;;; Commentary: + +;; This package provide a semantic way of using tab characters in +;; source code: tabs for indentation, spaces for alignment. +;; +;; It is derived from +;; with modifications by the various authors listed above. +;; +;; Modification history is at . + +;;; Installation: + +;; The easiest and preferred way to install smart-tabs-mode is to use +;; the package available on MELPA. +;; +;; Manual installation: +;; +;; Save smart-tabs-mode.el to a a directory on your load-path +;; (e.g., ~/.emacs.d/elisp), then add the following to your .emacs file: +;; +;; (autoload 'smart-tabs-mode "smart-tabs-mode" +;; "Intelligently indent with tabs, align with spaces!") +;; (autoload 'smart-tabs-mode-enable "smart-tabs-mode") +;; (autoload 'smart-tabs-advice "smart-tabs-mode") +;; (autoload 'smart-tabs-insinuate "smart-tabs-mode") +;; + +;;; Enabling smart-tabs-mode within language modes: + +;; As of version 1.0 of this package, the easiest and preferred way to +;; enable smart-tabs-mode is with the smart-tabs-insinuate function; +;; for example, +;; +;; (smart-tabs-insinuate 'c 'c++ 'java 'javascript 'cperl 'python +;; 'ruby 'nxml) +;; +;; will enable smart-tabs-mode with all supported language modes. +;; +;; (See below for instructions on adding additional language support.) +;; +;; The old method of manually enabling smart-tabs-mode is still +;; available, but is no longer recommended; smart-tabs-insinuate +;; wraps the functionality below in a convenient manner. +;; +;; For reference, the basic manual method looks like this: +;; +;; (add-hook 'MODE-HOOK 'smart-tabs-mode-enable) +;; (smart-tabs-advice INDENT-FUNC TAB-WIDTH-VAR) +;; +;; Note that it might be preferable to delay calling smart-tabs-advice +;; until after the major mode is loaded and evaluated, so the lines +;; above would be better written like this: +;; +;; (add-hook 'MODE-HOOK (lambda () +;; (smart-tabs-mode-enable) +;; (smart-tabs-advice INDENT-FUNC TAB-WIDTH-VAR))) +;; +;; Here are some specific examples for a few popular languages: +;; +;; ;; C +;; (add-hook 'c-mode-hook 'smart-tabs-mode-enable) +;; (smart-tabs-advice c-indent-line c-basic-offset) +;; (smart-tabs-advice c-indent-region c-basic-offset) +;; +;; ;; JavaScript +;; (add-hook 'js2-mode-hook 'smart-tabs-mode-enable) +;; (smart-tabs-advice js2-indent-line js2-basic-offset) +;; +;; ;; Perl (cperl-mode) +;; (add-hook 'cperl-mode-hook 'smart-tabs-mode-enable) +;; (smart-tabs-advice cperl-indent-line cperl-indent-level) +;; +;; ;; Python +;; (add-hook 'python-mode-hook 'smart-tabs-mode-enable) +;; (smart-tabs-advice python-indent-line-1 python-indent) + +;;; Adding language support + +;; Language support can be added through the use of the macro +;; `smart-tabs-add-language-support'. Pass in the symbol you wish +;; to use to identify the language, the mode hook, and a list +;; of cons cells containing (indent-line-function . offset-variable). +;; For example, if C++ mode was not provided by default it could be +;; added as follows: +;; +;; (smart-tabs-add-language-support c++ c++-mode-hook +;; ((c-indent-line . c-basic-offset) +;; (c-indent-region . c-basic-offset))) +;; +;; NOTE: All language support must be added before the call to +;; `smart-tabs-insinuate'. + +;;; Code: + +(require 'advice) +(require 'cl-lib) + +(defvar smart-tabs-mode nil + "Define if smart-tabs-mode is enabled") + + +;;;###autoload +(defmacro smart-tabs-when (condition advice-list) + (declare (indent 1)) + `(when ,condition + ,@(smart-tabs-create-advice-list advice-list))) + + +;;;###autoload +(defmacro smart-tabs-create-advice-list (advice-list) + `(cl-loop for (func . offset) in ,advice-list + collect `(smart-tabs-advice ,func ,offset))) + + +;;;###autoload +(defmacro smart-tabs-create-language-advice (lang mode-hook advice-list &rest body) + "Create a cons cell containing the actions to take to enable +`smart-tabs-mode' for the language LANG. This usually involved enabling +`smart-tabs-mode' through `smart-tabs-mode-enable' and adding a lambda +function to the MODE-HOOK for the specified language. This macro +simplifies the creation of such a cons cell." + (declare (indent 2)) + `'(,lang . (lambda () + (add-hook ',mode-hook + (lambda () + (smart-tabs-mode-enable) + ,@(smart-tabs-create-advice-list advice-list) + ,@(cl-loop for form in body + collect (macroexpand form))))))) + + +(defvar smart-tabs-insinuate-alist + `(,(smart-tabs-create-language-advice c c-mode-hook + ((c-indent-line . c-basic-offset) + (c-indent-region . c-basic-offset))) + + ,(smart-tabs-create-language-advice c++ c++-mode-hook + ((c-indent-line . c-basic-offset) + (c-indent-region . c-basic-offset))) + + ,(smart-tabs-create-language-advice java java-mode-hook + ((c-indent-line . c-basic-offset) + (c-indent-region . c-basic-offset))) + + ,(smart-tabs-create-language-advice javascript js2-mode-hook + ((js2-indent-line . js2-basic-offset))) + + ,(smart-tabs-create-language-advice cperl cperl-mode-hook + ((cperl-indent-line . cperl-indent-level))) + + ,(smart-tabs-create-language-advice python python-mode-hook + ((python-indent-line . python-indent-offset) + (python-indent-region . python-indent-offset)) + (smart-tabs-when (featurep 'python-mode) + ((py-indent-line . py-indent-offset) + (py-newline-and-indent . py-indent-offset) + (py-indent-region . py-indent-offset)))) + + ,(smart-tabs-create-language-advice ruby ruby-mode-hook + ((ruby-indent-line . ruby-indent-level))) + + ,(smart-tabs-create-language-advice nxml nxml-mode-hook + ((nxml-indent-line . nxml-child-indent)))) + + "Alist of language name and their activation code. +Smarttabs is enabled in mode hook.") + + + +(defmacro smart-tabs-mode/no-tabs-mode-advice (function) + `(unless (ad-find-advice ',function 'around 'smart-tabs) + (defadvice ,function (around smart-tabs activate) + (if smart-tabs-mode + (let ((indent-tabs-mode nil)) ad-do-it) + ad-do-it)))) + +;;;###autoload +(define-minor-mode smart-tabs-mode + "Intelligently indent with tabs, align with spaces!" + + (progn + (smart-tabs-mode/no-tabs-mode-advice align) + (smart-tabs-mode/no-tabs-mode-advice align-regexp) + (smart-tabs-mode/no-tabs-mode-advice indent-relative) + (smart-tabs-mode/no-tabs-mode-advice comment-dwim) + (smart-tabs-mode/no-tabs-mode-advice comment-box) + (smart-tabs-mode/no-tabs-mode-advice comment-indent) + + (unless + (ad-find-advice 'indent-according-to-mode 'around 'smart-tabs) + (defadvice indent-according-to-mode (around smart-tabs activate) + (if smart-tabs-mode + (let ((indent-tabs-mode indent-tabs-mode)) + (if (memq indent-line-function + '(indent-relative + indent-relative-maybe)) + (setq indent-tabs-mode nil)) + ad-do-it) + ad-do-it))) + )) + +;;;###autoload +(defun smart-tabs-mode-enable () + "Enable smart-tabs-mode." + (smart-tabs-mode t)) + +;;;###autoload +(defmacro smart-tabs-advice (function offset) + `(progn + (defadvice ,function (around smart-tabs activate) + (cond + (smart-tabs-mode + (save-excursion + (beginning-of-line) + (while (looking-at "\t*\\( +\\)\t+") + (replace-match "" nil nil nil 1))) + (setq tab-width tab-width) + (let ((indent-tabs-mode t) + (tab-width fill-column) + (,offset fill-column)) + (unwind-protect + (progn ad-do-it)))) + (t + ad-do-it))))) + +;;;###autoload +(defun smart-tabs-insinuate (&rest languages) + "Enable smart-tabs-mode for LANGUAGES. +LANGUAGES is a list of SYMBOL or NAME as defined in +'smart-tabs-insinuate-alist' alist or a language using standard named +indent function and indent level. +" + (mapc (lambda (lang) + (let ((lang-map (assoc lang smart-tabs-insinuate-alist)) + (lang-param (smart-tabs-get-standard-language lang))) + (cond ((and (null lang-map) + (not (null (car lang-param))) + (not (null (nth 1 lang-param))) + (not (null (nth 2 lang-param)))) + (smart-tabs-guess-insinuate lang-param)) + ((null lang-map) + (error (format "Unknown smart-tab-mode capable language '%s'" lang))) + (t (funcall (cdr lang-map)))))) + languages)) + + +;;;###autoload +(defmacro smart-tabs-add-language-support (lang mode-hook advice-list &rest body) + "Add support for a language not already in the `smart-tabs-insinuate-alist'." + (declare (indent 2)) + `(add-to-list + 'smart-tabs-insinuate-alist + (smart-tabs-create-language-advice ,lang ,mode-hook + ,advice-list ,@body))) + + +(defun smart-tabs-guess-insinuate (lang-param) + "Enable smart-tabs-mode if language respect standard naming. +Several languages define a '-indent-line' function and +'-indent-level' variable to control indentation. +LANG-PARAM is a list of HOOK INDENT-FUNCTION INDENT-LEVEL, if +thoses are defined, we use them." + (let ((lang-hook (car lang-param)) + (indent-function (nth 1 lang-param)) + (indent-level (nth 2 lang-param))) + (if (and (not (null lang-hook)) + (and (not (null indent-function)) + (fboundp indent-function)) + (and (not (null indent-level)) + (boundp indent-level))) + (add-hook lang-hook + `(lambda () + (smart-tabs-mode-enable) + (smart-tabs-advice ,indent-function ,indent-level)))))) + +(defun smart-tabs-get-standard-language (language) + "Return a list of HOOK INDENT-FUNCTION INDENT-LEVEL for a language." + (let ((indent-function (intern-soft (concat (symbol-name language) "-indent-line"))) + (indent-level (intern-soft (concat (symbol-name language) "-indent-level"))) + (lang-hook (intern-soft (concat (symbol-name language) "-mode-hook")))) + (list lang-hook indent-function indent-level))) + +(provide 'smart-tabs-mode) + +;;; smart-tabs-mode.el ends here