+++ /dev/null
-;=============================================================================
-; CMake - Cross Platform Makefile Generator
-; Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
-;
-; Distributed under the OSI-approved BSD License (the "License");
-; see accompanying file Copyright.txt for details.
-;
-; This software is distributed WITHOUT ANY WARRANTY; without even the
-; implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-; See the License for more information.
-;=============================================================================
-;;; cmake-mode.el --- major-mode for editing CMake sources
-
-;------------------------------------------------------------------------------
-
-;;; Commentary:
-
-;; Provides syntax highlighting and indentation for CMakeLists.txt and
-;; *.cmake source files.
-;;
-;; Add this code to your .emacs file to use the mode:
-;;
-;; (setq load-path (cons (expand-file-name "/dir/with/cmake-mode") load-path))
-;; (require 'cmake-mode)
-;; (setq auto-mode-alist
-;; (append '(("CMakeLists\\.txt\\'" . cmake-mode)
-;; ("\\.cmake\\'" . cmake-mode))
-;; auto-mode-alist))
-
-;------------------------------------------------------------------------------
-
-;;; Code:
-;;
-;; cmake executable variable used to run cmake --help-command
-;; on commands in cmake-mode
-;;
-;; cmake-command-help Written by James Bigler
-;;
-
-(defcustom cmake-mode-cmake-executable "cmake"
- "*The name of the cmake executable.
-
-This can be either absolute or looked up in $PATH. You can also
-set the path with these commands:
- (setenv \"PATH\" (concat (getenv \"PATH\") \";C:\\\\Program Files\\\\CMake 2.8\\\\bin\"))
- (setenv \"PATH\" (concat (getenv \"PATH\") \":/usr/local/cmake/bin\"))"
- :type 'file
- :group 'cmake)
-;;
-;; Regular expressions used by line indentation function.
-;;
-(defconst cmake-regex-blank "^[ \t]*$")
-(defconst cmake-regex-comment "#.*")
-(defconst cmake-regex-paren-left "(")
-(defconst cmake-regex-paren-right ")")
-(defconst cmake-regex-argument-quoted
- "\"\\([^\"\\\\]\\|\\\\\\(.\\|\n\\)\\)*\"")
-(defconst cmake-regex-argument-unquoted
- "\\([^ \t\r\n()#\"\\\\]\\|\\\\.\\)\\([^ \t\r\n()#\\\\]\\|\\\\.\\)*")
-(defconst cmake-regex-token (concat "\\(" cmake-regex-comment
- "\\|" cmake-regex-paren-left
- "\\|" cmake-regex-paren-right
- "\\|" cmake-regex-argument-unquoted
- "\\|" cmake-regex-argument-quoted
- "\\)"))
-(defconst cmake-regex-indented (concat "^\\("
- cmake-regex-token
- "\\|" "[ \t\r\n]"
- "\\)*"))
-(defconst cmake-regex-block-open
- "^\\(IF\\|MACRO\\|FOREACH\\|ELSE\\|ELSEIF\\|WHILE\\|FUNCTION\\)$")
-(defconst cmake-regex-block-close
- "^[ \t]*\\(ENDIF\\|ENDFOREACH\\|ENDMACRO\\|ELSE\\|ELSEIF\\|ENDWHILE\\|ENDFUNCTION\\)[ \t]*(")
-
-;------------------------------------------------------------------------------
-
-;;
-;; Helper functions for line indentation function.
-;;
-(defun cmake-line-starts-inside-string ()
- "Determine whether the beginning of the current line is in a string."
- (if (save-excursion
- (beginning-of-line)
- (let ((parse-end (point)))
- (beginning-of-buffer)
- (nth 3 (parse-partial-sexp (point) parse-end))
- )
- )
- t
- nil
- )
- )
-
-(defun cmake-find-last-indented-line ()
- "Move to the beginning of the last line that has meaningful indentation."
- (let ((point-start (point))
- region)
- (forward-line -1)
- (setq region (buffer-substring-no-properties (point) point-start))
- (while (and (not (bobp))
- (or (looking-at cmake-regex-blank)
- (not (and (string-match cmake-regex-indented region)
- (= (length region) (match-end 0))))))
- (forward-line -1)
- (setq region (buffer-substring-no-properties (point) point-start))
- )
- )
- )
-
-;------------------------------------------------------------------------------
-
-;;
-;; Line indentation function.
-;;
-(defun cmake-indent ()
- "Indent current line as CMAKE code."
- (interactive)
- (if (cmake-line-starts-inside-string)
- ()
- (if (bobp)
- (cmake-indent-line-to 0)
- (let (cur-indent)
-
- (save-excursion
- (beginning-of-line)
-
- (let ((point-start (point))
- token)
-
- ; Search back for the last indented line.
- (cmake-find-last-indented-line)
-
- ; Start with the indentation on this line.
- (setq cur-indent (current-indentation))
-
- ; Search forward counting tokens that adjust indentation.
- (while (re-search-forward cmake-regex-token point-start t)
- (setq token (match-string 0))
- (if (string-match (concat "^" cmake-regex-paren-left "$") token)
- (setq cur-indent (+ cur-indent cmake-tab-width))
- )
- (if (string-match (concat "^" cmake-regex-paren-right "$") token)
- (setq cur-indent (- cur-indent cmake-tab-width))
- )
- (if (and
- (string-match cmake-regex-block-open token)
- (looking-at (concat "[ \t]*" cmake-regex-paren-left))
- )
- (setq cur-indent (+ cur-indent cmake-tab-width))
- )
- )
- (goto-char point-start)
-
- ; If this is the end of a block, decrease indentation.
- (if (looking-at cmake-regex-block-close)
- (setq cur-indent (- cur-indent cmake-tab-width))
- )
- )
- )
-
- ; Indent this line by the amount selected.
- (if (< cur-indent 0)
- (cmake-indent-line-to 0)
- (cmake-indent-line-to cur-indent)
- )
- )
- )
- )
- )
-
-(defun cmake-point-in-indendation ()
- (string-match "^[ \\t]*$" (buffer-substring (point-at-bol) (point))))
-
-(defun cmake-indent-line-to (column)
- "Indent the current line to COLUMN.
-If point is within the existing indentation it is moved to the end of
-the indentation. Otherwise it retains the same position on the line"
- (if (cmake-point-in-indendation)
- (indent-line-to column)
- (save-excursion (indent-line-to column))))
-
-;------------------------------------------------------------------------------
-
-;;
-;; Helper functions for buffer
-;;
-(defun unscreamify-cmake-buffer ()
- "Convert all CMake commands to lowercase in buffer."
- (interactive)
- (setq save-point (point))
- (goto-char (point-min))
- (while (re-search-forward "^\\([ \t]*\\)\\(\\w+\\)\\([ \t]*(\\)" nil t)
- (replace-match
- (concat
- (match-string 1)
- (downcase (match-string 2))
- (match-string 3))
- t))
- (goto-char save-point)
- )
-
-;------------------------------------------------------------------------------
-
-;;
-;; Keyword highlighting regex-to-face map.
-;;
-(defconst cmake-font-lock-keywords
- (list '("^[ \t]*\\(\\w+\\)[ \t]*(" 1 font-lock-function-name-face))
- "Highlighting expressions for CMAKE mode."
- )
-
-;------------------------------------------------------------------------------
-
-;;
-;; Syntax table for this mode. Initialize to nil so that it is
-;; regenerated when the cmake-mode function is called.
-;;
-(defvar cmake-mode-syntax-table nil "Syntax table for cmake-mode.")
-(setq cmake-mode-syntax-table nil)
-
-;;
-;; User hook entry point.
-;;
-(defvar cmake-mode-hook nil)
-
-;;
-;; Indentation increment.
-;;
-(defvar cmake-tab-width 2)
-
-;------------------------------------------------------------------------------
-
-;;
-;; CMake mode startup function.
-;;
-(defun cmake-mode ()
- "Major mode for editing CMake listfiles."
- (interactive)
- (kill-all-local-variables)
- (setq major-mode 'cmake-mode)
- (setq mode-name "CMAKE")
-
- ; Create the syntax table
- (setq cmake-mode-syntax-table (make-syntax-table))
- (set-syntax-table cmake-mode-syntax-table)
- (modify-syntax-entry ?_ "w" cmake-mode-syntax-table)
- (modify-syntax-entry ?\( "()" cmake-mode-syntax-table)
- (modify-syntax-entry ?\) ")(" cmake-mode-syntax-table)
- (modify-syntax-entry ?# "<" cmake-mode-syntax-table)
- (modify-syntax-entry ?\n ">" cmake-mode-syntax-table)
-
- ; Setup font-lock mode.
- (make-local-variable 'font-lock-defaults)
- (setq font-lock-defaults '(cmake-font-lock-keywords))
-
- ; Setup indentation function.
- (make-local-variable 'indent-line-function)
- (setq indent-line-function 'cmake-indent)
-
- ; Setup comment syntax.
- (make-local-variable 'comment-start)
- (setq comment-start "#")
-
- ; Run user hooks.
- (run-hooks 'cmake-mode-hook))
-
-; Help mode starts here
-
-
-(defun cmake-command-run (type &optional topic)
- "Runs the command cmake with the arguments specified. The
-optional argument topic will be appended to the argument list."
- (interactive "s")
- (let* ((bufname (concat "*CMake" type (if topic "-") topic "*"))
- (buffer (get-buffer bufname))
- )
- (if buffer
- (display-buffer buffer 'not-this-window)
- ;; Buffer doesn't exist. Create it and fill it
- (setq buffer (generate-new-buffer bufname))
- (setq command (concat cmake-mode-cmake-executable " " type " " topic))
- (message "Running %s" command)
- ;; We don't want the contents of the shell-command running to the
- ;; minibuffer, so turn it off. A value of nil means don't automatically
- ;; resize mini-windows.
- (setq resize-mini-windows-save resize-mini-windows)
- (setq resize-mini-windows nil)
- (shell-command command buffer)
- ;; Save the original window, so that we can come back to it later.
- ;; save-excursion doesn't seem to work for this.
- (setq window (selected-window))
- ;; We need to select it so that we can apply special modes to it
- (select-window (display-buffer buffer 'not-this-window))
- (cmake-mode)
- (toggle-read-only t)
- ;; Restore the original window
- (select-window window)
- (setq resize-mini-windows resize-mini-windows-save)
- )
- )
- )
-
-(defun cmake-help-list-commands ()
- "Prints out a list of the cmake commands."
- (interactive)
- (cmake-command-run "--help-command-list")
- )
-
-(defvar cmake-help-command-history nil "Topic read history.")
-
-(require 'thingatpt)
-(defun cmake-get-topic (type)
- "Gets the topic from the minibuffer input. The default is the word the cursor is on."
- (interactive)
- (let* ((default-entry (word-at-point))
- (input (read-string
- (format "CMake %s (default %s): " type default-entry) ; prompt
- nil ; initial input
- 'cmake-help-command-history ; command history
- default-entry ; default-value
- )))
- (if (string= input "")
- (error "No argument given")
- input))
- )
-
-
-(defun cmake-help-command ()
- "Prints out the help message corresponding to the command the cursor is on."
- (interactive)
- (setq command (cmake-get-topic "command"))
- (cmake-command-run "--help-command" (downcase command))
- )
-
-
-; This file provides cmake-mode.
-(provide 'cmake-mode)
-
-;;; cmake-mode.el ends here
+++ /dev/null
-;;; crontab-mode.el --- Mode for editing crontab files
-;;
-;; ~/share/emacs/pkg/crontab/crontab-mode.el ---
-;;
-;; $Id: crontab-mode.el,v 1.18 2004/03/10 06:51:59 harley Exp $
-;;
-
-;; Author: Harley Gorrell <harley@mahalito.net>
-;; URL: http://www.mahalito.net/~harley/elisp/crontab-mode.el
-;; License: GPL v2
-;; Keywords: cron, crontab, emacs
-
-;;; Commentary:
-;; * I want to keep my crontabs under rcs to keep a history of
-;; the file. Editing them with 'crontab -e' is rather
-;; cumbersome. My method is to keep the crontab as a file,
-;; under rcs, and check in the changes with 'C-c C-c' after
-;; editing.
-;;
-;; * The remote systems are expected to share a filesystem.
-;; If they dont, modify crontab-shell or crontab-apply to
-;; suit your needs.
-;;
-;; * You may want to add one of these to your startup:
-;; (add-to-list 'auto-mode-alist '("\\.cron\\(tab\\)?\\'" . crontab-mode))
-;; (add-to-list 'auto-mode-alist '("cron\\(tab\\)?\\." . crontab-mode))
-
-;;; History:
-;; 2003-03-16: Updated URL and contact info
-;; 2004-02-26: Use ssh to apply crontabs to remote hosts.
-
-;;; Code:
-
-(defvar crontab-suffix ".crontab"
- "*Suffix for crontab buffers.")
-
-(defvar crontab-apply-after-save nil
- "*Non-nil to apply the crontab after a save.")
-(make-variable-buffer-local 'crontab-apply-after-save)
-
-(defvar crontab-host nil
- "*Hostname to use when saving the crontab to a remote host.")
-(make-variable-buffer-local 'crontab-host)
-
-(defvar crontab-user nil
- "*Username to use when saving the crontab to a remote host.")
-(make-variable-buffer-local 'crontab-user)
-
-;; Would be better to have "\\([0-9]\\([-,][0-9]+\\)+\\|...
-(defvar crontab-unit-regexp "\\([-,0-9]+\\|\\*\\)"
- "A regexp which matches a cron time unit.")
-
-(defvar crontab-sep-regexp "[ \t]+"
- "A regexp to match whitespace seperating cron time units.")
-
-(defvar crontab-ruler "
-# min hour day month day-of-week command
-#(0-59) (0-23) (1-31) (1-12) (0-6)
-#
-#------------------------------------------------------------
-"
- "*The ruler `crontab-insert-ruler' inserts.")
-
-;;
-(defvar crontab-mode-hook nil
- "*Hook for customising `crontab-mode'.")
-
-(defvar crontab-load-hook nil
- "*Hook run when the `crontab-mode' is loaded.")
-
-;;
-(defvar crontab-font-lock-keywords
- (list
- ;; Comments
- '("^#.*$" . font-lock-comment-face)
- ;; Blank lines are bad!
- '("^[ \t]+$" . highlight)
- ;; Variable defs
- '("^\\([A-Z_]+\\)=\\(.*\\)$" .
- ((1 font-lock-keyword-face)
- (2 font-lock-string-face)) )
- ;; Cron lines
- ;; 50 * * * * /usr/gnu/bin/bash
- (cons
- (concat "^"
- crontab-unit-regexp crontab-sep-regexp
- crontab-unit-regexp crontab-sep-regexp
- crontab-unit-regexp crontab-sep-regexp
- crontab-unit-regexp crontab-sep-regexp
- crontab-unit-regexp crontab-sep-regexp
- "\\(.*\\)$")
- '((1 font-lock-keyword-face)
- (2 font-lock-keyword-face)
- (3 font-lock-keyword-face)
- (4 font-lock-keyword-face)
- (5 font-lock-keyword-face)
- (6 font-lock-string-face))) )
- "Info for function `font-lock-mode'.")
-
-(defvar crontab-mode-map nil
- "Keymap used in `crontab-mode'.")
-
-(if crontab-mode-map
- ()
- (setq crontab-mode-map (make-sparse-keymap))
- (define-key crontab-mode-map "\C-c\C-c" 'crontab-save-and-apply)
- (define-key crontab-mode-map "\C-cc" 'crontab-save-and-apply)
- (define-key crontab-mode-map "\C-ca" 'crontab-save-and-apply-to)
- (define-key crontab-mode-map "\C-ci" 'crontab-insert-local-var)
- (define-key crontab-mode-map "\C-cr" 'crontab-insert-ruler))
-
-;; This will barf without the correct agent or key setup.
-(defvar crontab-rsh-cmd "ssh" ;; "rsh"
- "Program to use for remote shells.")
-
-(defun crontab-rsh-cmd ()
- "Generate the rsh command. Redefine as needed."
- (if crontab-user
- (concat crontab-rsh-cmd " -l " (format "%s" crontab-user)) ;; str-ify
- crontab-rsh-cmd) )
-
-(defun crontab-localhost-p (&optional host)
- "True if this is the same HOST Emacs is on."
- (or (null host)
- (string= host "")
- (string= host "localhost")
- (string= host (system-name))) )
-
-(defun crontab-shell (host cmd out-buffer)
- "On a possibly remote HOST, run CMD Output to OUT-BUFFER."
- (when (not (crontab-localhost-p host))
- (setq cmd (concat (crontab-rsh-cmd) " " host " " cmd)))
- (shell-command cmd out-buffer) )
-
-;;;###autoload
-(defun crontab-mode ()
- "Major mode for editing crontabs.
-Defines commands for getting and applying crontabs for hosts.
-Sets up command `font-lock-mode'.
-
-\\{crontab-mode-map}"
- (interactive)
- ;;
- (kill-all-local-variables)
- (setq mode-name "crontab")
- (setq major-mode 'crontab-mode)
- (use-local-map crontab-mode-map)
- ;;
- (setq comment-start "#")
- (setq comment-start-skip "#+ *")
- ;;
- (make-local-variable 'font-lock-defaults)
- (setq font-lock-defaults '(crontab-font-lock-keywords))
- ;; Add to the end of the buffers save hooks.
- (add-hook 'after-save-hook 'crontab-after-save t t)
- ;;
- (run-hooks 'crontab-mode-hook) )
-
-
-;;;###autoload
-(defun crontab-get (host)
- "Get the crontab for the HOST into a buffer."
- (interactive "sCrontab for host:")
- (let ((cbn (generate-new-buffer-name (concat host crontab-suffix))))
- (switch-to-buffer-other-window cbn)
- (erase-buffer)
- (crontab-mode)
- (crontab-insert host)
- (not-modified)
- (setq crontab-host host)) )
-
-(defun crontab-insert (&optional host)
- "Insert the crontab for the HOST into the current buffer."
- (crontab-shell host "crontab -l" t) )
-
-(defun crontab-apply (&optional host)
- "Apply the crontab to a HOST. The filesystem must be common."
- (if (buffer-file-name)
- (crontab-shell host (concat "crontab " (buffer-file-name)) nil)
- (error "No filename for this buffer")))
-
-(defun crontab-save-and-apply ()
- "Save and apply the buffer to the HOST."
- (interactive)
- (save-buffer)
- (if (not crontab-apply-after-save) ;; Dont apply it twice.
- (crontab-apply (crontab-host))) )
-
-(defun crontab-save-and-apply-to (host)
- "Prompt for the HOST and apply the file."
- (interactive "sApply to host:")
- (setq crontab-host host) ;; remember the change
- (crontab-save-and-apply) )
-
-(defun crontab-insert-ruler ()
- "Insert a ruler with comments into the crontab."
- (interactive)
- (end-of-line)
- (insert crontab-ruler) )
-
-(defun crontab-insert-local-var ()
- "Insert the current values of buffer local variables."
- (interactive)
- (end-of-buffer)
- (insert "
-" comment-start " Local " "Variables:
-" comment-start " mode: " (format "%s" (or mode-name "crontab")) "
-" comment-start " crontab-host: " (crontab-host) "
-" comment-start " crontab-apply-after-save: "
-(format "%s" crontab-apply-after-save) "
-" comment-start " End:
-") )
-
-(defun crontab-host ()
- "Return the hostname as a string, defaulting to the local host.
-The variable `crontab-host' could be a symbol or a string."
- (format "%s" (or crontab-host system-name)) )
-
-;;
-(defun crontab-after-save ()
- "If `crontab-apply-after-save' is set, apply the crontab after a save."
- (if crontab-apply-after-save (crontab-apply (crontab-host))) )
-
-(provide 'crontab-mode)
-(run-hooks 'crontab-load-hook)
-
-;;; crontab-mode.el ends here
+++ /dev/null
-;;; curve.el --- AUC-TeX style file for CurVe
-
-;; Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005 Didier Verna.
-
-;; Author: Didier Verna <didier@lrde.epita.fr>
-;; Maintainer: Didier Verna <didier@lrde.epita.fr>
-;; Created: Tue Apr 18 14:49:29 2000
-;; Last Revision: Wed May 19 16:33:24 2004
-;; Keywords: tex abbrev data
-
-;; This file is part of CurVe.
-
-;; CurVe may be distributed and/or modified under the
-;; conditions of the LaTeX Project Public License, either version 1.1
-;; of this license or (at your option) any later version.
-;; The latest version of this license is in
-;; http://www.latex-project.org/lppl.txt
-;; and version 1.1 or later is part of all distributions of LaTeX
-;; version 1999/06/01 or later.
-
-;; CurVe consists of all files listed in the file `README'.
-
-
-;;; Commentary:
-
-;; Contents management by FCM version 0.1-b2.
-
-
-;;; Code:
-
-(defun curve-rubric-file (optional &optional prompt)
- "Prompt for a CurVe rubric filename in the current directory.
-
-Caution: because of the flavor mechanism of CurVe, this function will use
-the choosen file name sans the last TWO extensions."
- (TeX-argument-insert
- (file-name-sans-extension
- (file-name-sans-extension
- (read-file-name (TeX-argument-prompt optional
- prompt "Rubric file")
- "" "" nil)))
- optional))
-
-(defun curve-rubric-item ()
- ;; Ideally, we should have a way (like, a prefix) to specify either an
- ;; entry, an entry* or a subrubric. But that would require to hack AUC-TeX
- ;; in order to pass an optional argument to LaTeX-insert-item.
- (TeX-insert-macro "entry*"))
-
-(add-hook 'LaTeX-mode-hook
- (lambda ()
- (setq LaTeX-item-list
- (cons '("rubric" . curve-rubric-item) LaTeX-item-list))))
-
-
-(TeX-add-style-hook "curve"
- (function
- (lambda ()
- (TeX-add-symbols
- '("photo" [ "Placement (l, c or r)" ] t)
- '("photosep")
- '("photoscale" t)
- '("leftheader" t)
- '("rightheader" t)
- '("headerscale" t)
- '("headerspace")
- '("makeheaders" [ "Alignment (t, c or b)" ])
-
- '("title" "Title")
- '("subtitle" "Subtitle")
- '("titlespace")
- '("titlefont" "Font for title")
- '("subtitlefont" "Font for subtitle")
- '("maketitle")
-
- '("flavor" "Flavor")
- '("makerubric" curve-rubric-file)
-
- '("rubricalignment" "Alignment (l, c, r, cl, cc)")
- '("rubricfont" "For for rubrics")
- '("rubricspace")
-
- '("subrubric" "Subrubric name")
- '("subrubricalignment" "Alignment (l, c, r, cl, cc)")
- '("subrubricfont" "Font for subrubrics")
- '("subrubricspace")
- '("subrubricbeforespace")
-
- '("entry" [ "Key" ] t)
- '("entry*" [ "Key" ])
- '("keyfont" "Font for keys")
- '("keyalignment" "Alignment (l, c, or r)")
- '("prefix" "Prefix command")
-
- '("continuedname" "Continuation name")
- '("listpubname" "List of publications name")
- )
- (LaTeX-add-environments
- '("rubric" "Name")
- )
- )))
-
-
-\f
-
-;;; Local variables:
-;;; eval: (put 'TeX-add-style-hook 'lisp-indent-function 1)
-;;; End:
-
-;;; curve.el ends here
+++ /dev/null
-;;; google-weather.el --- Fetch Google Weather forecasts.
-
-;; Copyright (C) 2010 Julien Danjou
-
-;; Author: Julien Danjou <julien@danjou.info>
-;; Keywords: comm
-
-;; This file is NOT 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:
-;; This module allows you to fetch Google Weather forecast from the
-;; Internet.
-;;
-;;; Code:
-
-(require 'url)
-(require 'url-cache)
-(require 'xml)
-(require 'time-date)
-
-(eval-when-compile
- (require 'cl))
-
-(defgroup google-weather nil
- "Google Weather."
- :group 'comm)
-
-(defcustom google-weather-use-https nil
- "Default protocol to use to access the Google Weather API."
- :group 'google-weather
- :type 'boolean)
-
-(defconst google-weather-url
- "www.google.com/ig/api"
- "URL of the Google Weather API.")
-
-(defconst google-weather-image-url
- "http://www.google.com"
- "URL prefix for images.")
-
-(defcustom google-weather-unit-system-temperature-assoc
- '(("SI" . "℃")
- ("US" . "℉"))
- "Find temperature symbol from unit system."
- :group 'google-weather)
-
-(defun google-weather-cache-expired (url expire-time)
- "Check if URL is cached for more than EXPIRE-TIME."
- (cond (url-standalone-mode
- (not (file-exists-p (url-cache-create-filename url))))
- (t (let ((cache-time (url-is-cached url)))
- (if cache-time
- (time-less-p
- (time-add
- cache-time
- (seconds-to-time expire-time))
- (current-time))
- t)))))
-
-(defun google-weather-cache-fetch (url)
- "Fetch URL from the cache."
- (with-current-buffer (generate-new-buffer " *temp*")
- (url-cache-extract (url-cache-create-filename url))
- (current-buffer)))
-
-(defun google-weather-retrieve-data-raw (url &optional expire-time)
- "Retrieve URL and return its data as string.
-If EXPIRE-TIME is set, the data will be fetched from the cache if
-their are not older than EXPIRE-TIME seconds. Otherwise, they
-will be fetched and then cached. Therefore, setting EXPIRE-TIME
-to 0 force a cache renewal."
- (let* ((expired (if expire-time
- (google-weather-cache-expired url expire-time)
- t))
- (buffer (if expired
- (url-retrieve-synchronously url)
- (google-weather-cache-fetch url)))
- data)
- (when (and expired expire-time)
- (url-store-in-cache buffer))
- buffer))
-
-(defun google-weather-retrieve-data (url &optional expire-time)
- "Retrieve URL and return its data as string.
-If EXPIRE-TIME is set, the data will be fetched from the cache if
-their are not older than EXPIRE-TIME seconds. Otherwise, they
-will be fetched and then cached. Therefore, setting EXPIRE-TIME
-to 0 force a cache renewal."
- (with-current-buffer (google-weather-retrieve-data-raw
- url expire-time)
- (goto-char (point-min))
- (unless (search-forward "\n\n" nil t)
- (error "Data not found"))
- (decode-coding-region
- (point) (point-max)
- (detect-coding-region (point) (point-max) t))
- (set-buffer-multibyte t)
- (let ((data (xml-parse-region (point) (point-max))))
- (kill-buffer (current-buffer))
- data)))
-
-(defun google-weather-build-url (location &optional language)
- "Build URL to retrieve weather for LOCATION in LANGUAGE."
- (concat "http" (when google-weather-use-https "s") "://" google-weather-url "?weather=" (url-hexify-string location)
- (when language
- (concat "&hl=" language))))
-
-(defun google-weather-get-data (location &optional language expire-time)
- "Get weather data for LOCATION in LANGUAGE.
-See `google-weather-retrieve-data' for the use of EXPIRE-TIME."
- (google-weather-retrieve-data
- (google-weather-build-url location language) expire-time))
-
-(defun google-weather-data->weather (data)
- "Return all weather information from DATA."
- (cddr (assoc 'weather (cdr (assoc 'xml_api_reply data)))))
-
-(defun google-weather-data->forecast-information (data)
- "Return the forecast information of DATA."
- (cddr (assoc 'forecast_information (google-weather-data->weather data))))
-
-(defun google-weather-assoc (key data)
- "Extract value of field KEY from DATA."
- (cdr (assoc 'data (cadr (assoc key data)))))
-
-(defun google-weather-data->city (data)
- "Return the city where the DATA come from."
- (google-weather-assoc
- 'city
- (google-weather-data->forecast-information data)))
-
-(defun google-weather-data->postal-code (data)
- "Return the postal code where the DATA come from."
- (google-weather-assoc
- 'postal_code
- (google-weather-data->forecast-information data)))
-
-(defun google-weather-data->unit-system (data)
- "Return the unit system used for DATA."
- (google-weather-assoc
- 'unit_system
- (google-weather-data->forecast-information data)))
-
-(defun google-weather-data->forecast-date (data)
- "Return the unit system used for DATA."
- (google-weather-assoc
- 'forecast_date
- (google-weather-data->forecast-information data)))
-
-(defun google-weather-data->forecast (data)
- "Get forecast list from DATA."
- ;; Compute date of the forecast in the same format as `current-time'
- (let ((date (apply 'encode-time
- (parse-time-string
- (concat (google-weather-data->forecast-date data) " 00:00:00")))))
- (mapcar
- (lambda (forecast)
- (let* ((forecast-date (decode-time date))
- (forecast-encoded-date (list (nth 4 forecast-date)
- (nth 3 forecast-date)
- (nth 5 forecast-date))))
- ;; Add one day to `date'
- (setq date (time-add date (days-to-time 1)))
- `(,forecast-encoded-date
- (low ,(google-weather-assoc 'low forecast))
- (high ,(google-weather-assoc 'high forecast))
- (icon ,(concat google-weather-image-url
- (google-weather-assoc 'icon forecast)))
- (condition ,(google-weather-assoc 'condition forecast)))))
- (loop for entry in (google-weather-data->weather data)
- when (eq (car entry) 'forecast_conditions)
- collect entry))))
-
-(defun google-weather-data->forecast-for-date (data date)
- "Return forecast for DATE from DATA.
-DATE should be in the same format used by calendar,
-i.e. (MONTH DAY YEAR)."
- (cdr (assoc date (google-weather-data->forecast data))))
-
-(defun google-weather-data->temperature-symbol (data)
- "Return the temperature to be used according in DATA.
-It uses `google-weather-unit-system-temperature-assoc' to find a
-match."
- (cdr (assoc (google-weather-data->unit-system data) google-weather-unit-system-temperature-assoc)))
-
-
-(defun google-weather-data->problem-cause (data)
- "Return a string if DATA contains a problem cause, `nil' otherwise.
-
-An error message example:
-
-((xml_api_reply
- ((version . \"1\"))
- (weather
- ((module_id . \"0\") (tab_id . \"0\") (mobile_row . \"0\")
- (mobile_zipped . \"1\") (row . \"0\") (section . \"0\"))
- (problem_cause ((data . \"Information is temporarily unavailable.\"))))))))"
- (google-weather-assoc
- 'problem_cause
- (google-weather-data->weather data)))
-
-(provide 'google-weather)
+++ /dev/null
-;;; iedit-lib.el --- APIs for editing multiple regions in the same way
-;;; simultaneously.
-
-;; Copyright (C) 2010, 2011, 2012 Victor Ren
-
-;; Time-stamp: <2012-10-17 08:48:28 Victor Ren>
-;; Author: Victor Ren <victorhge@gmail.com>
-;; Keywords: occurrence region simultaneous rectangle refactoring
-;; Version: 0.97
-;; X-URL: http://www.emacswiki.org/emacs/Iedit
-;; Compatibility: GNU Emacs: 22.x, 23.x, 24.x
-
-;; This file is not part of GNU Emacs, but it is distributed under
-;; the same terms as 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:
-
-;; This package is iedit APIs library that allow you to write your own minor mode.
-
-;;; todo:
-;; - Update comments for APIs
-;; - Add more easy access keys for whole occurrence
-;; - More APIs: extend occurrences,
-
-;;; Code:
-
-(eval-when-compile (require 'cl))
-
-(defgroup iedit nil
- "Edit multiple regions in the same way simultaneously."
- :prefix "iedit-"
- :group 'replace
- :group 'convenience)
-
-(defface iedit-occurrence
- '((t :inherit highlight))
- "*Face used for the occurrences' default values."
- :group 'iedit)
-
-(defcustom iedit-case-sensitive-default t
- "If no-nil, matching is case sensitive."
- :type 'boolean
- :group 'iedit)
-
-(defcustom iedit-unmatched-lines-invisible-default nil
- "If no-nil, hide lines that do not cover any occurrences by default."
- :type 'boolean
- :group 'iedit)
-
-(defcustom iedit-transient-mark-sensitive t
- "If no-nil, Iedit mode is sensitive to the Transient Mark mode.
-It means Iedit works as expected only when regions are
-highlighted. If you want to use iedit without Transient Mark
-mode, set it as nil."
- :type 'boolean
- :group 'iedit)
-
-(defvar iedit-occurrences-overlays nil
- "The occurrences slot contains a list of overlays used to
-indicate the position of each occurrence. In addition, the
-occurrence overlay is used to provide a different face
-configurable via `iedit-occurrence-face'. The list is sorted by
-the position of overlays.")
-
-(defvar iedit-case-sensitive iedit-case-sensitive-default
- "This is buffer local variable.
-If no-nil, matching is case sensitive.")
-
-(defvar iedit-unmatched-lines-invisible nil
- "This is buffer local variable which indicates whether
-unmatched lines are hided.")
-
-(defvar iedit-forward-success t
- "This is buffer local variable which indicates the moving
-forward or backward successful")
-
-(defvar iedit-before-modification-string ""
- "This is buffer local variable which is the buffer substring
-that is going to be changed.")
-
-(defvar iedit-before-modification-undo-list nil
- "This is buffer local variable which is the buffer undo list before modification.")
-
-;; `iedit-occurrence-update' gets called twice when change==0 and occurrence
-;; is zero-width (beg==end)
-;; -- for front and back insertion.
-(defvar iedit-skip-modification-once t
- "Variable used to skip first modification hook run when
-insertion against a zero-width occurrence.")
-
-(defvar iedit-aborting nil
- "This is buffer local variable which indicates Iedit mode is aborting.")
-
-(defvar iedit-aborting-hook nil
- "Functions to call before iedit-abort. Normally it should be mode exit function.")
-
-(defvar iedit-post-undo-hook-installed nil
- "This is buffer local variable which indicated if
-`iedit-post-undo-hook' is installed in `post-command-hook'.")
-
-(defvar iedit-buffering nil
- "This is buffer local variable which indicates iedit-mode is
-buffering, which means the modification to the current occurrence
-is not applied to other occurrences when it is true.")
-
-(defvar iedit-occurrence-context-lines 1
- "The number of lines before or after the occurrence.")
-
-(make-variable-buffer-local 'iedit-occurrences-overlays)
-(make-variable-buffer-local 'iedit-unmatched-lines-invisible)
-(make-local-variable 'iedit-case-sensitive)
-(make-variable-buffer-local 'iedit-forward-success)
-(make-variable-buffer-local 'iedit-before-modification-string)
-(make-variable-buffer-local 'iedit-before-modification-undo-list)
-(make-variable-buffer-local 'iedit-skip-modification-once)
-(make-variable-buffer-local 'iedit-aborting)
-(make-variable-buffer-local 'iedit-buffering)
-(make-variable-buffer-local 'iedit-post-undo-hook-installed)
-(make-variable-buffer-local 'iedit-occurrence-context-lines)
-
-(defconst iedit-occurrence-overlay-name 'iedit-occurrence-overlay-name)
-(defconst iedit-invisible-overlay-name 'iedit-invisible-overlay-name)
-
-;;; Define Iedit mode map
-(defvar iedit-lib-keymap
- (let ((map (make-sparse-keymap)))
- ;; Default key bindings
- (define-key map (kbd "TAB") 'iedit-next-occurrence)
- (define-key map (kbd "<S-tab>") 'iedit-prev-occurrence)
- (define-key map (kbd "<S-iso-lefttab>") 'iedit-prev-occurrence)
- (define-key map (kbd "<backtab>") 'iedit-prev-occurrence)
- (define-key map (kbd "C-'") 'iedit-toggle-unmatched-lines-visible)
- map)
- "Keymap used while Iedit mode is enabled.")
-
-(defvar iedit-occurrence-keymap-default
- (let ((map (make-sparse-keymap)))
-;; (set-keymap-parent map iedit-lib-keymap)
- (define-key map (kbd "M-U") 'iedit-upcase-occurrences)
- (define-key map (kbd "M-L") 'iedit-downcase-occurrences)
- (define-key map (kbd "M-R") 'iedit-replace-occurrences)
- (define-key map (kbd "M-SPC") 'iedit-blank-occurrences)
- (define-key map (kbd "M-D") 'iedit-delete-occurrences)
- (define-key map (kbd "M-N") 'iedit-number-occurrences)
- (define-key map (kbd "M-;") 'iedit-apply-global-modification)
- (define-key map (kbd "M-B") 'iedit-toggle-buffering)
- (define-key map (kbd "M-<") 'iedit-first-occurrence)
- (define-key map (kbd "M->") 'iedit-last-occurrence)
- (define-key map (kbd "C-?") 'iedit-help-for-occurrences)
- map)
- "Default keymap used within occurrence overlays.")
-
-(defvar iedit-occurrence-keymap 'iedit-occurrence-keymap-default
- "Keymap used within occurrence overlays.
-It should be set before occurrence overlay is created.")
-(make-local-variable 'iedit-occurrence-keymap)
-
-(defun iedit-help-for-occurrences ()
- "Display `iedit-occurrence-keymap-default'"
- (interactive)
- (message (concat (substitute-command-keys "\\[iedit-upcase-occurrences]") "/"
- (substitute-command-keys "\\[iedit-downcase-occurrences]") ":up/downcase "
- (substitute-command-keys "\\[iedit-replace-occurrences]") ":replace "
- (substitute-command-keys "\\[iedit-blank-occurrences]") ":blank "
- (substitute-command-keys "\\[iedit-delete-occurrences]") ":delete "
- (substitute-command-keys "\\[iedit-number-occurrences]") ":number "
- (substitute-command-keys "\\[iedit-apply-global-modification]") ":redo "
- (substitute-command-keys "\\[iedit-toggle-buffering]") ":buffering "
- (substitute-command-keys "\\[iedit-first-occurrence]") "/"
- (substitute-command-keys "\\[iedit-last-occurrence]") ":first/last "
- )))
-
-(defun iedit-make-occurrences-overlays (occurrence-regexp beg end)
- "Create occurrence overlays for `occurrence-regexp' in a region.
-Return the number of occurrences."
- (setq iedit-aborting nil)
- (setq iedit-occurrences-overlays nil)
- ;; Find and record each occurrence's markers and add the overlay to the occurrences
- (let ((counter 0)
- (case-fold-search (not iedit-case-sensitive)))
- (save-excursion
- (goto-char beg)
- (while (re-search-forward occurrence-regexp end t)
- (push (iedit-make-occurrence-overlay (match-beginning 0) (match-end 0))
- iedit-occurrences-overlays)
- (setq counter (1+ counter)))
- (message "%d matches for \"%s\"" counter (iedit-printable occurrence-regexp))
- (when (/= 0 counter)
- (setq iedit-occurrences-overlays (nreverse iedit-occurrences-overlays))
- (if iedit-unmatched-lines-invisible
- (iedit-hide-unmatched-lines iedit-occurrence-context-lines))))
- counter))
-
-(defun iedit-add-next-occurrence-overlay (occurrence-exp &optional point)
- "Create next occurrence overlay for `occurrence-exp'."
- (iedit-add-occurrence-overlay occurrence-exp point t))
-
-(defun iedit-add-previous-occurrence-overlay (occurrence-exp &optional point)
- "Create previous occurrence overlay for `occurrence-exp'."
- (iedit-add-occurrence-overlay occurrence-exp point nil))
-
-(defun iedit-add-occurrence-overlay (occurrence-exp point forward)
- "Create next or previous occurrence overlay for `occurrence-exp'."
- (or point
- (setq point (point)))
- (let ((case-fold-search (not iedit-case-sensitive)))
- (save-excursion
- (goto-char point)
- (if (not (if forward
- (re-search-forward occurrence-exp nil t)
- (re-search-backward occurrence-exp nil t)))
- (message "No matches.")
- (if (or (iedit-find-overlay-at-point (match-beginning 0) 'iedit-occurrence-overlay-name)
- (iedit-find-overlay-at-point (match-end 0) 'iedit-occurrence-overlay-name))
- (error "Conflict region."))
- (push (iedit-make-occurrence-overlay (match-beginning 0)
- (match-end 0))
- iedit-occurrences-overlays)
- (sort iedit-occurrences-overlays
- (lambda (left right)
- (< (overlay-start left) (overlay-start right))))
- (message "Add one match for \"%s\"" (iedit-printable occurrence-exp))
- (if iedit-unmatched-lines-invisible
- (iedit-hide-unmatched-lines iedit-occurrence-context-lines))))))
-
-(defun iedit-add-region-as-occurrence (beg end)
- "Add region as an occurrence.
-The length of the region must the same as other occurrences if
-there are."
- (or (= beg end)
- (error "No region"))
- (if (null iedit-occurrences-overlays)
- (push
- (iedit-make-occurrence-overlay beg end)
- iedit-occurrences-overlays)
- (or (= (- end beg) (iedit-occurrence-string-length))
- (error "Wrong region."))
- (if (or (iedit-find-overlay-at-point beg 'iedit-occurrence-overlay-name)
- (iedit-find-overlay-at-point end 'iedit-occurrence-overlay-name))
- (error "Conflict region."))
- (push (iedit-make-occurrence-overlay beg end)
- iedit-occurrences-overlays)
- (sort iedit-occurrences-overlays
- (lambda (left right)
- (< (overlay-start left) (overlay-start right)))))) ;; todo test this function
-
-(defun iedit-cleanup ()
- "Clean up occurrence overlay, invisible overlay and local variables."
- (remove-overlays nil nil iedit-occurrence-overlay-name t)
- (iedit-show-all)
- (setq iedit-occurrences-overlays nil)
- (setq iedit-aborting nil)
- (setq iedit-before-modification-string "")
- (setq iedit-before-modification-undo-list nil))
-
-(defun iedit-make-occurrence-overlay (begin end)
- "Create an overlay for an occurrence in Iedit mode.
-Add the properties for the overlay: a face used to display a
-occurrence's default value, and modification hooks to update
-occurrences if the user starts typing."
- (let ((occurrence (make-overlay begin end (current-buffer) nil t)))
- (overlay-put occurrence iedit-occurrence-overlay-name t)
- (overlay-put occurrence 'face 'iedit-occurrence)
- (overlay-put occurrence 'keymap iedit-occurrence-keymap)
- (overlay-put occurrence 'insert-in-front-hooks '(iedit-occurrence-update))
- (overlay-put occurrence 'insert-behind-hooks '(iedit-occurrence-update))
- (overlay-put occurrence 'modification-hooks '(iedit-occurrence-update))
- occurrence))
-
-(defun iedit-make-unmatched-lines-overlay (begin end)
- "Create an overlay for lines between two occurrences in Iedit mode."
- (let ((unmatched-lines-overlay (make-overlay begin end (current-buffer) nil t)))
- (overlay-put unmatched-lines-overlay iedit-invisible-overlay-name t)
- (overlay-put unmatched-lines-overlay 'invisible 'iedit-invisible-overlay-name)
- ;; (overlay-put unmatched-lines-overlay 'intangible t)
- unmatched-lines-overlay))
-
-(defun iedit-post-undo-hook ()
- "Check if it is time to abort iedit after undo command is executed.
-
-This is added to `post-command-hook' when undo command is executed
-in occurrences."
- (if (iedit-same-length)
- nil
- (run-hooks 'iedit-aborting-hook))
- (remove-hook 'post-command-hook 'iedit-post-undo-hook t)
- (setq iedit-post-undo-hook-installed nil))
-
-(defun iedit-reset-aborting ()
- "Turning Iedit mode off and reset `iedit-aborting'.
-
-This is added to `post-command-hook' when aborting Iedit mode is
-decided. `iedit-aborting-hook' is postponed after the current
-command is executed for avoiding `iedit-occurrence-update' is
-called for a removed overlay."
- (run-hooks 'iedit-aborting-hook)
- (remove-hook 'post-command-hook 'iedit-reset-aborting t)
- (setq iedit-aborting nil))
-
-;; There are two ways to update all occurrence. One is to redefine all key
-;; stroke map for overlay, the other is to figure out three basic modification
-;; in the modification hook. This function chooses the latter.
-(defun iedit-occurrence-update (occurrence after beg end &optional change)
- "Update all occurrences.
-This modification hook is triggered when a user edits any
-occurrence and is responsible for updating all other occurrences.
-Current supported edits are insertion, yank, deletion and
-replacement. If this modification is going out of the
-occurrence, it will abort Iedit mode."
- (if undo-in-progress
- ;; If the "undo" change make occurrences different, it is going to mess up
- ;; occurrences. So a check will be done after undo command is executed.
- (when (not iedit-post-undo-hook-installed)
- (add-hook 'post-command-hook 'iedit-post-undo-hook nil t)
- (setq iedit-post-undo-hook-installed t))
- (when (and (not iedit-aborting ))
- ;; before modification
- (if (null after)
- (if (or (< beg (overlay-start occurrence))
- (> end (overlay-end occurrence)))
- (progn (setq iedit-aborting t) ; abort iedit-mode
- (add-hook 'post-command-hook 'iedit-reset-aborting nil t))
- (setq iedit-before-modification-string
- (buffer-substring-no-properties beg end))
- ;; Check if this is called twice before modification. When inserting
- ;; into zero-width occurrence or between two conjoined occurrences,
- ;; both insert-in-front-hooks and insert-behind-hooks will be
- ;; called. Two calls will make `iedit-skip-modification-once' true.
- (setq iedit-skip-modification-once (not iedit-skip-modification-once)))
- ;; after modification
- (when (not iedit-buffering)
- (if iedit-skip-modification-once
- ;; Skip the first hook
- (setq iedit-skip-modification-once nil)
- (setq iedit-skip-modification-once t)
- (when (or (eq 0 change) ;; insertion
- (eq beg end) ;; deletion
- (not (string= iedit-before-modification-string
- (buffer-substring-no-properties beg end))))
- (let ((inhibit-modification-hooks t) ; todo: extract this as a function
- (offset (- beg (overlay-start occurrence)))
- (value (buffer-substring-no-properties beg end)))
- (save-excursion
- ;; insertion or yank
- (if (eq 0 change)
- (dolist (another-occurrence iedit-occurrences-overlays)
- (let* ((beginning (+ (overlay-start another-occurrence) offset))
- (ending (+ beginning (- end beg))))
- (when (not (eq another-occurrence occurrence))
- (goto-char beginning)
- (insert-and-inherit value)
- ;; todo: reconsider this change Quick fix for
- ;; multi-occur occur-edit-mode: multi-occur depend on
- ;; after-change-functions to update original
- ;; buffer. Since inhibit-modification-hooks is set to
- ;; non-nil, after-change-functions hooks are not going
- ;; to be called for the changes of other occurrences.
- ;; So run the hook here.
- (run-hook-with-args 'after-change-functions
- beginning
- ending
- change))
- (iedit-move-conjoined-overlays another-occurrence)))
- ;; deletion
- (dolist (another-occurrence (remove occurrence iedit-occurrences-overlays))
- (let ((beginning (+ (overlay-start another-occurrence) offset)))
- (delete-region beginning (+ beginning change))
- (unless (eq beg end) ;; replacement
- (goto-char beginning)
- (insert-and-inherit value))
- (run-hook-with-args 'after-change-functions
- beginning
- (+ beginning (- beg end))
- change)))))))))))))
-
-(defun iedit-next-occurrence ()
- "Move forward to the next occurrence in the `iedit'.
-If the point is already in the last occurrences, you are asked to type
-another `iedit-next-occurrence', it starts again from the
-beginning of the buffer."
- (interactive)
- (let ((pos (point))
- (in-occurrence (get-char-property (point) 'iedit-occurrence-overlay-name)))
- (when in-occurrence
- (setq pos (next-single-char-property-change pos 'iedit-occurrence-overlay-name)))
- (setq pos (next-single-char-property-change pos 'iedit-occurrence-overlay-name))
- (if (/= pos (point-max))
- (setq iedit-forward-success t)
- (if (and iedit-forward-success in-occurrence)
- (progn (message "This is the last occurrence.")
- (setq iedit-forward-success nil))
- (progn
- (if (get-char-property (point-min) 'iedit-occurrence-overlay-name)
- (setq pos (point-min))
- (setq pos (next-single-char-property-change
- (point-min)
- 'iedit-occurrence-overlay-name)))
- (setq iedit-forward-success t)
- (message "Located the first occurrence."))))
- (when iedit-forward-success
- (goto-char pos))))
-
-(defun iedit-prev-occurrence ()
- "Move backward to the previous occurrence in the `iedit'.
-If the point is already in the first occurrences, you are asked to type
-another `iedit-prev-occurrence', it starts again from the end of
-the buffer."
- (interactive)
- (let ((pos (point))
- (in-occurrence (get-char-property (point) 'iedit-occurrence-overlay-name)))
- (when in-occurrence
- (setq pos (previous-single-char-property-change pos 'iedit-occurrence-overlay-name)))
- (setq pos (previous-single-char-property-change pos 'iedit-occurrence-overlay-name))
- ;; At the start of the first occurrence
- (if (or (and (eq pos (point-min))
- (not (get-char-property (point-min) 'iedit-occurrence-overlay-name)))
- (and (eq (point) (point-min))
- in-occurrence))
- (if (and iedit-forward-success in-occurrence)
- (progn (message "This is the first occurrence.")
- (setq iedit-forward-success nil))
- (progn
- (setq pos (previous-single-char-property-change (point-max) 'iedit-occurrence-overlay-name))
- (if (not (get-char-property (- (point-max) 1) 'iedit-occurrence-overlay-name))
- (setq pos (previous-single-char-property-change pos 'iedit-occurrence-overlay-name)))
- (setq iedit-forward-success t)
- (message "Located the last occurrence.")))
- (setq iedit-forward-success t))
- (when iedit-forward-success
- (goto-char pos))))
-
-(defun iedit-first-occurrence ()
- "Move to the first occurrence."
- (interactive)
- (let ((pos (if (get-char-property (point-min) 'iedit-occurrence-overlay-name)
- (point-min)
- (next-single-char-property-change
- (point-min) 'iedit-occurrence-overlay-name))))
- (setq iedit-forward-success t)
- (goto-char pos)
- (message "Located the first occurrence.")))
-
-(defun iedit-last-occurrence ()
- "Move to the last occurrence."
- (interactive)
- (let ((pos (previous-single-char-property-change (point-max) 'iedit-occurrence-overlay-name)))
- (if (not (get-char-property (- (point-max) 1) 'iedit-occurrence-overlay-name))
- (setq pos (previous-single-char-property-change pos 'iedit-occurrence-overlay-name)))
- (setq iedit-forward-success t)
- (goto-char pos)
- (message "Located the last occurrence.")))
-
-(defun iedit-toggle-unmatched-lines-visible (&optional arg)
- "Toggle whether to display unmatched lines.
-A prefix ARG specifies how many lines before and after the
-occurrences are not hided; negative is treated the same as zero.
-
-If no prefix argument, the prefix argument last time or default
-value of `iedit-occurrence-context-lines' is used for this time."
- (interactive "P")
- (if (null arg)
- ;; toggle visible
- (progn (setq iedit-unmatched-lines-invisible (not iedit-unmatched-lines-invisible))
- (if iedit-unmatched-lines-invisible
- (iedit-hide-unmatched-lines iedit-occurrence-context-lines)
- (iedit-show-all)))
- ;; reset invisible lines
- (setq arg (prefix-numeric-value arg))
- (if (< arg 0)
- (setq arg 0))
- (unless (and iedit-unmatched-lines-invisible
- (= arg iedit-occurrence-context-lines))
- (when iedit-unmatched-lines-invisible
- (remove-overlays nil nil iedit-invisible-overlay-name t))
- (setq iedit-occurrence-context-lines arg)
- (setq iedit-unmatched-lines-invisible t)
- (iedit-hide-unmatched-lines iedit-occurrence-context-lines))))
-
-(defun iedit-show-all()
- "Show hided lines."
- (setq line-move-ignore-invisible nil)
- (remove-from-invisibility-spec '(iedit-invisible-overlay-name . t))
- (remove-overlays nil nil iedit-invisible-overlay-name t))
-
-(defun iedit-hide-unmatched-lines (context-lines)
- "Hide unmatched lines using invisible overlay.
-This function depends on the order of `iedit-occurrences-overlays'. TODO"
- (let ((prev-occurrence-end 1)
- (unmatched-lines nil))
- (save-excursion
- (dolist (overlay iedit-occurrences-overlays)
- (goto-char (overlay-start overlay))
- (forward-line (- context-lines))
- (let ((line-beginning (line-beginning-position)))
- (if (> line-beginning prev-occurrence-end)
- (push (list prev-occurrence-end (1- line-beginning)) unmatched-lines)))
- (goto-char (overlay-end overlay))
- (forward-line context-lines)
- (setq prev-occurrence-end (line-end-position)))
- (if (< prev-occurrence-end (point-max))
- (push (list prev-occurrence-end (point-max)) unmatched-lines))
- (when unmatched-lines
- (set (make-local-variable 'line-move-ignore-invisible) t)
- (add-to-invisibility-spec '(iedit-invisible-overlay-name . t))
- (dolist (unmatch unmatched-lines)
- (iedit-make-unmatched-lines-overlay (car unmatch) (cadr unmatch)))))))
-
-;;;; functions for overlay keymap
-(defun iedit-apply-on-occurrences (function &rest args)
- "Call function for each occurrence."
- (let ((inhibit-modification-hooks t))
- (save-excursion
- (dolist (occurrence iedit-occurrences-overlays)
- (apply function (overlay-start occurrence) (overlay-end occurrence) args)))))
-
-(defun iedit-upcase-occurrences ()
- "Covert occurrences to upper case."
- (interactive "*")
- (iedit-apply-on-occurrences 'upcase-region))
-
-(defun iedit-downcase-occurrences()
- "Covert occurrences to lower case."
- (interactive "*")
- (iedit-apply-on-occurrences 'downcase-region))
-
-(defun iedit-replace-occurrences(to-string)
- "Replace occurrences with STRING.
-This function preserves case."
- (interactive "*sReplace with: ")
- (let* ((ov (iedit-find-current-occurrence-overlay))
- (offset (- (point) (overlay-start ov)))
- (from-string (downcase (buffer-substring-no-properties
- (overlay-start ov)
- (overlay-end ov)))))
- (iedit-apply-on-occurrences
- (lambda (beg end from-string to-string)
- (goto-char beg)
- (search-forward from-string end)
- (replace-match to-string nil))
- from-string to-string)
- (goto-char (+ (overlay-start ov) offset))))
-
-(defun iedit-blank-occurrences()
- "Replace occurrences with blank spaces."
- (interactive "*")
- (let* ((ov (car iedit-occurrences-overlays))
- (offset (- (point) (overlay-start ov)))
- (count (- (overlay-end ov) (overlay-start ov))))
- (iedit-apply-on-occurrences
- (lambda (beg end )
- (delete-region beg end)
- (goto-char beg)
- (insert-and-inherit (make-string count 32))))
- (goto-char (+ (overlay-start ov) offset))))
-
-(defun iedit-delete-occurrences()
- "Delete occurrences."
- (interactive "*")
- (iedit-apply-on-occurrences 'delete-region))
-
-;; todo: add cancel buffering function
-(defun iedit-toggle-buffering ()
- "Toggle buffering.
-This is intended to improve iedit's response time. If the number
-of occurrences are huge, it might be slow to update all the
-occurrences for each key stoke. When buffering is on,
-modification is only applied to the current occurrence and will
-be applied to other occurrences when buffering is off."
- (interactive "*")
- (if iedit-buffering
- (iedit-stop-buffering)
- (iedit-start-buffering))
- (message (concat "Modification Buffering "
- (if iedit-buffering
- "started."
- "stopped."))))
-
-(defun iedit-start-buffering ()
- "Start buffering."
- (setq iedit-buffering t)
- (setq iedit-before-modification-string (iedit-current-occurrence-string))
- (setq iedit-before-modification-undo-list buffer-undo-list)
- (message "Start buffering editing...")
- ;; (setq iedit-mode (propertize
- ;; (concat " Iedit-B:" (number-to-string (length iedit-occurrences-overlays)))
- ;; 'face 'font-lock-warning-face))
- ;; (force-mode-line-update)
- )
-
-(defun iedit-stop-buffering ()
- "Stop buffering and apply the modification to other occurrences.
-If current point is not at any occurrence, the buffered
-modification is not going to be applied to other occurrences."
- (let ((ov (iedit-find-current-occurrence-overlay)))
- (when ov
- (let* ((beg (overlay-start ov))
- (end (overlay-end ov))
- (modified-string (buffer-substring-no-properties beg end))
- (offset (- (point) beg)) ;; delete-region moves cursor
- (inhibit-modification-hooks t))
- (when (not (string= iedit-before-modification-string modified-string))
- (save-excursion
- ;; Rollback the current modification and buffer-undo-list. This is
- ;; to avoid the inconsistency if user undoes modifications
- (delete-region beg end)
- (goto-char beg)
- (insert-and-inherit iedit-before-modification-string)
- (setq buffer-undo-list iedit-before-modification-undo-list)
- (dolist (occurrence iedit-occurrences-overlays) ; todo:extract as a function
- (let ((beginning (overlay-start occurrence))
- (ending (overlay-end occurrence)))
- (delete-region beginning ending)
- (unless (eq beg end) ;; replacement
- (goto-char beginning)
- (insert-and-inherit modified-string))
- (iedit-move-conjoined-overlays occurrence))))
- (goto-char (+ (overlay-start ov) offset))))))
- (setq iedit-buffering nil)
- ;; (setq iedit-mode (propertize
- ;; (concat (if iedit-rectangle " Iedit-RECT:" " Iedit:")
- ;; (number-to-string (length iedit-occurrences-overlays)))
- ;; 'face 'font-lock-warning-face))
- ;; (force-mode-line-update)
- (message "Buffered modification applied.")
- (setq iedit-before-modification-undo-list nil))
-
-(defun iedit-move-conjoined-overlays (occurrence)
- "This function keeps overlays conjoined after modification.
-After modification, conjoined overlays may be overlapped."
- (let ((beginning (overlay-start occurrence))
- (ending (overlay-end occurrence)))
- (unless (= beginning (point-min))
- (let ((previous-overlay (iedit-find-overlay-at-point
- (1- beginning)
- 'iedit-occurrence-overlay-name)))
- (if previous-overlay ; two conjoined occurrences
- (move-overlay previous-overlay
- (overlay-start previous-overlay)
- beginning))))
- (unless (= ending (point-max))
- (let ((next-overlay (iedit-find-overlay-at-point
- ending
- 'iedit-occurrence-overlay-name)))
- (if next-overlay ; two conjoined occurrences
- (move-overlay next-overlay ending (overlay-end next-overlay)))))))
-
-(defvar iedit-number-line-counter 1
- "Occurrence number for 'iedit-number-occurrences.")
-
-(defun iedit-default-occurrence-number-format (start-at)
- (concat "%"
- (int-to-string
- (length (int-to-string
- (1- (+ (length iedit-occurrences-overlays) start-at)))))
- "d "))
-
-(defun iedit-number-occurrences (start-at &optional format-string)
- "Insert numbers in front of the occurrences.
-START-AT, if non-nil, should be a number from which to begin
-counting. FORMAT, if non-nil, should be a format string to pass
-to `format-string' along with the line count. When called
-interactively with a prefix argument, prompt for START-AT and
-FORMAT."
- (interactive
- (if current-prefix-arg
- (let* ((start-at (read-number "Number to count from: " 1)))
- (list start-at
- (read-string "Format string: "
- (iedit-default-occurrence-number-format
- start-at))))
- (list 1 nil)))
- (unless format-string
- (setq format-string (iedit-default-occurrence-number-format start-at)))
- (let ((iedit-number-occurrence-counter start-at)
- (inhibit-modification-hooks t))
- (save-excursion
- (dolist (occurrence iedit-occurrences-overlays)
- (goto-char (overlay-start occurrence))
- (insert (format format-string iedit-number-occurrence-counter))
- (iedit-move-conjoined-overlays occurrence)
- (setq iedit-number-occurrence-counter
- (1+ iedit-number-occurrence-counter))))))
-
-
-;;; help functions
-(defun iedit-find-current-occurrence-overlay ()
- "Return the current occurrence overlay at point or point - 1.
-This function is supposed to be called in overlay keymap."
- (or (iedit-find-overlay-at-point (point) 'iedit-occurrence-overlay-name)
- (iedit-find-overlay-at-point (1- (point)) 'iedit-occurrence-overlay-name)))
-
-(defun iedit-find-overlay-at-point (point property)
- "Return the overlay with PROPERTY at POINT."
- (let ((overlays (overlays-at point))
- found)
- (while (and overlays (not found))
- (let ((overlay (car overlays)))
- (if (overlay-get overlay property)
- (setq found overlay)
- (setq overlays (cdr overlays)))))
- found))
-
-(defun iedit-same-column ()
- "Return t if all occurrences are at the same column."
- (save-excursion
- (let ((column (progn (goto-char (overlay-start (car iedit-occurrences-overlays)))
- (current-column)))
- (overlays (cdr iedit-occurrences-overlays))
- (same t))
- (while (and overlays same)
- (let ((overlay (car overlays)))
- (if (/= (progn (goto-char (overlay-start overlay))
- (current-column))
- column)
- (setq same nil)
- (setq overlays (cdr overlays)))))
- same)))
-
-(defun iedit-same-length ()
- "Return t if all occurrences are the same length."
- (save-excursion
- (let ((length (iedit-occurrence-string-length))
- (overlays (cdr iedit-occurrences-overlays))
- (same t))
- (while (and overlays same)
- (let ((ov (car overlays)))
- (if (/= (- (overlay-end ov) (overlay-start ov))
- length)
- (setq same nil)
- (setq overlays (cdr overlays)))))
- same)))
-
-;; This function might be called out of any occurrence
-(defun iedit-current-occurrence-string ()
- "Return current occurrence string.
-Return nil if occurrence string is empty string."
- (let* ((ov (or (iedit-find-current-occurrence-overlay)
- (car iedit-occurrences-overlays)))
- (beg (overlay-start ov))
- (end (overlay-end ov)))
- (if (and ov (/= beg end))
- (buffer-substring-no-properties beg end)
- nil)))
-
-(defun iedit-occurrence-string-length ()
- "Return the length of current occurrence string."
- (let ((ov (car iedit-occurrences-overlays)))
- (- (overlay-end ov) (overlay-start ov))))
-
-(defun iedit-find-overlay (beg end property &optional exclusive)
- "Return a overlay with property in region, or out of the region if EXCLUSIVE is not nil."
- (if exclusive
- (or (iedit-find-overlay-in-region (point-min) beg property)
- (iedit-find-overlay-in-region end (point-max) property))
- (iedit-find-overlay-in-region beg end property)))
-
-(defun iedit-find-overlay-in-region (beg end property)
- "Return a overlay with property in region."
- (let ((overlays (overlays-in beg end))
- found)
- (while (and overlays (not found))
- (let ((overlay (car overlays)))
- (if (and (overlay-get overlay property)
- (>= (overlay-start overlay) beg)
- (<= (overlay-end overlay) end))
- (setq found overlay)
- (setq overlays (cdr overlays)))))
- found))
-
-(defun iedit-cleanup-occurrences-overlays (beg end &optional inclusive)
- "Remove deleted overlays from list `iedit-occurrences-overlays'."
- (if inclusive
- (remove-overlays beg end iedit-occurrence-overlay-name t)
- (remove-overlays (point-min) beg iedit-occurrence-overlay-name t)
- (remove-overlays end (point-max) iedit-occurrence-overlay-name t))
- (let (overlays)
- (dolist (overlay iedit-occurrences-overlays)
- (if (overlay-buffer overlay)
- (push overlay overlays)))
- (setq iedit-occurrences-overlays (nreverse overlays))))
-
-(defun iedit-printable (string)
- "Return a omitted substring that is not longer than 50.
-STRING is already `regexp-quote'ed"
- (let ((first-newline-index (string-match "$" string))
- (length (length string)))
- (if (and first-newline-index
- (/= first-newline-index length))
- (if (< first-newline-index 50)
- (concat (substring string 0 first-newline-index) "...")
- (concat (substring string 0 50) "..."))
- (if (> length 50)
- (concat (substring string 0 50) "...")
- string))))
-
-(defun iedit-region-active ()
- "Return t if region is active and not empty.
-If variable `iedit-transient-mark-sensitive' is t, active region
-means `transient-mark-mode' is on and mark is active. Otherwise,
-it just means mark is active."
- (and (if iedit-transient-mark-sensitive
- transient-mark-mode
- t)
- mark-active (not (equal (mark) (point)))))
-
-(defun iedit-barf-if-lib-active()
- "Signal error if `iedit-occurrences-overlays' is not nil."
- (or (null iedit-occurrences-overlays )
- (error "Iedit lib is active.")))
-
-(provide 'iedit-lib)
-
-;;; iedit-lib.el ends here
-
-;; LocalWords: iedit el MERCHANTABILITY kbd isearch todo ert Lindberg Tassilo
-;; LocalWords: eval rect defgroup defcustom boolean defvar assq alist nconc
-;; LocalWords: substring cadr keymap defconst purecopy bkm defun princ prev
-;; LocalWords: iso lefttab backtab upcase downcase concat setq autoload arg
-;; LocalWords: refactoring propertize cond goto nreverse progn rotatef eq elp
-;; LocalWords: dolist pos unmatch args ov sReplace iedit's cdr quote'ed
+++ /dev/null
-;;; iedit-rect.el --- visible rectangle editing support based on Iedit.
-
-;; Copyright (C) 2010, 2011, 2012 Victor Ren
-
-;; Time-stamp: <2012-09-05 09:49:55 Victor Ren>
-;; Author: Victor Ren <victorhge@gmail.com>
-;; Keywords: occurrence region simultaneous rectangle refactoring
-;; Version: 0.97
-;; X-URL: http://www.emacswiki.org/emacs/Iedit
-;; Compatibility: GNU Emacs: 22.x, 23.x, 24.x
-
-;; This file is not part of GNU Emacs, but it is distributed under
-;; the same terms as 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:
-
-;; This package also provides rectangle support with *visible rectangle*
-;; highlighting, which is similar with cua-mode rectangle support. But it is
-;; lighter weight and uses iedit mechanisms.
-
-;; The code was developed and fully tested on Gnu Emacs 24.0.93, partially
-;; tested on Gnu Emacs 22. If you have any compatible problem, please let me
-;; know.
-
-;;; todo:
-;; - Add restrict function back
-
-;;; Code:
-
-(eval-when-compile (require 'cl))
-(require 'rect) ;; kill-rectangle
-(require 'iedit-lib)
-
-(defvar iedit-rectangle-mode nil) ;; Name of the minor mode
-
-(make-variable-buffer-local 'iedit-rectangle-mode)
-(or (assq 'iedit-rectangle-mode minor-mode-alist)
- (nconc minor-mode-alist
- (list '(iedit-rectangle-mode iedit-rectangle-mode))))
-
-
-;;; Default key bindings:
-(define-key global-map [C-return] 'iedit-rectangle-mode)
-
-(defvar iedit-rectangle nil
- "This buffer local variable which is the rectangle geometry if
-current mode is iedit-rect. Otherwise it is nil.
-\(car iedit-rectangle) is the top-left corner and
-\(cadr iedit-rectangle) is the bottom-right corner" )
-
-(make-variable-buffer-local 'iedit-rectangle)
-
-;;; Define Iedit rect mode map
-(defvar iedit-rect-keymap
- (let ((map (make-sparse-keymap)))
- (set-keymap-parent map iedit-occurrence-keymap-default)
- (define-key map (kbd "M-K") 'iedit-kill-rectangle)
- map)
- "Keymap used within overlays in Iedit-rect mode.")
-
-(or (assq 'iedit-rectangle-mode minor-mode-map-alist)
- (setq minor-mode-map-alist
- (cons (cons 'iedit-rectangle-mode iedit-lib-keymap) minor-mode-map-alist)))
-
-
-;; Avoid to restore Iedit-rect mode when restoring desktop
-(add-to-list 'desktop-minor-mode-handlers
- '(iedit-rectangle-mode . nil))
-
-;;;###autoload
-(defun iedit-rectangle-mode ()
- "Toggle Iedit-rect mode.
-
-When Iedit-rect mode is on, a rectangle is started with visible
-rectangle highlighting. Rectangle editing support is based on
-Iedit mechanism.
-
-Commands:
-\\{iedit-rect-keymap}"
- (interactive)
- (if iedit-rectangle-mode
- (iedit-rectangle-done)
- (iedit-barf-if-lib-active)
- (if (iedit-region-active)
- (let ((beg (region-beginning))
- (end (region-end)))
- (setq mark-active nil)
- (run-hooks 'deactivate-mark-hook)
- (iedit-rectangle-start beg end)))))
-
-(defun iedit-rectangle-start (beg end)
- "Start Iedit mode for the region as a rectangle."
- (barf-if-buffer-read-only)
- (setq iedit-occurrences-overlays nil)
- (setq iedit-rectangle (list beg end))
- (setq iedit-initial-string-local nil)
- (setq iedit-occurrence-keymap iedit-rect-keymap)
- (save-excursion
- (let ((beg-col (progn (goto-char beg) (current-column)))
- (end-col (progn (goto-char end) (current-column))))
- (when (< end-col beg-col)
- (rotatef beg-col end-col))
- (goto-char beg)
- (loop do (progn
- (push (iedit-make-occurrence-overlay
- (progn
- (move-to-column beg-col t)
- (point))
- (progn
- (move-to-column end-col t)
- (point)))
- iedit-occurrences-overlays)
- (forward-line 1))
- until (> (point) end))
- (setq iedit-occurrences-overlays (nreverse iedit-occurrences-overlays))))
- (setq iedit-rectangle-mode (propertize
- (concat " Iedit-rect:" (number-to-string (length iedit-occurrences-overlays)))
- 'face 'font-lock-warning-face))
- (force-mode-line-update)
- (add-hook 'kbd-macro-termination-hook 'iedit-rectangle-done nil t)
- (add-hook 'change-major-mode-hook 'iedit-rectangle-done nil t)
- (add-hook 'iedit-aborting-hook 'iedit-rectangle-done nil t))
-
-(defun iedit-rectangle-done ()
- "Exit Iedit mode.
-Save the current occurrence string locally and globally. Save
-the initial string globally."
- (when iedit-buffering
- (iedit-stop-buffering))
- (iedit-cleanup)
- (setq iedit-rectangle-mode nil)
- (force-mode-line-update)
- (remove-hook 'kbd-macro-termination-hook 'iedit-rectangle-done t)
- (remove-hook 'change-major-mode-hook 'iedit-rectangle-done t)
- (remove-hook 'iedit-aborting-hook 'iedit-rectangle-done t))
-
-(defun iedit-kill-rectangle(&optional fill)
- "Kill the rectangle.
-The behavior is the same as `kill-rectangle' in rect mode."
- (interactive "*P")
- (or (and iedit-rectangle (iedit-same-column))
- (error "Not a rectangle"))
- (let ((inhibit-modification-hooks t)
- (beg (overlay-start (car iedit-occurrences-overlays)))
- (end (overlay-end (progn (iedit-last-occurrence)
- (iedit-find-current-occurrence-overlay)))))
- (kill-rectangle beg end fill)))
-
-(provide 'iedit-rect)
-
-;;; iedit-rect.el ends here
-
-;; LocalWords: iedit el MERCHANTABILITY kbd isearch todo ert Lindberg Tassilo
-;; LocalWords: eval rect defgroup defcustom boolean defvar assq alist nconc
-;; LocalWords: substring cadr keymap defconst purecopy bkm defun princ prev
-;; LocalWords: iso lefttab backtab upcase downcase concat setq autoload arg
-;; LocalWords: refactoring propertize cond goto nreverse progn rotatef eq elp
-;; LocalWords: dolist pos unmatch args ov sReplace iedit's cdr quote'ed
+++ /dev/null
-;;; iedit-tests.el --- iedit's automatic-tests
-
-;; Copyright (C) 2010, 2011, 2012 Victor Ren
-
-;; Time-stamp: <2012-10-22 14:01:57 Victor Ren>
-;; Author: Victor Ren <victorhge@gmail.com>
-;; Version: 0.97
-;; X-URL: http://www.emacswiki.org/emacs/Iedit
-
-;; This file is not part of GNU Emacs, but it is distributed under
-;; the same terms as 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:
-
-;; This file is part of iedit.
-
-;;; Code:
-(require 'ert)
-(require 'iedit)
-(require 'iedit-rect)
-
-(ert-deftest iedit-compile-test ()
- (let ((byte-compile-error-on-warn t ))
- (should (byte-compile-file "iedit.el"))
- (delete-file "iedit.elc" nil)))
-
-(defun with-iedit-test-fixture (input-buffer-string body)
- "iedit test fixture"
- (let ((old-transient-mark-mode transient-mark-mode)
- (old-iedit-transient-sensitive iedit-transient-mark-sensitive))
- (unwind-protect
- (progn
- (with-temp-buffer
- (transient-mark-mode t)
- (setq iedit-transient-mark-sensitive t)
- (insert input-buffer-string)
- (goto-char 1)
- (iedit-mode)
- (funcall body))
- (with-temp-buffer
- (setq iedit-transient-mark-sensitive nil)
- (transient-mark-mode -1)
- (insert input-buffer-string)
- (goto-char 1)
- (iedit-mode)
- (funcall body)))
- (transient-mark-mode old-transient-mark-mode)
- (setq iedit-transient-mark-sensitive old-transient-mark-mode))))
-
-(ert-deftest iedit-mode-base-test ()
- (with-iedit-test-fixture
-"foo
- foo
- barfoo
- foo"
- (lambda ()
- (should (= 3 (length iedit-occurrences-overlays)))
- (should (string= iedit-initial-string-local "foo"))
- (set-mark-command nil)
- (forward-line 2)
- (iedit-mode)
- (should (= 2 (length iedit-occurrences-overlays)))
- (should (string= iedit-initial-string-local "foo"))
- (iedit-mode)
- (should (null iedit-occurrences-overlays)))))
-
-(ert-deftest iedit-mode-with-region-test ()
- (with-iedit-test-fixture
-"foobar
- foo
- foo
- bar
-foo"
- (lambda ()
- (iedit-mode)
- (goto-char 1)
- (set-mark-command nil)
- (forward-char 3)
- (iedit-mode)
- (should (= 4 (length iedit-occurrences-overlays)))
- (should (string= iedit-initial-string-local "foo"))
- (should (null iedit-only-complete-symbol-local))
- (goto-char 1)
- (set-mark-command nil)
- (forward-line 3)
- (iedit-mode 4)
- (should (= 1 (length iedit-occurrences-overlays))))))
-
-(ert-deftest iedit-move-conjointed-overlays-test ()
- (with-iedit-test-fixture
-"foobar
- foofoofoo
- foofoo
- foo"
- (lambda ()
- (iedit-mode)
- (goto-char 1)
- (set-mark-command nil)
- (forward-char 3)
- (iedit-mode)
- (should (= 7 (length iedit-occurrences-overlays)))
- (should (string= iedit-initial-string-local "foo"))
- (should (null iedit-only-complete-symbol-local))
- (goto-char 1)
- (insert "123")
- (should (string= (buffer-string)
-"123foobar
- 123foo123foo123foo
- 123foo123foo
- 123foo"))
- (forward-char 3)
- (insert "456")
- (should (string= (buffer-string)
-"123foo456bar
- 123foo456123foo456123foo456
- 123foo456123foo456
- 123foo456")))))
-
-(ert-deftest iedit-overlay-at-end-of-buffer ()
- (with-iedit-test-fixture
- "foo
-foo"
- (lambda ()
- (iedit-mode)
- (highlight-changes-mode 1)
- (goto-char (point-min))
- (goto-char (point-at-eol))
- (iedit-mode)
- (delete-region (point) (1- (point)))
- (should (string= (buffer-string)
- "fo
-fo"))
- (insert "b")
- (should (string= (buffer-string)
- "fob
-fob")))))
-
-(ert-deftest iedit-mode-start-from-isearch-test ()
- (with-iedit-test-fixture
-"foo
- foo
- barfoo
- foo"
- (lambda ()
- (should (= 3 (length iedit-occurrences-overlays)))
- (should (string= iedit-initial-string-local "foo"))
- (iedit-mode)
- (forward-line 2)
- (isearch-mode t)
- (isearch-process-search-char ?f)
- (isearch-process-search-char ?o)
- (isearch-process-search-char ?o)
- (call-interactively 'iedit-mode-from-isearch)
- (should (string= iedit-initial-string-local "foo"))
- (should (= 4 (length iedit-occurrences-overlays)))
- (iedit-mode)
- (should (null iedit-occurrences-overlays)))))
-
-(ert-deftest iedit-mode-last-local-occurrence-test ()
- (with-iedit-test-fixture
-"foo
- foo
- barfoo
- foo"
- (lambda ()
- (should (= 3 (length iedit-occurrences-overlays)))
- (should (string= iedit-initial-string-local "foo"))
- (iedit-mode)
- (goto-char 15)
- (iedit-mode 4) ; last local
- (should (string= iedit-initial-string-local "foo"))
- (should (= 3 (length iedit-occurrences-overlays))))))
-
-(ert-deftest iedit-mode-last-global-occurrence-test ()
- (with-iedit-test-fixture
-"foo
- foo
- barfoo
- foo"
- (lambda ()
- (should (= 3 (length iedit-occurrences-overlays)))
- (should (string= iedit-initial-string-local "foo"))
- (iedit-mode)
- (with-temp-buffer
- (insert "bar foo foo")
- (goto-char 1)
- (iedit-mode 16)
- (should (string= iedit-initial-string-local "foo"))
- (should (= 2 (length iedit-occurrences-overlays)))))))
-
-(ert-deftest iedit-execute-last-modification-test ()
- (with-iedit-test-fixture
-"foo
- foo
- barfoo
- foo"
- (lambda ()
- (should (= 3 (length iedit-occurrences-overlays)))
- (should (string= iedit-initial-string-local "foo"))
- (iedit-mode)
- (with-temp-buffer
- (insert "bar foo foo")
- (should-error (iedit-execute-last-modification))))))
-
-(ert-deftest iedit-movement-test ()
- (with-iedit-test-fixture
-"foo
- foo
- barfoo
- foo "
- (lambda ()
- (iedit-last-occurrence)
- (should (= (point) 24))
- (iedit-first-occurrence)
- (should (= (point) 1))
- (iedit-next-occurrence)
- (should (= (point) 7))
- (iedit-next-occurrence)
- (should (= (point) 24))
- (iedit-next-occurrence)
- (should (= (point) 24)) ;; (should (string= (current-message) "This is the last occurrence."))
- (iedit-next-occurrence)
- (should (= (point) 1)) ;; (should (string= (current-message) "Located the first occurrence."))
- (iedit-next-occurrence)
- (should (= (point) 7))
- (goto-char (point-max))
- (iedit-prev-occurrence)
- (should (= (point) 27))
- (iedit-prev-occurrence)
- (should (= (point) 24))
- (iedit-prev-occurrence)
- (should (= (point) 7))
- (iedit-prev-occurrence)
- (should (= (point) 1))
- (iedit-prev-occurrence)
- (should (= (point) 1)) ;; (should (string= (current-message) "This is the first occurrence."))
- (iedit-prev-occurrence)
- (should (= (point) 24)) ;; (should (string= (current-message) "Located the last occurrence."))
- )))
-
-(ert-deftest iedit-occurrence-update-test ()
- (with-iedit-test-fixture
-"foo
- foo
- barfoo
- foo"
- (lambda ()
- (insert "1")
- (should (string= (buffer-string)
-"1foo
- 1foo
- barfoo
- 1foo"))
- (backward-delete-char 1)
- (should (string= (buffer-string)
-"foo
- foo
- barfoo
- foo"))
- (capitalize-word 1)
- (should (string= (buffer-string)
-"Foo
- Foo
- barfoo
- Foo"))
- ;; test insert from empty
- (iedit-delete-occurrences)
- (insert "1")
- (should (string= (buffer-string)
-"1
- 1
- barfoo
- 1")))))
-
-(ert-deftest iedit-aborting-test ()
- (with-iedit-test-fixture
-"foo
- foo
- barfoo
- foo"
- (lambda ()
- (kill-region (point) (+ 4 (point)))
- (should (string= (buffer-string)
-" foo
- barfoo
- foo")))))
-
-(ert-deftest iedit-toggle-case-sensitive-test ()
- (with-iedit-test-fixture
-"foo
- Foo
- barfoo
- foo"
- (lambda ()
- (should (= 2 (length iedit-occurrences-overlays)))
- (iedit-toggle-case-sensitive)
- (should (= 3 (length iedit-occurrences-overlays)))
- (iedit-next-occurrence)
- (iedit-toggle-case-sensitive)
- (should (= 1 (length iedit-occurrences-overlays))))))
-
-(ert-deftest iedit-apply-on-occurrences-test ()
- "Test functions deal with the whole occurrences"
- (with-iedit-test-fixture
-"foo
- foo
- barfoo
- foo"
- (lambda ()
- (iedit-upcase-occurrences)
- (should (string= (buffer-string)
-"FOO
- FOO
- barfoo
- FOO"))
- (iedit-downcase-occurrences)
- (should (string= (buffer-string)
-"foo
- foo
- barfoo
- foo"))
- (iedit-replace-occurrences "bar")
- (should (string= (buffer-string)
-"bar
- bar
- barfoo
- bar"))
- (iedit-number-occurrences 1)
- (should (string= (buffer-string)
-"1 bar
- 2 bar
- barfoo
- 3 bar")))))
-
-(ert-deftest iedit-blank-occurrences-test ()
- "Test functions deal with the whole occurrences"
- (with-iedit-test-fixture
-"foo foo barfoo foo"
- (lambda ()
- (iedit-blank-occurrences)
- (should (string= (buffer-string) " barfoo ")))))
-
-(ert-deftest iedit-blank-occurrences-rectangle-test ()
- "Test functions deal with the whole occurrences"
- (with-iedit-test-fixture
-"foo
- foo barfoo foo"
- (lambda ()
- (iedit-mode) ; turn off iedit
- (goto-char 2)
- (set-mark-command nil)
- (goto-char 7)
- (iedit-rectangle-mode)
- (iedit-blank-occurrences)
- (should (string= (buffer-string) "f o
- oo barfoo foo")))))
-
-(ert-deftest iedit-delete-occurrences-test ()
- "Test functions deal with the whole occurrences"
- (with-iedit-test-fixture
-"foo foo barfoo foo"
- (lambda ()
- (iedit-delete-occurrences)
- (should (string= (buffer-string) " barfoo ")))))
-
-(ert-deftest iedit-toggle-buffering-test ()
- (with-iedit-test-fixture
-"foo
- foo
- barfoo
- foo"
- (lambda ()
- (iedit-toggle-buffering)
- (insert "bar")
- (should (string= (buffer-string)
-"barfoo
- foo
- barfoo
- foo"))
- (iedit-toggle-buffering)
- (should (string= (buffer-string)
-"barfoo
- barfoo
- barfoo
- barfoo"))
- (should (= (point) 4))
- (iedit-toggle-buffering)
- (backward-delete-char 3)
- (should (string= (buffer-string)
-"foo
- barfoo
- barfoo
- barfoo"))
- (goto-char 15) ;not in an occurrence
- (should (null (iedit-find-current-occurrence-overlay)))
- (iedit-toggle-buffering)
- (should (string= (buffer-string)
-"foo
- barfoo
- barfoo
- barfoo")))))
-
-(ert-deftest iedit-rectangle-start-test ()
- (with-iedit-test-fixture
-"foo
- foo
- barfoo
- foo"
- (lambda ()
- (iedit-mode)
- (set-mark-command nil)
- (forward-char 3)
- (forward-line 3)
- (iedit-rectangle-mode)
- (should (equal iedit-rectangle '(1 19))))))
-
-(ert-deftest iedit-kill-rectangle-error-test ()
- (with-iedit-test-fixture
-"foo
- foo
- barfoo
- foo"
- (lambda ()
- (iedit-mode)
- (set-mark-command nil)
- (goto-char 22)
- (iedit-rectangle-mode)
- (should (iedit-same-column))
- (should (equal iedit-rectangle '(1 22)))
- (iedit-prev-occurrence)
- (delete-char -1)
- (should (not (iedit-same-column)))
- (should-error (iedit-kill-rectangle)))))
-
-(ert-deftest iedit-kill-rectangle-test ()
- (with-iedit-test-fixture
-"foo
- foo
- barfoo
- foo"
- (lambda ()
- (iedit-mode)
- (set-mark-command nil)
- (goto-char 22)
- (iedit-rectangle-mode)
- (should (iedit-same-column))
- (should (equal iedit-rectangle '(1 22)))
- (iedit-kill-rectangle)
- (should (string= (buffer-string)
-"
-o
-arfoo
- foo"))
- (should (equal killed-rectangle '("foo" " fo" " b" " "))))))
-
-(ert-deftest iedit-restrict-defun-test ()
- (with-iedit-test-fixture
-"a
-(defun foo (foo bar foo)
-\"foo bar foobar\" nil)
-(defun bar (bar foo bar)
- \"bar foo barfoo\" nil)"
- (lambda ()
- (iedit-mode)
- (emacs-lisp-mode)
- (goto-char 5)
- (iedit-mode)
- (iedit-restrict-function)
- (should (= 1 (length iedit-occurrences-overlays)))
- (iedit-mode)
- (goto-char 13)
- (iedit-mode-toggle-on-function)
- (should (= 4 (length iedit-occurrences-overlays)))
- (iedit-mode)
- (iedit-mode)
- (mark-defun)
- (iedit-mode)
- (should (= 4 (length iedit-occurrences-overlays))))))
-
-(ert-deftest iedit-transient-sensitive-test ()
- (with-iedit-test-fixture
-"a
-(defun foo (foo bar foo)
-\"foo bar foobar\" nil)
-(defun bar (bar foo bar)
- \"bar foo barfoo\" nil)"
- (lambda ()
- (iedit-mode)
- (emacs-lisp-mode)
- (setq iedit-transient-mark-sensitive t)
- (transient-mark-mode -1)
- (goto-char 5)
- (iedit-mode)
- (iedit-restrict-function)
- (should (= 1 (length iedit-occurrences-overlays)))
- (iedit-mode)
- (goto-char 13)
- (iedit-mode 0)
- (should (= 4 (length iedit-occurrences-overlays)))
- (iedit-mode) ;;turn off iedit mode
- (iedit-mode)
- (mark-defun)
- (iedit-mode)
- (should (= 0 (length iedit-occurrences-overlays))))))
-
-(defvar iedit-printable-test-lists
- '(("" "")
- ("abc" "abc")
- ("abc
-bcd" "abc...")
- ("abc\n34" "abc...")
- ("12345678901234567890123456789012345678901234567890abc" "12345678901234567890123456789012345678901234567890...")
- ("12345678901234567890123456789012345678901234567890abc
-abcd" "12345678901234567890123456789012345678901234567890...")))
-
-(ert-deftest iedit-printable-test ()
- (dolist (test iedit-printable-test-lists)
- (should (string= (iedit-printable (car test)) (cadr test)))))
-
-
-;; (elp-instrument-list '(insert-and-inherit
-;; delete-region
-;; goto-char
-;; iedit-occurrence-update
-;; buffer-substring-no-properties
-;; string=
-;; re-search-forward
-;; replace-match))
-
-
-;;; iedit-tests.el ends here
+++ /dev/null
-;;; iedit.el --- Edit multiple regions in the same way simultaneously.
-
-;; Copyright (C) 2010, 2011, 2012 Victor Ren
-
-;; Time-stamp: <2012-10-22 14:14:53 Victor Ren>
-;; Author: Victor Ren <victorhge@gmail.com>
-;; Keywords: occurrence region simultaneous refactoring
-;; Version: 0.97
-;; X-URL: http://www.emacswiki.org/emacs/Iedit
-;; Compatibility: GNU Emacs: 22.x, 23.x, 24.x
-
-;; This file is not part of GNU Emacs, but it is distributed under
-;; the same terms as 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:
-
-;; This package is an Emacs minor mode and allows you to edit one occurrence of
-;; some text in a buffer (possibly narrowed) or region, and simultaneously have
-;; other occurrences edited in the same way.
-;;
-;; Normal scenario of iedit-mode is like:
-;;
-;; - Highlight certain contents - by press C-;
-;; All occurrences of a symbol, string in the buffer or a region may be
-;; highlighted corresponding to current mark, point and prefix argument.
-;; Refer to the document of `iedit-mode' for details.
-;;
-;; - Edit one of the occurrences
-;; The change is applied to other occurrences simultaneously.
-;;
-;; - Finish - by pressing C-; again
-;;
-;; You can also use Iedit mode as a quick way to temporarily show only the
-;; buffer lines that match the current text being edited. This gives you the
-;; effect of a temporary `keep-lines' or `occur'. To get this effect, hit C-'
-;; when in Iedit mode - it toggles hiding non-matching lines.
-;;
-;; Renaming refactoring is convenient in Iedit mode
-;;
-;; - The symbol under point is selected as occurrence by default and only
-;; complete symbols are matched
-;; - With digit prefix argument 0, only symbols in current function are matched
-;; - Restricting symbols in current region can be done by pressing C-; again
-;; - Last renaming refactoring is remembered and can be applied to other buffers
-;; later
-;;
-;; There are also some other facilities you may never think about. Refer to the
-;; document of function `iedit-mode' (C-h f iedit-mode RET) for more details.
-
-;; The code was developed and fully tested on Gnu Emacs 24.0.93, partially
-;; tested on Gnu Emacs 22. If you have any compatible problem, please let me
-;; know.
-
-;;; todo:
-;; - Add more easy access keys for whole occurrence
-
-;;; Contributors
-;; Adam Lindberg <eproxus@gmail.com> added a case sensitivity option that can be toggled.
-
-;; Tassilo Horn <tassilo@member.fsf.org> added an option to match only complete
-;; words, not inside words
-
-;; Le Wang <l26wang@gmail.com> proposed to match only complete symbols, not
-;; inside symbols, contributed rectangle support
-
-;;; Code:
-
-(eval-when-compile (require 'cl))
-(require 'iedit-lib)
-
-(defcustom iedit-current-symbol-default t
- "If no-nil, use current symbol by default for the occurrence."
- :type 'boolean
- :group 'iedit)
-
-(defcustom iedit-only-at-symbol-boundaries t
- "If no-nil, matches have to start and end at symbol boundaries.
-For example, when invoking command `iedit-mode' on the \"in\" in the
- sentence \"The king in the castle...\", the \"king\" is not
- edited."
- :type 'boolean
- :group 'iedit)
-
-(defcustom iedit-toggle-key-default (kbd "C-;")
- "If no-nil, the key is inserted into global-map, isearch-mode-map, esc-map and help-map."
- :type 'vector
- :group 'iedit)
-
-(defvar iedit-mode-hook nil
- "Function(s) to call after starting up an iedit.")
-
-(defvar iedit-mode-end-hook nil
- "Function(s) to call after terminating an iedit.")
-
-(defvar iedit-mode nil) ;; Name of the minor mode
-
-(defvar iedit-only-complete-symbol-local nil
- "This is buffer local variable which indicates the occurrence
-only matches complete symbol.")
-
-(defvar iedit-only-complete-symbol-global nil
- "This is global variable which indicates the last global occurrence
-only matches complete symbol.")
-
-(defvar iedit-last-occurrence-local nil
- "This is buffer local variable which is the occurrence when
-Iedit mode is turned off last time.")
-
-(defvar iedit-last-occurrence-global nil
- "This is global variable which is the occurrence when
-Iedit mode is turned off last time.")
-
-(defvar iedit-last-initial-string-global nil
- "This is a global variable which is the last initial occurrence string.")
-
-(defvar iedit-initial-string-local nil
- "This is buffer local variable which is the initial string to start Iedit mode.")
-(defvar iedit-initial-region nil
- "This is buffer local variable which is the initial region
-where Iedit mode is started from.")
-
-
-(make-variable-buffer-local 'iedit-mode)
-(make-variable-buffer-local 'iedit-only-complete-symbol-local)
-(make-variable-buffer-local 'iedit-last-occurrence-local)
-(make-variable-buffer-local 'iedit-initial-string-local)
-(make-variable-buffer-local 'iedit-initial-region)
-
-
-(or (assq 'iedit-mode minor-mode-alist)
- (nconc minor-mode-alist
- (list '(iedit-mode iedit-mode))))
-
-;;; Define iedit help map.
-(eval-when-compile (require 'help-macro))
-
-(defvar iedit-help-map
- (let ((map (make-sparse-keymap)))
- (define-key map (char-to-string help-char) 'iedit-help-for-help)
- (define-key map [help] 'iedit-help-for-help)
- (define-key map [f1] 'iedit-help-for-help)
- (define-key map "?" 'iedit-help-for-help)
- (define-key map "b" 'iedit-describe-bindings)
- (define-key map "k" 'iedit-describe-key)
- (define-key map "m" 'iedit-describe-mode)
- (define-key map "q" 'help-quit)
- map)
- "Keymap for characters following the Help key for Iedit mode.")
-
-(make-help-screen
- iedit-help-for-help-internal
- (purecopy "Type a help option: [bkm] or ?")
- "You have typed %THIS-KEY%, the help character. Type a Help option:
-\(Type \\<help-map>\\[help-quit] to exit the Help command.)
-
-b Display all Iedit key bindings.
-k KEYS Display full documentation of Iedit key sequence.
-m Display documentation of Iedit mode.
-
-You can't type here other help keys available in the global help map,
-but outside of this help window when you type them in Iedit mode,
-they exit Iedit mode before displaying global help."
- iedit-help-map)
-
-(defun iedit-help-for-help ()
- "Display Iedit help menu."
- (interactive)
- (let (same-window-buffer-names same-window-regexps)
- (iedit-help-for-help-internal)))
-
-(defun iedit-describe-bindings ()
- "Show a list of all keys defined in Iedit mode, and their definitions.
-This is like `describe-bindings', but displays only Iedit keys."
- (interactive)
- (let (same-window-buffer-names
- same-window-regexps
- (keymap (substitute-command-keys "\\{iedit-mode-keymap}\\{iedit-mode-occurrence-keymap}")))
- (with-help-window "*Help*"
- (with-current-buffer standard-output
- (princ "Iedit Mode Bindings: ")
- (princ keymap)))))
-
-(defun iedit-describe-key ()
- "Display documentation of the function invoked by Iedit mode key."
- (interactive)
- (let (same-window-buffer-names same-window-regexps)
- (call-interactively 'describe-key)))
-
-(defun iedit-describe-mode ()
- "Display documentation of Iedit mode."
- (interactive)
- (let (same-window-buffer-names same-window-regexps)
- (describe-function 'iedit-mode)))
-
-;;; Default key bindings:
-(when iedit-toggle-key-default
- (define-key global-map iedit-toggle-key-default 'iedit-mode)
- (define-key isearch-mode-map iedit-toggle-key-default 'iedit-mode-from-isearch)
- (define-key esc-map iedit-toggle-key-default 'iedit-execute-last-modification)
- (define-key help-map iedit-toggle-key-default 'iedit-mode-toggle-on-function))
-
-;; Avoid to restore Iedit mode when restoring desktop
-(add-to-list 'desktop-minor-mode-handlers
- '(iedit-mode . nil))
-
-;;; Define iedit help map.
-(eval-when-compile (require 'help-macro))
-
-(defvar iedit-mode-occurrence-keymap
- (let ((map (make-sparse-keymap)))
- (set-keymap-parent map iedit-occurrence-keymap-default)
- (define-key map (kbd "M-H") 'iedit-restrict-function)
- (define-key map (kbd "M-C") 'iedit-toggle-case-sensitive)
- map)
- "Keymap used within overlays in Iedit mode.")
-
-(defvar iedit-mode-keymap
- (let ((map (make-sparse-keymap)))
- (set-keymap-parent map iedit-lib-keymap)
- (define-key map (char-to-string help-char) iedit-help-map)
- (define-key map [help] iedit-help-map)
- (define-key map [f1] iedit-help-map)
- map)
- "Keymap used while Iedit mode is enabled.")
-
-;;; Define Iedit mode map
-(or (assq 'iedit-mode minor-mode-map-alist)
- (setq minor-mode-map-alist
- (cons (cons 'iedit-mode iedit-mode-keymap) minor-mode-map-alist)))
-
-;; Avoid to restore Iedit mode when restoring desktop
-(add-to-list 'desktop-minor-mode-handlers
- '(iedit-mode . nil))
-
-;;;###autoload
-(defun iedit-mode (&optional arg)
- "Toggle Iedit mode.
-This command behaves differently, depending on the mark, point,
-prefix argument and variable `iedit-transient-mark-sensitive'.
-
-If Iedit mode is off, turn Iedit mode on.
-
-When Iedit mode is turned on, all the occurrences of the current
-region in the buffer (possibly narrowed) or a region are
-highlighted. If one occurrence is modified, the change are
-propagated to all other occurrences simultaneously.
-
-If region is not active, the current symbol (returns from
-`current-word') is used as the occurrence by default. The
-occurrences of the current symbol, but not include occurrences
-that are part of other symbols, are highlighted. If you still
-want to match all the occurrences, even though they are parts of
-other symbols, you may have to mark the symbol first.
-
-In the above two situations, with digit prefix argument 0, only
-occurrences in current function are matched. This is good for
-renaming refactoring in programming.
-
-You can also switch to Iedit mode from isearch mode directly. The
-current search string is used as occurrence. All occurrences of
-the current search string are highlighted.
-
-With an universal prefix argument, the occurrence when Iedit mode
-is turned off last time in current buffer is used as occurrence.
-This is intended to recover last Iedit mode which is turned off.
-If region active, Iedit mode is limited within the current
-region.
-
-With repeated universal prefix argument, the occurrence when
-Iedit mode is turned off last time (might be in other buffer) is
-used as occurrence. If region active, Iedit mode is limited
-within the current region.
-
-If Iedit mode is on and region is active, Iedit mode is
-restricted in the region, e.g. the occurrences outside of the
-region is excluded.
-
-If Iedit mode is on and region is active, with an universal
-prefix argument, Iedit mode is restricted outside of the region,
-e.g. the occurrences in the region is excluded.
-
-Turn off Iedit mode in other situations.
-
-Commands:
-\\{iedit-mode-keymap}
-Keymap used within overlays:
-\\{iedit-mode-occurrence-keymap}"
- (interactive "P")
- (if iedit-mode
- (progn
- (iedit-mode-on-action arg)
- (setq iedit-only-complete-symbol-global iedit-only-complete-symbol-local))
- (iedit-barf-if-lib-active)
- (let (occurrence
- complete-symbol
- (beg (if (eq major-mode 'occur-edit-mode) ; skip the first occurrence
- (next-single-char-property-change 1 'read-only)
- (point-min)))
- (end (point-max)))
- (cond ((and arg
- (= 4 (prefix-numeric-value arg))
- iedit-last-occurrence-local)
- (setq occurrence iedit-last-occurrence-local)
- (setq complete-symbol iedit-only-complete-symbol-local))
- ((and arg
- (= 16 (prefix-numeric-value arg))
- iedit-last-initial-string-global)
- (setq occurrence iedit-last-initial-string-global)
- (setq complete-symbol iedit-only-complete-symbol-global))
- ((iedit-region-active)
- (setq occurrence (buffer-substring-no-properties
- (mark) (point))))
- ((and iedit-current-symbol-default (current-word t))
- (setq occurrence (current-word))
- (when iedit-only-at-symbol-boundaries
- (setq complete-symbol t)))
- (t (error "No candidate of the occurrence, cannot enable Iedit mode")))
- (when arg
- (if (= 0 (prefix-numeric-value arg))
- (save-excursion
- (mark-defun)
- (setq beg (region-beginning))
- (setq end (region-end)))
- (when (iedit-region-active)
- (setq beg (region-beginning))
- (setq end (region-end)))))
- (setq iedit-only-complete-symbol-local complete-symbol)
- (setq mark-active nil)
- (run-hooks 'deactivate-mark-hook)
- (setq iedit-initial-string-local occurrence)
- (iedit-start (iedit-regexp-quote occurrence) beg end))))
-
-(defun iedit-mode-from-isearch (regexp)
- "Start Iedit mode using last search string as the regexp."
- (interactive
- (let ((regexp (cond
- ((functionp isearch-word)
- (funcall isearch-word isearch-string))
- (isearch-word (word-search-regexp isearch-string))
- (isearch-regexp isearch-string)
- (t (regexp-quote isearch-string)))))
- (list regexp)))
- (if (or isearch-regexp isearch-word)
- nil
- (setq iedit-initial-string-local isearch-string))
- (isearch-exit)
- (setq mark-active nil)
- (run-hooks 'deactivate-mark-hook)
- (iedit-start regexp (point-min) (point-max))
- ;; TODO: reconsider how to avoid the loop in iedit-same-length
- (if (iedit-same-length)
- nil
- (iedit-done)
- (message "Matches are not the same length.")))
-
-(defun iedit-start (occurrence-regexp beg end)
- "Start Iedit mode for the `occurrence-regexp' in the current buffer."
- (setq iedit-unmatched-lines-invisible iedit-unmatched-lines-invisible-default)
- (setq iedit-initial-region (list beg end))
- (iedit-start2 occurrence-regexp beg end)
- (run-hooks 'iedit-mode-hook)
- (add-hook 'kbd-macro-termination-hook 'iedit-done nil t)
- (add-hook 'change-major-mode-hook 'iedit-done nil t)
- (add-hook 'iedit-aborting-hook 'iedit-done nil t))
-
-(defun iedit-regexp-quote (exp)
- "Return a regexp string."
- (if iedit-only-complete-symbol-local
- (concat "\\_<" (regexp-quote exp) "\\_>")
- (regexp-quote exp)))
-
-(defun iedit-start2 (occurrence-regexp beg end)
- "Refresh Iedit mode."
- (setq iedit-occurrence-keymap iedit-mode-occurrence-keymap)
- (setq iedit-mode
- (propertize
- (concat " Iedit:"
- (number-to-string
- (iedit-make-occurrences-overlays occurrence-regexp beg end)))
- 'face
- 'font-lock-warning-face))
- (force-mode-line-update))
-
-(defun iedit-done ()
- "Exit Iedit mode.
-Save the current occurrence string locally and globally. Save
-the initial string globally."
- (when iedit-buffering
- (iedit-stop-buffering))
- (setq iedit-last-occurrence-local (iedit-current-occurrence-string))
- (setq iedit-last-occurrence-global iedit-last-occurrence-local)
- (setq iedit-last-initial-string-global iedit-initial-string-local)
-
- (iedit-cleanup)
-
- (setq iedit-initial-string-local nil)
- (setq iedit-mode nil)
- (force-mode-line-update)
- (remove-hook 'kbd-macro-termination-hook 'iedit-done t)
- (remove-hook 'change-major-mode-hook 'iedit-done t)
- (remove-hook 'iedit-aborting-hook 'iedit-done t)
- (run-hooks 'iedit-mode-end-hook))
-
-(defun iedit-mode-on-action (&optional arg)
- "Turn off Iedit mode or restrict it in a region if region is active."
- (if (iedit-region-active)
- ;; Restrict iedit-mode
- (let ((beg (region-beginning))
- (end (region-end)))
- (if (null (iedit-find-overlay beg end 'iedit-occurrence-overlay-name arg))
- (iedit-done)
- (iedit-restrict-region beg end arg)
- (iedit-first-occurrence)))
- (iedit-done)))
-
-
-;;;###autoload
-(defun iedit-mode-toggle-on-function ()
- "Toggle Iedit mode on current function."
- (interactive)
- (iedit-mode 0))
-
-(defun iedit-execute-last-modification (&optional arg)
- "Apply last modification in Iedit mode to the current buffer or an active region."
- (interactive "*P")
- (or (and iedit-last-initial-string-global
- (not (string= iedit-last-initial-string-global iedit-last-occurrence-global)))
- (error "No modification available"))
- (let ((occurrence-exp (regexp-quote iedit-last-initial-string-global))
- (replacement iedit-last-occurrence-global)
- (case-fold-search (not iedit-case-sensitive))
- beg end)
- (when case-fold-search
- (setq occurrence-exp (downcase occurrence-exp))
- (setq replacement (downcase replacement)))
- (if iedit-only-complete-symbol-global
- (setq occurrence-exp (concat "\\_<" occurrence-exp "\\_>")))
- (when (iedit-region-active)
- (setq beg (region-beginning))
- (setq end (region-end)))
- (perform-replace occurrence-exp replacement t t nil nil nil beg end)))
-
-(defun iedit-apply-global-modification ()
- "Apply last global modification."
- (interactive "*")
- (if (and iedit-last-initial-string-global
- (string= iedit-initial-string-local iedit-last-initial-string-global)
- (not (string= iedit-last-initial-string-global iedit-last-occurrence-global)))
- (iedit-replace-occurrences iedit-last-occurrence-global)
- (message "No global modification available.")))
-
-
-(defun iedit-restrict-function(&optional arg)
- "Restricting Iedit mode in current function."
- (interactive "P")
- (save-excursion
- (mark-defun)
- (iedit-restrict-region (region-beginning) (region-end) arg))
- (message "Restricted in current function, %d matches."
- (length iedit-occurrences-overlays)))
-
-(defun iedit-restrict-region (beg end &optional inclusive)
- "Restricting Iedit mode in a region."
- (when iedit-buffering
- (iedit-stop-buffering))
- (setq iedit-last-occurrence-local (iedit-current-occurrence-string))
- (setq mark-active nil)
- (run-hooks 'deactivate-mark-hook)
- (iedit-show-all)
- (iedit-cleanup-occurrences-overlays beg end inclusive)
- (if iedit-unmatched-lines-invisible
- (iedit-hide-unmatched-lines iedit-occurrence-context-lines))
- (setq iedit-mode (propertize
- (concat " Iedit:" (number-to-string
- (length iedit-occurrences-overlays)))
- 'face 'font-lock-warning-face))
- (force-mode-line-update))
-
-(defun iedit-toggle-case-sensitive ()
- "Toggle case-sensitive matching occurrences.
-Todo: how about region"
- (interactive)
- (setq iedit-case-sensitive (not iedit-case-sensitive))
- (if iedit-buffering
- (iedit-stop-buffering))
- (setq iedit-last-occurrence-local (iedit-current-occurrence-string))
- (when iedit-last-occurrence-local
- (remove-overlays nil nil iedit-occurrence-overlay-name t)
- (iedit-show-all)
- (iedit-start2 (iedit-regexp-quote iedit-last-occurrence-local)
- (car iedit-initial-region)
- (cadr iedit-initial-region))))
-
-(provide 'iedit)
-
-;;; iedit.el ends here
-
-;; LocalWords: iedit el MERCHANTABILITY kbd isearch todo ert Lindberg Tassilo
-;; LocalWords: eval defgroup defcustom boolean defvar assq alist nconc
-;; LocalWords: substring cadr keymap defconst purecopy bkm defun princ prev
-;; LocalWords: iso lefttab backtab upcase downcase concat setq autoload arg
-;; LocalWords: refactoring propertize cond goto nreverse progn rotatef eq elp
-;; LocalWords: dolist pos unmatch args ov sReplace iedit's cdr quote'ed
+++ /dev/null
-;;; multi-web-mode.el --- multiple major mode support for web editing
-
-;; Copyright (C) 2012 Fabián Ezequiel Gallina.
-
-;; Author: Fabián E. Gallina <fabian@anue.biz>
-;; URL: https://github.com/fgallina/multi-web-mode
-;; Version: 0.1
-;; Created: Feb 2009
-;; Keywords: convenience, languages, wp
-
-;; This file is part of Multi Web Mode
-
-;; Multi Web Mode 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.
-
-;; Multi Web Mode 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 Multi Web Mode. If not, see <http://www.gnu.org/licenses/>.
-
-;;; Commentary:
-
-;; Multi Web Mode is a minor mode wich makes web editing in Emacs much easier.
-
-;; Basically what it does is select the appropriate major mode
-;; automatically when you move the point and also calculates the
-;; correct indentation of chunks according to the indentation of the
-;; most relevant major mode.
-
-;;
-\f
-;;; Code:
-
-(eval-when-compile
- (require 'cl)
- (defvar multi-web-mode))
-
-(defvar mweb-mode-map
- (let ((mweb-mode-map (make-sparse-keymap)))
- (define-key mweb-mode-map (kbd "M-<f11>") 'mweb-set-default-major-mode)
- (define-key mweb-mode-map (kbd "M-<f12>") 'mweb-set-extra-indentation)
- (define-key mweb-mode-map [remap mark-whole-buffer] 'mweb-mark-whole-buffer)
- mweb-mode-map)
- "Keymaps for command `multi-web-mode'.")
-
-(defvar mweb-mode-hook nil
- "Hooks to run when command `multi-web-mode' is initialized.")
-
-(defvar mweb-extra-indentation 0
- "Extra indentation for chunks.
-Automatically calculated when the major mode has changed.")
-
-(defcustom mweb-default-major-mode nil
- "Default major mode when not in chunk."
- :type 'symbol
- :group 'multi-web-mode
- :safe 'symbolp)
-
-(defcustom mweb-filename-extensions
- nil
- "File extensions that trigger activation.
-
-This is an example configuration:
-'(\"php\" \"htm\" \"html\" \"ctp\" \"phtml\" \"php4\" \"php5\")"
- :type '(list string)
- :group 'multi-web-mode
- :safe #'(lambda (extensions)
- (not (catch 'fail
- (dolist (ext extensions)
- (when (not (stringp ext))
- (throw 'fail t)))))))
-
-;; What you read in the docstring translates to:
-;; ((php-mode "<\\?php\\|<\\? \\|<\\?=" "\\?>")
-;; (js-mode "<script +\\(type=\"text/javascript\"\\|language=\"javascript\"\\)[^>]*>" "</script>")
-;; (css-mode "<style +type=\"text/css\"[^>]*>" "</style>"))
-(defcustom mweb-tags
- nil
- "Tags enabled for command `multi-web-mode'.
-This var is an alist on which each element has the form
-\(major-mode \"open tag regex\" \"close tag regex\").
-
-This is an example configuration:
-
-\(\(php-mode \"<\\\\?php\\|<\\\\? \\|<\\\\?=\" \"\\\\?>\")
- \(js-mode
- \"<script +\\\\(type=\\\"text/javascript\\\"\\\\
-|language=\\\"javascript\\\"\\\\)[^>]*>\"
- \"</script>\")
- \(css-mode \"<style +type=\\\"text/css\\\"[^>]*>\" \"</style>\"))"
- :type '(repeat (symbol string string))
- :group 'multi-web-mode
- :safe #'(lambda (tags)
- (not (catch 'fail
- (dolist (tag tags)
- (when (or
- (not (symbolp (mweb-get-tag-attr tag 'mode)))
- (not (stringp (mweb-get-tag-attr tag 'open)))
- (not (stringp (mweb-get-tag-attr tag 'close))))
- (throw 'fail t)))))))
-
-(defcustom mweb-submode-indent-offset 2
- "Indentation offset for code inside chunks."
- :type 'integer
- :group 'multi-web-mode
- :safe 'integerp)
-
-(defcustom mweb-ignored-commands
- (list
- 'undo
- 'yas/expand
- 'yas/next-field-or-maybe-expand
- 'isearch-forward
- 'isearch-backward
- 'isearch-other-control-char)
- "Commands that prevent changing the major mode."
- :type '(repeat symbol)
- :group 'multi-web-mode
- :safe #'(lambda (names)
- (not (catch 'fail
- (dolist (name names)
- (when (not (symbolp name))
- (throw 'fail t)))))))
-
-(defun mweb-get-tag-attr (tag attribute)
- "Get TAG ATTRIBUTE.
-ATTRIBUTE values can be 'mode to get the tag's major mode or
-'open/'close to get the open/close regexp respectively."
- (case attribute
- (mode (car tag))
- (open (cadr tag))
- (close (caddr tag))))
-
-(defun mweb-get-tag (tag-major-mode)
- "Return tag from `mweb-tags' matching TAG-MAJOR-MODE."
- (assoc tag-major-mode mweb-tags))
-
-(defun mweb--looking-at-tag (&optional type)
- "Return non-nil if pointer is looking at an open or close tag.
-
-Possible values of TYPE are:
- * nil: to check if point is looking at an open or close tag.
- * 'open: to check if point is looking at an open tag
- * 'close: to check if point is looking at a close tag"
- (let ((index 0)
- (looking)
- (open-tag)
- (close-tag)
- (tag-regexp))
- (save-excursion
- (back-to-indentation)
- (while (and (< index (length mweb-tags))
- (not looking))
- (setq open-tag (mweb-get-tag-attr (elt mweb-tags index) 'open))
- (setq close-tag (mweb-get-tag-attr (elt mweb-tags index) 'close))
- (case type
- (open (setq tag-regexp open-tag))
- (close (setq tag-regexp close-tag))
- (otherwise (setq tag-regexp (concat open-tag "\\|" close-tag))))
- (when (looking-at tag-regexp)
- (setq looking t))
- (setq index (+ 1 index))))
- looking))
-
-(defsubst mweb-looking-at-open-tag-p ()
- "Return t if point is looking at an open tag."
- (mweb--looking-at-tag 'open))
-
-(defsubst mweb-looking-at-close-tag-p ()
- "Return t if point is looking at a close tag."
- (mweb--looking-at-tag 'close))
-
-(defsubst mweb-looking-at-tag-p ()
- "Return t if point is looking at an open or close tag."
- (mweb--looking-at-tag))
-
-(defun mweb-change-major-mode ()
- "Call the appropriate major mode for the pointed chunk.
-If the current `major-mode' is the correct one it doesn't funcall the
-major mode and returns nil, otherwise changes the `major-mode' and
-returns a symbol with its name."
- (let ((closest-chunk-point 0)
- (closest-chunk-mode mweb-default-major-mode)
- (result nil))
- (save-restriction
- (widen)
- (dolist (tag mweb-tags)
- (setq result (mweb-closest-starting-chunk-point tag))
- (when (and (integerp result)
- (<= closest-chunk-point result))
- (setq closest-chunk-point result)
- (setq closest-chunk-mode (mweb-get-tag-attr tag 'mode)))))
- (when (not (equal closest-chunk-mode major-mode))
- (funcall closest-chunk-mode)
- closest-chunk-mode)))
-
-(defun mweb-change-indent-line-function ()
- "Set the correct value for `indent-line-function'.
-Depending of `major-mode'."
- (when (not (equal major-mode mweb-default-major-mode))
- (setq indent-line-function 'mweb-indent-line)))
-
-(defun mweb-closest-starting-chunk-point (tag)
- "Return the point of the closest chunk for TAG.
-Where TAG is one of the tags contained in the `mweb-tags'
-list. If the chunk is not found then it returns nil."
- (let ((open-tag)
- (close-tag))
- (save-excursion
- (setq open-tag (re-search-backward (mweb-get-tag-attr tag 'open) nil t)))
- (save-excursion
- (setq close-tag (re-search-backward (mweb-get-tag-attr tag 'close) nil t)))
- (cond ((not open-tag)
- nil)
- ((and open-tag
- (not close-tag))
- open-tag)
- ((> open-tag close-tag)
- open-tag))))
-
-(defun mweb-multiple-chunks-p ()
- "Check if multiple chunks exist in the current buffer."
- (save-excursion
- (save-restriction
- (widen)
- (goto-char (point-min))
- (re-search-forward "[^\s\t\n]" nil t)
- (or (not (mweb-looking-at-open-tag-p))
- (catch 'break
- (dolist (tag mweb-tags)
- (when (re-search-forward (mweb-get-tag-attr tag 'close) nil t)
- (throw 'break (not (not (re-search-forward "[^\s\t\n]" nil t)))))))))))
-
-(defun mweb-update-context ()
- "Update extra indentation value for chunks."
- (let ((changed-major-mode (mweb-change-major-mode)))
- (if (and changed-major-mode
- (not (equal major-mode mweb-default-major-mode)))
- (setq mweb-extra-indentation (mweb-calculate-indentation))
- (setq mweb-extra-indentation 0)))
- (mweb-change-indent-line-function))
-
-(defun mweb-calculate-indentation ()
- "Calculate the correct indentation given previous submode."
- (let ((indentation 0)
- (prev-line-pos)
- (changed-major-mode major-mode)
- (buffer-modified-flag (buffer-modified-p)))
- (save-restriction
- (widen)
- (save-excursion
- (mweb-goto-current-mode-open-tag)
- (if (progn (mweb-forward-nonblank-line -1) (bobp))
- (if (mweb-multiple-chunks-p)
- (setq indentation 0)
- (setq indentation (- mweb-submode-indent-offset)))
- (end-of-line)
- (setq prev-line-pos (point-marker))
- (insert "\na")
- (mweb-change-major-mode)
- (indent-according-to-mode)
- (setq indentation (current-indentation))
- (delete-region prev-line-pos (line-end-position))))
- (funcall changed-major-mode)
- (set-buffer-modified-p buffer-modified-flag)
- indentation)))
-
-(defun mweb-mark-whole-buffer ()
- "Multi-web-mode's version of `mark-whole-buffer'."
- (interactive)
- (push-mark (point))
- (goto-char (point-min))
- (mweb-change-major-mode)
- (push-mark (point-max) nil t))
-
-(defun mweb-indent-line ()
- "Function to use when indenting a submode line."
- (interactive)
- ;; Yes, indent according to mode will do what we expect
- (setq mweb-extra-indentation (mweb-calculate-indentation))
- (if (not (mweb-looking-at-open-tag-p))
- (if (not (mweb-looking-at-close-tag-p))
- ;; Normal indentation
- (if (equal major-mode mweb-default-major-mode)
- (indent-according-to-mode)
- (save-excursion
- (beginning-of-line)
- (delete-horizontal-space)
- (unless (bobp)
- (indent-according-to-mode)
- (indent-to (+ mweb-extra-indentation mweb-submode-indent-offset)))))
- ;; Close tag indentation routine
- (let ((open-tag-indentation 0))
- (save-excursion
- (mweb-goto-current-mode-open-tag)
- (setq open-tag-indentation (current-indentation)))
- (beginning-of-line)
- (delete-horizontal-space)
- (indent-to open-tag-indentation)))
- ;; Open tag indentation routine
- (beginning-of-line)
- (delete-horizontal-space)
- (insert "a")
- (delete-horizontal-space)
- (beginning-of-line)
- (mweb-update-context)
- (indent-according-to-mode)
- (indent-to (+ mweb-extra-indentation mweb-submode-indent-offset))
- (delete-char 1))
- (and (bolp) (back-to-indentation)))
-
-(defun mweb-indent-region (start end)
- "Indent a region taking care of chunks.
-This routine considers the relative position of the chunks within
-the buffer. It follows the same filosophy than
-`mweb-indent-line-forward' because that function is what is used
-to indent the chunks which are not for the default major mode.
-Called from a program, START and END specify the region to indent."
- (interactive "r")
- (let ((delete-active-region nil)
- (line-end))
- (save-excursion
- (goto-char end)
- (setq end (point-marker))
- (goto-char start)
- (mweb-change-major-mode)
- (or (bolp) (forward-line 1))
- (while (< (point) end)
- (mweb-update-context)
- (if (equal major-mode mweb-default-major-mode)
- (indent-according-to-mode)
- (mweb-indent-line))
- (forward-line 1))
- (move-marker end nil))))
-
-(defun mweb-get-current-mode-tag-point (type)
- "Gets the point marker of current chunk's open/close tag.
-
-The TYPE argument can be a 'open for the open tag or 'close for
-the close tag."
- (when (not (equal major-mode mweb-default-major-mode))
- (let ((index 0)
- (found nil)
- (tag)
- (result nil)
- (re-search-func (if (equal type 'open)
- 're-search-backward
- 're-search-forward)))
- (while (and (< index (length mweb-tags))
- (not found))
- (setq tag (elt mweb-tags index))
- (when (or (equal (mweb-get-tag-attr tag 'mode) major-mode)
- (equal major-mode mweb-default-major-mode))
- (setq found t)
- (save-excursion
- (if (looking-at (mweb-get-tag-attr tag type))
- (progn
- (back-to-indentation)
- (setq result (point)))
- (setq result (funcall re-search-func
- (mweb-get-tag-attr tag type)
- nil t)))))
- (setq index (+ 1 index)))
- result)))
-
-(defun mweb-goto-current-mode-open-tag ()
- "Move the point to the open tag of the current chunk."
- (interactive)
- (let ((tag-point (mweb-get-current-mode-tag-point 'open)))
- (when tag-point
- (goto-char tag-point))))
-
-(defun mweb-goto-current-mode-close-tag ()
- "Move the point to the close tag of the current chunk."
- (interactive)
- (let ((tag-point (mweb-get-current-mode-tag-point 'close)))
- (when tag-point
- (goto-char tag-point))))
-
-(defun mweb-set-extra-indentation (number)
- "Set the new value for `mweb-extra-indentation' to NUMBER."
- (interactive "nNew mweb-extra-indentation value: ")
- (setq mweb-extra-indentation number)
- (message "mweb-extra-indentation = %d" mweb-extra-indentation))
-
-(defun mweb-set-default-major-mode (major-mode)
- "Set the new value for `mweb-default-major-mode' to MAJOR-MODE."
- (interactive "CNew default major mode: ")
- (setq mweb-default-major-mode major-mode)
- (mweb-change-major-mode)
- (message "mweb-default-major-mode = %s" mweb-default-major-mode))
-
-(defun mweb-forward-nonblank-line (&optional number)
- "Move the cursor to the next/previous non blank line.
-
-When NUMBER is positive it moves forward and when is negative
-it moves backwards."
- (when (not number)
- (setq number 1))
- (when (> number 1)
- (setq number 1))
- (when (< number -1)
- (setq number -1))
- (forward-line number)
- (while (and (equal (mweb-get-current-line-trimmed-contents) "")
- (not (or (bobp) (eobp))))
- (forward-line number)))
-
-(defun mweb-get-current-line-trimmed-contents ()
- "Gets the contents of the current line.
-It trims all space characters at the beginning and end of the line."
- (let ((start-point)
- (end-point)
- (contents))
- (save-excursion
- (beginning-of-line)
- (setq start-point (point))
- (end-of-line)
- (setq end-point (point))
- (setq contents (buffer-substring start-point end-point))
- (when (string-match "[ \t]*$" contents)
- (setq contents (replace-match "" nil nil contents)))
- (when (string-match "^[ \t]*" contents)
- (setq contents (replace-match "" nil nil contents))))
- contents))
-
-(defun mweb-post-command-hook ()
- "The function which is appended to the `post-command-hook'."
- (when (and multi-web-mode
- (not (region-active-p))
- (not (member last-command mweb-ignored-commands)))
- (mweb-update-context)))
-
-(defun mweb-enable ()
- "Setup the minor mode."
- (set (make-local-variable 'indent-region-function)
- 'mweb-indent-region)
- (make-local-variable 'indent-line-function)
- (add-hook 'post-command-hook 'mweb-post-command-hook)
- (assq-delete-all 'multi-web-mode minor-mode-map-alist)
- (push (cons 'multi-web-mode mweb-mode-map)
- minor-mode-map-alist)
- (run-hooks 'mweb-mode-hook))
-
-(defun mweb-disable ()
- "Disable the minor mode."
- (assq-delete-all 'multi-web-mode minor-mode-map-alist))
-
-;;;###autoload
-(define-minor-mode multi-web-mode
- "Enables the multi web mode chunk detection and indentation"
- :lighter " Multi-Web" :group 'convenience
- (if multi-web-mode
- (mweb-enable)
- (mweb-disable)))
-
-(defun multi-web-mode-maybe ()
- "Used to turn on the globalized minor mode."
- (when (member
- (file-name-extension (or buffer-file-name ""))
- mweb-filename-extensions)
- (multi-web-mode 1)))
-
-(define-globalized-minor-mode multi-web-global-mode
- multi-web-mode multi-web-mode-maybe
- :group 'multi-web-mode
- :require 'multi-web-mode)
-
-(provide 'multi-web-mode)
-;;; multi-web-mode.el ends here
+++ /dev/null
-;; mutt.el --- Use Emacs 20 as an external editor for the Mutt mailer
-;; Copyright 1998 Eric Kidd
-
-;; Author: Eric Kidd <eric.kidd@pobox.com>
-;; Version: $Revision: 1.4 $
-
-;; This is free software distributed under the GPL, yadda, yadda, yadda.
-;; It has no warranty. See the GNU General Public License for more
-;; information. Send me your feature requests and patches, and I'll try
-;; to integrate everything.
-
-;;; Commentary:
-
-;; This is a major mode for use with Mutt, the spiffy *nix mailreader
-;; du jour. See <http://www.cs.hmc.edu/~me/mutt/index.html>. To use this
-;; mode, add the following line to the .emacs file in your home directory:
-;;
-;; (load "/your/local/path/to/this/file/mutt")
-;;
-;; Note that you can omit to ".el" from the file name when calling load.
-;;
-;; If you want to make it available to all your users, type \C-h v
-;; load-path RET, pick an appropriate directory for mutt.el, and modify
-;; your sitewide default.el to (require 'mutt).
-
-
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;;;
-;;; Thanks
-;;;
-;;; Dave Pearson: Code, feature ideas, Mutt experience. Many thanks!
-;;; Louis Theran: Encouragement to make Mutt mode work like Emacs MUAs.
-;;; Ronald: Enlightening gripes about what Emacs should do, but doesn't.
-;;; Robert Napier: Bug reports about font-lock mode, fancy wrapping.
-
-
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;;;
-;;; Revision History
-;;;
-;;; $Log: mutt.el,v $
-;;; Revision 1.4 1998/04/11 00:05:46 emk
-;;; Fixed font-lock bug. Also made mutt-mode a little more careful about
-;;; saving various bits of Emacs state when moving around the buffer.
-;;;
-;;; Revision 1.3 1998/03/25 00:37:36 emk
-;;; Added support for menus and font-lock mode, plus a few bug fixes.
-;;;
-;;; Revision 1.2 1998/03/24 13:19:46 emk
-;;; Major overhaul--more commands, a minor mode for header editing, and other
-;;; desirable features. Attaching files seems to be broken, though.
-;;;
-
-
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;;;
-;;; Required Packages
-
-(require 'derived)
-(require 'cl) ; Big but featureful. Do we need this?
-(require 'easymenu)
-
-
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;;;
-;;; Customization Support
-;;;
-;;; Set up our customizable features. You can edit these (and lots of other
-;;; fun stuff) by typing M-x customize RET. The Mutt preferences can be
-;;; found under the [Applications] [Mail] category.
-
-(defgroup mutt nil
- "Composing e-mail messages with Mutt.
-Emacs can run as an external editor for Mutt, the spiffy Unix mail reader
-du jour. You can get Mutt from <http://www.cs.hmc.edu/~me/mutt/index.html>."
- :group 'mail)
-
-(defcustom mutt-uses-fill-mode t
- "*Specifies whether Mutt should automatically wrap lines.
-Set this to t to enable line wrapping, and nil to disable line
-wrapping. Note that if a paragraph gets messed up (the line wrapper
-is very primitive), you can type \\[fill-paragraph] to rewrap the paragraph."
- :type 'boolean
- :group 'mutt)
-
-(defcustom mutt-signature-pattern "\\(--\\|Cheers,\\|\f\\)"
- "*Pattern for identifying signatures.
-Mutt uses this to locate signatures. It should contain no leaading or
-trailing whitespace."
- :type 'string
- :group 'mutt)
-
-(defcustom mutt-file-pattern "mutt-[a-z]+-[0-9]+-[0-9]+\\'"
- "*Regular expression which matches Mutt's temporary files."
- :type 'string
- :group 'mutt)
-
-
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;;;
-;;; Customizable Faces
-;;; The dark background versions are probably uglier than the light
-;;; (which I use). If you find a more attractive, subdued color scheme,
-;;; please mail it to me.
-
-(defgroup mutt-faces nil
- "Typefaces used for composing messages with Mutt."
- :group 'mutt
- :group 'faces)
-
-(defface mutt-header-keyword-face
- '((((class color)
- (background light))
- (:foreground "Navy" :bold t))
- (((class color)
- (background dark))
- (:foreground "LightBlue" :bold t))
- (t
- (:bold t)))
- "Face used for displaying keywords (e.g. \"From:\") in headers."
- :group 'mutt-faces)
-
-(defface mutt-header-value-face
- '((((class color)
- (background light))
- (:foreground "MidnightBlue"))
- (((class color)
- (background dark))
- (:foreground "LightSteelBlue")))
- "Face used for displaying the values of headers."
- :group 'mutt-faces)
-
-(defface mutt-quoted-text-face
- '((((class color)
- (background light))
- (:foreground "Sienna" :italic t))
- (((class color)
- (background dark))
- (:foreground "Wheat" :italic t))
- (t
- (:bold t :italic t)))
- "Face used for displaying text which has been quoted (e.g. \">foo\")."
- :group 'mutt-faces)
-
-(defface mutt-multiply-quoted-text-face
- '((((class color)
- (background light))
- (:foreground "Firebrick" :italic t))
- (((class color)
- (background dark))
- (:foreground "Tan" :italic t))
- (t
- (:italic t)))
- "Face used for text which has been quoted more than once (e.g. \">>foo\")."
- :group 'mutt-faces)
-
-(defvar mutt-font-lock-keywords
- '(("^\\([A-Z][-A-Za-z0-9.]+:\\)\\(.*\\)$"
- (1 'mutt-header-keyword-face)
- (2 'mutt-header-value-face))
- ("^[ \t\f]*\\(>[ \t\f]*[^ \t\f>].*\\)$"
- (1 'mutt-quoted-text-face))
- ("^[ \t\f]*\\(>[ \t\f]*\\)\\(>.*\\)$"
- (1 'mutt-quoted-text-face)
- (2 'mutt-multiply-quoted-text-face)))
- "Highlighting rules for message mode.")
-
-
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;;;
-;;; Interactive Commands
-
-(defun mutt-save-current-buffer-and-exit ()
- "Save the current buffer and exit Emacs."
- (interactive)
- (basic-save-buffer)
- (save-buffers-kill-emacs))
-
-(defun mutt-delete-quoted-signatures ()
- "Delete quoted signatures from buffer."
- (interactive)
- (goto-char (point-min))
- (flush-lines (concat "^\\([ \t\f]*>[ \t\f>]*\\)"
- mutt-signature-pattern
- "[ \t\f]*\\(\n\\1.*\\)*")))
-
-(defun mutt-delete-old-citations ()
- "Delete citations more than one level deep from buffer."
- (interactive)
- (goto-char (point-min))
- (flush-lines "^[ \t\f]*>[ \t\f]*>[ \t\f>]*"))
-
-(defun mutt-goto-body ()
- "Go to the beginning of the message body."
- (interactive)
- (goto-char (point-min))
- ;; If the message has headers, slide downward.
- (and headers-mode
- (save-match-data (re-search-forward "^$" nil t))
- (next-line 1)))
-
-(defun mutt-goto-signature ()
- "Go to the beginning of the message signature."
- (interactive)
- (goto-char (point-max))
- (and (save-match-data
- (re-search-backward (concat "^" mutt-signature-pattern
- "[ \t\f]*$")
- nil t))
- (previous-line 1)))
-
-
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;;;
-;;; Mutt Mode Meat
-
-(define-derived-mode mutt-mode text-mode "Mutt"
- "Major mode for composing E-mail with the Mutt mailer.
-To customize it, type \\[customize] and select [Applications] [Mail] [Mutt].
-When you finish editing this message, type \\[mutt-save-current-buffer-and-exit] to save and exit Emacs.
-
-\\{mutt-mode-map}"
-
- (rename-buffer "*Composing*" t)
- (auto-fill-mode (if mutt-uses-fill-mode 1 0))
-
- ;; Make Emacs smarter about wrapping citations and paragraphs.
- ;; We probably can't handle Supercited messages, though.
- (make-local-variable 'paragraph-start)
- (make-local-variable 'paragraph-separate)
- (setq paragraph-start
- "\\([ \t\n\f]+[^ \t\n\f>]\\|[ \t\f>]*$\\)"
- paragraph-separate
- "[ \t\f>]*$")
-
- ;; If Mutt passed us headers, activate the necessary commands.
- (when (looking-at "^[-A-Za-z0-9]+:")
- (headers-mode 1))
-
- ;; Our temporary file lives in /tmp. Yuck! Compensate appropriately.
- (make-local-variable 'backup-inhibited)
- (setq backup-inhibited t)
- (cd "~")
-
- (make-local-variable 'font-lock-defaults)
- (setq font-lock-defaults '(mutt-font-lock-keywords t))
-
- (mutt-goto-body)
- (message (substitute-command-keys "Type \\[describe-mode] for help composing; \\[mutt-save-current-buffer-and-exit] when done.")))
-
-
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;;;
-;;; Mutt Headers Mode
-
-(defvar headers-mode nil)
-
-(defun headers-mode (&optional arg)
- "Commands for editing the headers of an e-mail or news message.
-
-\\{headers-mode-map}"
-
- (interactive "P")
- (make-local-variable 'headers-mode)
- (setq headers-mode
- (if (null arg)
- (not headers-mode)
- (> (prefix-numeric-value arg) 0)))
- (force-mode-line-update))
-
-(defvar headers-mode-map (make-sparse-keymap)
- "Keymap used for editing RFC822 headers.")
-
-(defun headers-position-on-value ()
- (beginning-of-line)
- (skip-chars-forward "-A-Za-z0-9:")
- ;; XXX - Should make sure we stay on line.
- (forward-char))
-
-(defun headers-goto-field (field)
- (let ((case-fold-search t))
- (goto-char (point-min))
- (save-match-data
- (when (re-search-forward (concat "^\\($\\|" field ": \\)"))
- (if (looking-at "^$")
- (progn
- (insert-string field ": \n")
- (forward-char -1))
- (headers-position-on-value))))))
-
-(defmacro define-header-goto (name header)
- `(defun ,name ()
- ,(concat "Position the cursor on the " header ": header.")
- (interactive)
- (headers-goto-field ,header)))
-
-(define-header-goto headers-goto-to "To")
-(define-header-goto headers-goto-cc "Cc")
-(define-header-goto headers-goto-fcc "Fcc")
-(define-header-goto headers-goto-summary "Summary")
-(define-header-goto headers-goto-keywords "Keywords")
-(define-header-goto headers-goto-subject "Subject")
-(define-header-goto headers-goto-bcc "Bcc")
-(define-header-goto headers-goto-reply-to "Reply-To")
-(define-header-goto headers-goto-from "From")
-(define-header-goto headers-goto-organization "Organization")
-
-(defun headers-attach-file (file description)
- "Attach a file to the current message (works with Mutt)."
- (interactive "fAttach file: \nsDescription: ")
- (when (> (length file) 0)
- (save-excursion
- (save-match-data
- (save-restriction
- (widen)
- (goto-char (point-min))
- (search-forward-regexp "^$")
- (insert-string (concat "Attach: " (file-truename file) " "
- description "\n"))
- (message (concat "Attached '" file "'.")))))))
-
-(or (assq 'headers-mode minor-mode-alist)
- (setq minor-mode-alist
- (cons '(headers-mode " Headers") minor-mode-alist)))
-
-(or (assq 'headers-mode minor-mode-map-alist)
- (setq minor-mode-map-alist
- (cons (cons 'headers-mode headers-mode-map)
- minor-mode-map-alist)))
-
-
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;;;
-;;; Key Bindings
-
-(define-key mutt-mode-map "\C-c\C-c" 'mutt-save-current-buffer-and-exit)
-(define-key mutt-mode-map "\C-c\C-d\C-s" 'mutt-delete-quoted-signatures)
-(define-key mutt-mode-map "\C-c\C-d\C-c" 'mutt-delete-old-citations)
-(define-key mutt-mode-map "\C-c\C-b" 'mutt-goto-body)
-(define-key mutt-mode-map "\C-c\C-i" 'mutt-goto-signature)
-
-(define-key headers-mode-map "\C-c\C-f\C-t" 'headers-goto-to)
-(define-key headers-mode-map "\C-c\C-f\C-c" 'headers-goto-cc)
-(define-key headers-mode-map "\C-c\C-f\C-w" 'headers-goto-fcc)
-(define-key headers-mode-map "\C-c\C-f\C-u" 'headers-goto-summary)
-(define-key headers-mode-map "\C-c\C-f\C-k" 'headers-goto-keywords)
-(define-key headers-mode-map "\C-c\C-f\C-s" 'headers-goto-subject)
-(define-key headers-mode-map "\C-c\C-f\C-b" 'headers-goto-bcc)
-(define-key headers-mode-map "\C-c\C-f\C-r" 'headers-goto-reply-to)
-(define-key headers-mode-map "\C-c\C-f\C-f" 'headers-goto-from)
-(define-key headers-mode-map "\C-c\C-f\C-o" 'headers-goto-organization)
-(define-key headers-mode-map "\C-c\C-a" 'headers-attach-file)
-
-
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;;;
-;;; Menus
-
-(easy-menu-define
- mutt-mode-menu mutt-mode-map "Mutt Message Composition Commands."
- '("Mutt"
- ["Delete Quoted Signatures" mutt-delete-quoted-signatures t]
- ["Delete Doubly-Quoted Text" mutt-delete-old-citations t]
- "----"
- ["Go To Body of Message" mutt-goto-body t]
- ["Go To Signature of Message" mutt-goto-signature t]
- "----"
- ["Save Message and Return to Mutt" mutt-save-current-buffer-and-exit t]))
-
-(easy-menu-define
- headers-mode-menu headers-mode-map "Header Editing Commands."
- '("Headers"
- ["Attach File..." headers-attach-file t]
- "----"
- ["Edit From Header" headers-goto-from t]
- ["Edit Subject Header" headers-goto-subject t]
- ["Edit To Header" headers-goto-to t]
- ["Edit Cc Header" headers-goto-cc t]
- ["Edit Bcc Header" headers-goto-bcc t]
- ["Edit Fcc Header" headers-goto-fcc t]
- ["Edit Reply-To Header" headers-goto-reply-to t]
- ["Edit Summary Header" headers-goto-summary t]
- ["Edit Keywords Header" headers-goto-keywords t]
- ["Edit Organization Header" headers-goto-organization t]))
-
-
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;;;
-;;; Finish Installing Mutt Mode
-
-(unless (assq mutt-file-pattern auto-mode-alist)
- (setq auto-mode-alist
- (cons (cons mutt-file-pattern 'mutt-mode)
- auto-mode-alist)))
-
-(provide 'mutt)
+++ /dev/null
-;;; org-google-weather.el --- Show Google Weather forecasts in Org agenda.
-
-;; Copyright (C) 2010 Julien Danjou
-
-;; Author: Julien Danjou <julien@danjou.info>
-;; Keywords: comm
-
-;; This file is NOT 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:
-;; This module allows to display the weather forecast fetched from Google in
-;; your Org agenda.
-;;
-;; Wednesday 8 September 2010
-;; Weather: Pluie, 12/18 ℃
-;; Thursday 9 September 2010
-;; Weather: Couverture nuageuse partielle, 11/21 ℃
-;;
-;; Just add the following in an Org buffer:
-;; %%(org-google-weather)
-;;
-;;; Code:
-
-(require 'google-weather)
-(require 'image)
-(require 'format-spec)
-(require 'solar)
-
-(defgroup org-google-weather nil
- "Google Weather for Org mode."
- :group 'comm
- :group 'org)
-
-(defcustom org-google-weather-location calendar-location-name
- "Default location for org-google-weather."
- :group 'org-google-weather)
-
-(defcustom org-google-weather-format "%i %c, [%l,%h] %s"
- "String to return to describe the weather.
-Valid %-sequences are:
- - %i the icon
- - %c means the weather condition
- - %L the supplied location
- - %C the city the weather is for
- - %l the lower temperature
- - %h the higher temperature
- - %s the temperature unit symbol")
-
-(defcustom org-google-weather-cache-time 43200
- "Define for how many seconds we should cache the weather."
- :group 'org-google-weather)
-
-(defcustom org-google-weather-display-icon-p t
- "Display icons."
- :group 'org-google-weather)
-
-(defcustom org-google-weather-icon-directory "/usr/share/icons/gnome/16x16/status"
- "Directory where to find icon listed in `org-google-weather-icon-alist'."
- :group 'org-google-weather)
-
-(defcustom org-google-weather-icon-alist
- '((chance_of_rain . "weather-showers-scattered.png")
- (chance_of_snow . "weather-snow.png")
- (chance_of_storm . "weather-storm.png")
- (cn_cloudy . "weather-overcast.png")
- (cn_heavyrun . "weather-showers.png")
- (cn_sunny . "weather-clear.png")
- (cloudy . "weather-overcast.png")
- (dust . "weather-fog.png")
- (flurries . "weather-storm.png")
- (fog . "weather-fog.png")
- (haze . "weather-fog.png")
- (icy . "weather-snow.png")
- (jp_sunny . "weather-clear.png")
- (jp_cloudy . "weather-overcast.png")
- (mist . "weather-storm.png")
- (mostly_cloudy . "weather-overcast.png")
- (mostly_sunny . "weather-clear.png")
- (partly_cloudy . "weather-few-clouds.png")
- (rain . "weather-showers.png")
- (rain_snow . "weather-snow.png")
- (sleet . "weather-snow.png")
- (smoke . "weather-fog.png")
- (snow . "weather-snow.png")
- (storm . "weather-storm.png")
- (thunderstorm . "weather-storm.png")
- (sunny . "weather-clear.png"))
- "Icons to use to illustrate the weather."
- :group 'org-google-weather)
-
-(defcustom org-google-weather-use-google-icons nil
- "Fetch icons from Google or use local ones.
-If you decide to use local ones, you should check
-`org-google-weather-icon-directory' and
-`org-google-weather-icon-alist'. Otherwise, if you want to use
-icons from Google, you have nothing to do."
- :group 'org-google-weather
- :type 'boolean)
-
-(defun org-google-weather-get-icon (url)
- (with-current-buffer
- (google-weather-retrieve-data-raw url org-google-weather-cache-time)
- (goto-char (point-min))
- (unless (search-forward "\n\n" nil t)
- (error "Data not found"))
- (let ((data (buffer-substring (point) (point-max))))
- (kill-buffer (current-buffer))
- data)))
-
-;;;###autoload
-(defun org-google-weather (&optional location language)
- "Return Org entry with the weather for LOCATION in LANGUAGE.
-If LOCATION is not set, use org-google-weather-location."
- (let* ((location (or location org-google-weather-location))
- (data (ignore-errors
- (google-weather-get-data location
- language
- org-google-weather-cache-time)))
- (problem-cause (when data (google-weather-data->problem-cause data)))
- (forecast (when (and (null problem-cause) data)
- (google-weather-data->forecast-for-date data date))))
- (if problem-cause
- (message "%s: %s" location problem-cause)
- (when forecast
- (let ((condition (cadr (assoc 'condition forecast)))
- (low (cadr (assoc 'low forecast)))
- (high (cadr (assoc 'high forecast)))
- (city (google-weather-data->city data))
- ;; But *they* told me it's just about calling functions!
- (icon (when (and org-google-weather-display-icon-p (display-images-p))
- (if org-google-weather-use-google-icons
- (create-image (org-google-weather-get-icon
- (cadr (assoc 'icon forecast)))
- nil t)
- (create-image
- (concat
- org-google-weather-icon-directory
- "/"
- (cdr
- (assoc
- (intern
- (file-name-sans-extension
- (file-name-nondirectory
- (cadr (assoc 'icon forecast)))))
- org-google-weather-icon-alist)))))))
- (temp-symbol (google-weather-data->temperature-symbol data)))
- (format-spec org-google-weather-format
- `((?i . ,(if icon
- (propertize "icon"
- 'display
- (append
- icon '(:ascent center))
- 'rear-nonsticky '(display))
- ""))
- (?c . ,condition)
- (?L . ,location)
- (?C . ,city)
- (?l . ,low)
- (?h . ,high)
- (?s . ,temp-symbol))))))))
-
-(provide 'org-google-weather)
+++ /dev/null
-;;; vcl-mode.el --- Major mode for Varnish Configuration Language -*- lexical-binding:t -*-
-
-;; Author: Sergey Poznyakoff <gray@gnu.org.ua>
-;; Version: 1.1
-;; Keywords: Varnish, VCL
-
-;; Copyright (C) 2015-2018 Free Software Foundation, Inc.
-
-;; This program is free software; you can redistribute it and/or modify
-;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 3 of the License, or
-;; (at your option) any later version.
-
-;; This program is distributed in the hope that it will be useful,
-;; but WITHOUT ANY WARRANTY; without even the implied warranty of
-;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-;; GNU General Public License for more details.
-
-;; You should have received a copy of the GNU General Public License
-;; along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-;;; Commentary:
-
-;; Emacs support for Varnish's configuration language:
-;; https://varnish-cache.org/docs/trunk/users-guide/vcl.html
-;; This version of vcl-mode supports VCL-4.0.
-
-;; The features provided are auto-indentation (based on CC-mode's
-;; engine), keyword highlighting, and matching of {"..."} multi-line
-;; string delimiters.
-
-;; If you need support for VCL-2.0, you might have more luck with the older
-;; package: https://github.com/ssm/elisp/blob/master/vcl-mode.el
-
-;;; Code:
-
-(require 'cc-mode)
-(require 'cc-langs)
-
-(defvar vcl-mode-map
- (let ((map (make-sparse-keymap)))
- (set-keymap-parent map c-mode-base-map)
- (define-key map "\C-c%" 'vcl-match-paren)
- map)
- "Keymap used in vcl-mode buffers.")
-
-(defvar vcl-mode-syntax-table
- (let ((st (make-syntax-table)))
- (modify-syntax-entry ?\n "> b" st)
- ;; Use comment style `b' to match the style used for \n!
- (modify-syntax-entry ?\# "< b" st)
- (modify-syntax-entry ?/ ". 124b" st)
- (modify-syntax-entry ?* ". 23" st)
- (modify-syntax-entry ?+ "." st)
- (modify-syntax-entry ?- "." st)
- (modify-syntax-entry ?~ "." st)
- (modify-syntax-entry ?= "." st)
- (modify-syntax-entry ?% "." st)
- (modify-syntax-entry ?< "." st)
- (modify-syntax-entry ?> "." st)
- (modify-syntax-entry ?& "." st)
- (modify-syntax-entry ?| "." st)
- (modify-syntax-entry ?_ "_" st)
- (modify-syntax-entry ?\' "." st)
- (modify-syntax-entry ?\" "\"" st)
- st)
- "Syntax table in use in VCL Mode buffers.")
-
-(define-abbrev-table 'vcl-mode-abbrev-table
- '(("else" "else" c-electric-continued-statement :system t))
- "Abbreviation table used in vcl-mode buffers.")
-
-;; Font locking
-(defconst vcl-font-lock-keywords-1
- (eval-when-compile
- (list
- ;; Version declaration
- '("^[ \t]*\\(vcl\\)\\>[ \t]*\\([[:digit:]]+\\.[[:digit:]]+\\)"
- (1 font-lock-keyword-face) (2 font-lock-constant-face nil t))
- ;; Built-ins
- (cons
- (concat "\\<"
- (regexp-opt
- '("vcl_init"
- "vcl_recv"
- "vcl_pipe"
- "vcl_pass"
- "vcl_hash"
- "vcl_hit"
- "vcl_miss"
- "vcl_fetch"
- "vcl_deliver"
- "vcl_error"
- "vcl_fini"
- "vcl_synth"
- "vcl_backend_fetch"
- "vcl_backend_response"
- "vcl_backend_error") t)
- "\\>")
- 'font-lock-builtin-face)
- ;; Keywords
- (cons
- (concat "\\<"
- (regexp-opt
- '("sub"
- "import"
- "include"
- "backend"))
- "\\>")
- 'font-lock-keyword-face)
- ))
- "Subdued level highlighting for VCL buffers.")
-
-(defconst vcl-font-lock-keywords-2
- (append vcl-font-lock-keywords-1
- (eval-when-compile
- (list
- ;; Keywords
- (cons
- (concat "\\<"
- (regexp-opt
- '("acl"
- "if"
- "else"
- "return"
- "call"
- "set"
- "remove"
- "unset"
- "director"
- "probe"))
- "\\>")
- 'font-lock-keyword-face)
- ;; Return values
- (cons
- (concat "\\<"
- (regexp-opt
- '("error"
- "fetch"
- "hash"
- "hit_for_pass"
- "lookup"
- "ok"
- "pass"
- "pipe"
- "deliver"
- "restart"
- "true"
- "false"))
- "\\>")
- 'font-lock-constant-face)
- ;; Functions
- (cons
- (concat "\\<"
- (regexp-opt
- '("ban"
- "call"
- "hash_data"
- "new"
- "synth"
- "synthetic"
- "regsub"
- "regsuball"))
- "\\>")
- 'font-lock-function-name-face)
-
- ;; Objects and variables
- ;; See https://www.varnish-cache.org/docs/4.0/reference/vcl.html#variables
- (list (concat "\\<"
- (regexp-opt
- '("req"
- "resp"
- "bereq"
- "beresp"
- "obj")
- t)
- "\\.\\(http\\)\\(\\.\\([a-zA-Z_-][a-zA-Z_0-9-]*\\)\\)?")
- '(1 font-lock-builtin-face)
- '(2 font-lock-builtin-face)
- '(4 font-lock-string-face nil t))
- (list (concat "\\<\\(bereq\\)\\."
- (regexp-opt
- '("backend"
- "between_bytes_timeout"
- "connect_timeout"
- "first_byte_timeout"
- "method"
- "proto"
- "retries"
- "uncacheable"
- "url"
- "xid")
- t))
- '(1 font-lock-builtin-face)
- '(2 font-lock-builtin-face))
- (list (concat "\\<\\(beresp\\)\\.\\(backend\\)\\."
- (regexp-opt
- '("name"
- "ip")
- t))
- '(1 font-lock-builtin-face)
- '(2 font-lock-builtin-face)
- '(3 font-lock-builtin-face))
- (list (concat "\\<\\(beresp\\)\\."
- (regexp-opt
- '("do_esi"
- "do_gunzip"
- "do_gzip"
- "do_stream"
- "grace"
- "keep"
- "proto"
- "reason"
- "status"
- "storage_hint"
- "ttl"
- "uncacheable")
- t))
- '(1 font-lock-builtin-face)
- '(2 font-lock-builtin-face))
- (list (concat "\\<\\(client\\)\\."
- (regexp-opt
- '("identity"
- "ip")
- t))
- '(1 font-lock-builtin-face)
- '(2 font-lock-builtin-face))
- (list (concat "\\<\\(obj\\)\\."
- (regexp-opt
- '("grace"
- "hits"
- "keep"
- "proto"
- "reason"
- "status"
- "ttl"
- "uncacheable")
- t))
- '(1 font-lock-builtin-face)
- '(2 font-lock-builtin-face))
- (list (concat "\\<\\(req\\)\\."
- (regexp-opt
- '("backend_hint"
- "can_gzip"
- "esi"
- "esi_level"
- "hash_always_miss"
- "hash_ignore_busy"
- "method"
- "proto"
- "restarts"
- "ttl"
- "url"
- "xid")
- t))
- '(1 font-lock-builtin-face)
- '(2 font-lock-builtin-face))
- (list (concat "\\<\\(resp\\)\\."
- (regexp-opt
- '("proto"
- "reason"
- "status")
- t))
- '(1 font-lock-builtin-face)
- '(2 font-lock-builtin-face))
- (list (concat "\\<\\(server\\)\\."
- (regexp-opt
- '("hostname"
- "identity"
- "ip")
- t))
- '(1 font-lock-builtin-face)
- '(2 font-lock-builtin-face))
- (list (concat "\\<\\(storage\\)\\.\\(\\sw+\\)\\."
- (regexp-opt
- '("free_space"
- "used_space"
- "happy")
- t))
- '(1 font-lock-builtin-face)
- '(2 font-lock-variahle-name-face)
- '(3 font-lock-builtin-face))
-
- (cons
- (concat "\\<"
- (regexp-opt
- '("req"
- "resp"
- "bereq"
- "beresp"
- "client"
- "server"
- "obj"
- "now"))
- "\\>")
- 'font-lock-builtin-face)
-
- ;; Function calls
- '("\\<\\(\\(\\sw+\\)\\.\\)*\\(\\sw+\\)[ \t]*("
- (2 font-lock-variable-name-face nil t)
- (3 font-lock-function-name-face))
-
- ;; Constants
- '("\\<\\([[:digit:]]+\\(\\.[[:digit:]]+\\)?\\)[ \t]*\\(ms\\|[smhdwy]\\)?\\>"
- (1 font-lock-constant-face) (3 font-lock-builtin-face nil t)))))
- "Medium level highlighting for VCL buffers.")
-
-(defconst vcl-font-lock-keywords-3
- (append vcl-font-lock-keywords-2
- (eval-when-compile
- (list
- ;; User function names.
- '("^[ \t]*\\(sub\\)\\>[ \t]*\\(\\sw+\\)?"
- (1 font-lock-keyword-face) (2 font-lock-function-name-face nil t)))))
- "Gaudy level highlighting for VCL buffers.")
-
-(defvar vcl-font-lock-keywords vcl-font-lock-keywords-3)
-
-(put 'vcl-mode 'c-mode-prefix "vcl-")
-
-(defconst vcl-syntax-propertize-function
- (syntax-propertize-rules
- ("\\({\\)\""
- (1 (when (null (nth 8 (save-excursion
- (syntax-ppss (match-beginning 0)))))
- (string-to-syntax "|"))))
- ("\"\\(}\\)"
- (1 (when (eq t (nth 3 (save-excursion
- (syntax-ppss (match-beginning 0)))))
- (string-to-syntax "|"))))))
-
-(defun vcl-match-paren (&optional arg)
- ;; FIXME: Assuming syntax-propertize works correctly, forward-sexp and
- ;; backward-sexp should do the trick!
- "If point is on a parenthesis (including VCL multi-line string delimiter),
-find the matching one and move point to it.
-With ARG, do it that many times."
- (interactive "p")
- (let ((n (or arg 1))
- (matcher (cond
- ((looking-at "\\s(")
- (cons
- (let ((s (match-string 0)))
- (lambda ()
- (search-forward s)
- (backward-char)))
- (lambda ()
- (forward-list)
- (backward-char))))
- ((looking-at "\\s)")
- (cons
- (let ((s (match-string 0)))
- (lambda ()
- (search-backward s)))
- (lambda ()
- (forward-char)
- (backward-list))))
- ((or (looking-at "{\"")
- (save-excursion
- (backward-char)
- (looking-at "{\"")))
- (cons
- (lambda ()
- (search-forward "{\""))
- (lambda ()
- (search-forward-regexp "\"}")
- (backward-char))))
- ((or (looking-at "\"}")
- (save-excursion
- (backward-char)
- (looking-at "\"}")))
- (cons
- (lambda ()
- (search-backward "\"}"))
- (lambda ()
- (search-backward-regexp "{\"")))))))
- (if (not matcher)
- (message "Point not at parenthesis")
- (condition-case err
- (let ((fx (car matcher))
- (fn (cdr matcher)))
- (catch 'stop
- (while t
- (funcall fn)
- (setq n (1- n))
- (if (= n 0)
- (throw 'stop t)
- (condition-case nil
- (funcall fx)
- (search-failed
- (message "Not enough groups to satisfy the request")
- (throw 'stop t)))))))
-
- (scan-error (goto-char (nth 2 err))
- (message "%s" (nth 1 err)))
- (search-failed (message "Unbalanced %s" (cdr err)))))))
-
-;;;###autoload
-(add-to-list 'auto-mode-alist (cons (purecopy "\\.vcl\\'") 'vcl-mode))
-
-;;;###autoload
-(define-derived-mode vcl-mode prog-mode "VCL"
- "Major mode for editing Varnish Configuration Language code.
-
-Key bindings:
-\\{vcl-mode-map}"
- :abbrev-table vcl-mode-abbrev-table
- (set (make-local-variable 'syntax-propertize-function)
- vcl-syntax-propertize-function)
- (set (make-local-variable 'parse-sexp-lookup-properties) t)
-
- (c-initialize-cc-mode t)
- (c-lang-setvar comment-start "# ")
- (setq c-opt-cpp-prefix nil)
- (setq abbrev-mode t)
- (c-init-language-vars vcl-mode)
- (c-common-init 'vcl-mode)
-
- (run-mode-hooks 'c-mode-common-hook 'vcl-mode-hook)
- (c-update-modeline))
-
-;;;; ChangeLog:
-
-;; 2018-11-30 Stefan Monnier <monnier@iro.umontreal.ca>
-;;
-;; * vcl-mode/vcl-mode.el: Simplify syntax handling; plus cosmetics
-;;
-;; Use lexical-binding. Don't require `cl`.
-;; (vcl-mode-map): Move initialization into declaration. Don't rely on
-;; CC-mode's c-make-inherited-keymap.
-;; (vcl-mode-syntax-table): Use comment style b for `#` and mark `"` as a
-;; string delimiter.
-;; (vcl-mode-abbrev-table): Simplify definition.
-;; (vcl-font-lock-keywords-2): Don't request explicit subgroups if not
-;; used.
-;; (vcl-sharp-comment-syntax): Remove function.
-;; (vcl-syntax-propertize-function): Remove special cases for `#` and `"`.
-;; Refine `{"` and `"}` to filter out false positives.
-;; (vcl-match-paren): Use match-string.
-;; (vcl-mode): Let define-derived-mode set syntax-table, local-map, and
-;; abbrev-table. Use run-mode-hooks.
-;;
-;; 2018-11-29 Stefan Monnier <monnier@iro.umontreal.ca>
-;;
-;; * vcl-mode.el: Update header and fix last line; improve commentary
-;;
-;; 2018-11-29 Stefan Monnier <monnier@iro.umontreal.ca>
-;;
-;; Add 'packages/vcl-mode/' from commit
-;; 'd6bba7c13e0d72936001f5adea155256151339ac'
-;;
-;; git-subtree-dir: packages/vcl-mode git-subtree-mainline:
-;; c0c44c3c0ded215e5bc60da74e2aaa090a35617b git-subtree-split:
-;; d6bba7c13e0d72936001f5adea155256151339ac
-;;
-
-
-(provide 'vcl-mode)
-;;; vcl-mode.el ends here