--- /dev/null
+;;; anything-config.el --- predefined configurations for anything
+
+;; Copyright (C) 2007 Tassilo Horn
+
+;; Maintainer: Tassilo Horn <tassilo@member.fsf.org>
+
+;; Contributors:
+;; Tamas Patrovics
+;; Tassilo Horn <tassilo@member.fsf.org>
+;; Vagn Johansen <gonz808@hotmail.com>
+;; Mathias Dahl <mathias.dahl@gmail.com>
+;; Bill Clementson <billclem@gmail.com>
+;; Stefan Kamphausen (see http://www.skamphausen.de for more informations)
+;; Drew Adams <drew.adams@oracle.com>
+;; Jason McBrayer <jmcbray@carcosa.net>
+
+;; This file is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation; either version 2, or (at your option)
+;; any later version.
+
+;; This file is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs; see the file COPYING. If not, write to the
+;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
+
+;;; Commentary:
+
+;;
+;; This package provides predefined configurations for anything.el. To enable
+;; it, put this into your `user-init-file'.
+;;
+;; (require 'anything-config) ; loads anything.el too
+;;
+;; To configure anything you should tweak the variables `anything-sources' and
+;; `anything-type-attributes'. See the default configuration at the bottom of
+;; this file. Copy and modify it to your needs.
+;;
+;; (setq anything-sources ...)
+;; (setq anything-type-attributes ...)
+;;
+
+;;; Bugs and TODOs:
+
+;;
+;; - TODO: anything-c-adaptive stores infos for sources/types that don't have
+;; set it as `filtered-candidate-transformer'.
+;;
+;; - TODO: The Imenu source is broken for very recent emacsen. It seems to
+;; work with 22.1, though.
+;;
+
+;;; Startup
+
+;;; (require 'anything)
+
+;;; Version
+
+(defvar anything-c-version "<2008-08-13 Wed 14:49>"
+ "The version of anything-config.el, or better the date of the
+last change.")
+
+;;; Keymaps
+
+(defvar anything-c-use-standard-keys t
+ "If non-nil the keybindings of anything will be the standard
+bindings used in most parts of emacs, e.g. M-p/M-n for minibuffer
+history, C-s for isearch, etc.
+
+If it's nil anything uses some bindings that don't conflict with
+`iswitchb', e.g. C-p/C-n for the minibuffer history. If you use
+`iswitchb' you probably should say nil here.")
+
+(when anything-c-use-standard-keys
+ (setq anything-map
+ (let ((map (copy-keymap minibuffer-local-map)))
+ (define-key map (kbd "<down>") 'anything-next-line)
+ (define-key map (kbd "<up>") 'anything-previous-line)
+ (define-key map (kbd "C-n") 'anything-next-line)
+ (define-key map (kbd "C-p") 'anything-previous-line)
+ (define-key map (kbd "<prior>") 'anything-previous-page)
+ (define-key map (kbd "<next>") 'anything-next-page)
+ (define-key map (kbd "M-v") 'anything-previous-page)
+ (define-key map (kbd "C-v") 'anything-next-page)
+ (define-key map (kbd "<right>") 'anything-next-source)
+ (define-key map (kbd "<left>") 'anything-previous-source)
+ (define-key map (kbd "<RET>") 'anything-exit-minibuffer)
+ (define-key map (kbd "C-1") 'anything-select-with-digit-shortcut)
+ (define-key map (kbd "C-2") 'anything-select-with-digit-shortcut)
+ (define-key map (kbd "C-3") 'anything-select-with-digit-shortcut)
+ (define-key map (kbd "C-4") 'anything-select-with-digit-shortcut)
+ (define-key map (kbd "C-5") 'anything-select-with-digit-shortcut)
+ (define-key map (kbd "C-6") 'anything-select-with-digit-shortcut)
+ (define-key map (kbd "C-7") 'anything-select-with-digit-shortcut)
+ (define-key map (kbd "C-8") 'anything-select-with-digit-shortcut)
+ (define-key map (kbd "C-9") 'anything-select-with-digit-shortcut)
+ (define-key map (kbd "<tab>") 'anything-select-action)
+ (defalias 'anything-next-history-element 'next-history-element)
+ (defalias 'anything-previous-history-element 'previous-history-element)
+ (define-key map (kbd "M-p") 'anything-previous-history-element)
+ (define-key map (kbd "M-n") 'anything-next-history-element)
+ (define-key map (kbd "C-s") 'anything-isearch)
+ (define-key map (kbd "C-r") 'undefined)
+ map))
+
+ (setq anything-isearch-map
+ (let ((map (copy-keymap (current-global-map))))
+ (define-key map (kbd "<return>") 'anything-isearch-default-action)
+ (define-key map (kbd "<tab>") 'anything-isearch-select-action)
+ (define-key map (kbd "C-g") 'anything-isearch-cancel)
+ (define-key map (kbd "C-s") 'anything-isearch-again)
+ (define-key map (kbd "C-r") 'undefined)
+ (define-key map (kbd "<backspace>") 'anything-isearch-delete)
+ ;; add printing chars
+ (let ((i ?\s))
+ (while (< i 256)
+ (define-key map (vector i) 'anything-isearch-printing-char)
+ (setq i (1+ i))))
+ map)))
+
+;;; Sources
+
+;;;; Match functions
+
+(defun anything-c-match-on-file-name (candidate)
+ "Return non-nil if `anything-pattern' matches the
+filename (without directory part) of CANDIDATE."
+ (string-match anything-pattern (file-name-nondirectory candidate)))
+
+(defun anything-c-match-on-directory-name (candidate)
+ "Return non-nil if `anything-pattern' matches the directory
+part of CANDIDATE (a file)."
+ (let ((dir (file-name-directory candidate)))
+ (when dir
+ (string-match anything-pattern dir))))
+
+(defun anything-c-string-match (candidate)
+ "Return non-nil if `anything-pattern' matches CANDIDATE.
+The match is done with `string-match'."
+ (string-match anything-pattern candidate))
+
+;;;; Buffers
+
+(defun anything-c-buffer-list ()
+ "Return the list of names of buffers with the `anything-buffer'
+and hidden buffers filtered out. The first buffer in the list
+will be the last recently used buffer that is not the current
+buffer."
+ (let ((buffers (remove-if (lambda (name)
+ (or (equal name anything-buffer)
+ (eq ?\ (aref name 0))))
+ (mapcar 'buffer-name (buffer-list)))))
+ (append (cdr buffers) (list (car buffers)))))
+
+(defvar anything-c-source-buffers
+ '((name . "Buffers")
+ (candidates . anything-c-buffer-list)
+ (volatile)
+ (type . buffer)))
+
+(defun anything-c-define-dummy-source (name func &rest other-attrib)
+ `((name . ,name)
+ (candidates "dummy")
+ ,@other-attrib
+ (filtered-candidate-transformer
+ . (lambda (candidates source)
+ (funcall ',func)))
+ (requires-pattern . 1)
+ (volatile)
+ (category create)))
+
+(defun anything-c-dummy-candidate ()
+ ;; `source' is defined in filtered-candidate-transformer
+ (list (cons (concat (assoc-default 'name source)
+ " '" anything-input "'")
+ anything-input)))
+
+(defvar anything-c-source-buffer-not-found
+ (anything-c-define-dummy-source
+ "Create buffer"
+ (lambda () (unless (get-buffer anything-input)
+ (anything-c-dummy-candidate)))
+ '(type . buffer)))
+
+;;;; File name history
+
+(defvar anything-c-source-file-name-history
+ '((name . "File Name History")
+ (candidates . file-name-history)
+ (match . (anything-c-match-on-file-name
+ anything-c-match-on-directory-name))
+ (type . file)))
+
+;;;; Recentf files
+
+(defvar anything-c-source-recentf
+ '((name . "Recentf")
+ (candidates . recentf-list)
+ (match . (anything-c-match-on-file-name
+ anything-c-match-on-directory-name))
+ (type . file))
+ "See (info \"(emacs)File Conveniences\").")
+
+;;;; Files in current dir
+
+(defvar anything-c-source-files-in-current-dir
+ '((name . "Files from Current Directory")
+ (init . (lambda ()
+ (setq anything-c-default-directory
+ default-directory)))
+ (candidates . (lambda ()
+ (directory-files
+ anything-c-default-directory)))
+ (volatile)
+ (type . file)))
+
+;;;; Man Pages
+
+(defvar anything-c-man-pages nil
+ "All man pages on system.
+Will be calculated the first time you invoke anything with this
+source.")
+
+(defvar anything-c-source-man-pages
+ `((name . "Manual Pages")
+ (candidates . (lambda ()
+ (if anything-c-man-pages
+ anything-c-man-pages
+ ;; XEmacs doesn't have a woman :)
+ (setq anything-c-man-pages
+ (condition-case nil
+ (progn
+ (require 'woman)
+ (woman-file-name "")
+ (sort (mapcar 'car
+ woman-topic-all-completions)
+ 'string-lessp))
+ (error nil))))))
+ (action . (("Show with Woman" . woman)))
+ (requires-pattern . 2)))
+
+;;;; Info pages
+
+(defvar anything-c-info-pages nil
+ "All info pages on system.
+Will be calculated the first time you invoke anything with this
+source.")
+
+(defvar anything-c-source-info-pages
+ `((name . "Info Pages")
+ (candidates
+ . (lambda ()
+ (if anything-c-info-pages
+ anything-c-info-pages
+ (setq anything-c-info-pages
+ (save-window-excursion
+ (save-excursion
+ (require 'info)
+ (Info-find-node "dir" "top")
+ (goto-char (point-min))
+ (let ((info-topic-regexp "\\* +\\([^:]+: ([^)]+)[^.]*\\)\\.")
+ topics)
+ (while (re-search-forward info-topic-regexp nil t)
+ (add-to-list 'topics (match-string-no-properties 1)))
+ (goto-char (point-min))
+ (Info-exit)
+ topics)))))))
+ (action . (("Show with Info" .(lambda (node-str)
+ (info (replace-regexp-in-string "^[^:]+: "
+ ""
+ node-str))))))
+ (requires-pattern . 2)))
+
+;;;; Complex command history
+
+(defvar anything-c-source-complex-command-history
+ '((name . "Complex Command History")
+ (candidates . (lambda ()
+ (mapcar 'prin1-to-string
+ command-history)))
+ (volatile)
+ (type . sexp)))
+
+;;;; Emacs commands
+
+(defvar anything-c-source-emacs-commands
+ '((name . "Emacs Commands")
+ (candidates . (lambda ()
+ (let (commands)
+ (mapatoms (lambda (a)
+ (if (commandp a)
+ (push (symbol-name a)
+ commands))))
+ (sort commands 'string-lessp))))
+ (volatile)
+ (type . command)
+ (requires-pattern . 2))
+ "Source for completing and invoking Emacs commands. A command
+is a function with interactive spec that can be invoked with
+`M-x'.
+
+To get non-interactive functions listed, use
+`anything-c-source-emacs-functions'.")
+
+;;;; Emacs functions
+
+;;;;; Normal
+
+(defvar anything-c-source-emacs-functions
+ '((name . "Emacs Functions")
+ (candidates . (lambda ()
+ (let (commands)
+ (mapatoms (lambda (a)
+ (if (functionp a)
+ (push (symbol-name a)
+ commands))))
+ (sort commands 'string-lessp))))
+ (volatile)
+ (type . function)
+ (requires-pattern . 2))
+ "Source for completing Emacs functions.")
+
+;;;;; With abbrev expansion similar to my exec-abbrev-cmd.el
+
+;; See http://www.tsdh.de/cgi-bin/wiki.pl/exec-abbrev-cmd.el
+
+(defvar anything-c-function-abbrev-regexp nil
+ "Regexp built from the current `anything-pattern' interpreting
+it as abbreviation. Only for internal use.")
+
+(defun anything-c-match-function-by-abbrev (candidate)
+ "Return non-nil if `anything-pattern' is an abbreviation of the
+function CANDIDATE.
+
+Abbreviations are made by taking the first character from each
+word in the function's name, e.g. \"bb\" is an abbrev for
+`bury-buffer', \"stb\" is an abbrev for `switch-to-buffer'."
+ (string-match anything-c-function-abbrev-regexp candidate))
+
+(defvar anything-c-source-emacs-functions-with-abbrevs
+ (append anything-c-source-emacs-functions
+ '((match . (anything-c-match-function-by-abbrev
+ anything-c-string-match)))
+ '((init . (lambda ()
+ (defadvice anything-update
+ (before anything-c-update-function-abbrev-regexp activate)
+ (let ((char-list (append anything-pattern nil))
+ (str "^"))
+ (dolist (c char-list)
+ (setq str (concat str (list c) "[^-]*-")))
+ (setq str (concat (substring str 0 (1- (length str))) "$"))
+ (setq anything-c-function-abbrev-regexp str))))))))
+
+;;;; Bookmarks
+
+(defvar anything-c-source-bookmarks
+ '((name . "Bookmarks")
+ (init . (lambda ()
+ (require 'bookmark)))
+ (candidates . bookmark-all-names)
+ (type . bookmark))
+ "See (info \"(emacs)Bookmarks\").")
+
+;;;; Picklist
+
+(defvar anything-c-source-picklist
+ '((name . "Picklist")
+ (candidates . (lambda ()
+ (mapcar 'car picklist-list)))
+ (volatile)
+ (type . file)))
+
+;;;; Imenu
+
+(defvar anything-c-source-imenu
+ '((name . "Imenu")
+ (init . (lambda ()
+ (setq anything-c-imenu-current-buffer
+ (current-buffer))))
+ (candidates . (lambda ()
+ (condition-case nil
+ (with-current-buffer anything-c-imenu-current-buffer
+ (mapcar (lambda (x)
+ (cons (car x) x))
+ ;; leave only top level completions for
+ ;; simplicity (could be more sophisticated)
+ (remove-if-not (lambda (x)
+ (markerp (cdr x)))
+ (imenu--make-index-alist))))
+ (error nil))))
+ (volatile)
+ (action . imenu)))
+
+;;;; File Cache
+
+(defvar anything-c-source-file-cache-initialized nil)
+
+(defvar anything-c-file-cache-files nil)
+
+(defvar anything-c-source-file-cache
+ '((name . "File Cache")
+ (init . (lambda ()
+ (unless anything-c-source-file-cache-initialized
+ (setq anything-c-file-cache-files
+ (loop for item in file-cache-alist append
+ (destructuring-bind (base &rest dirs) item
+ (loop for dir in dirs collect
+ (concat dir base)))))
+ (defadvice file-cache-add-file (after file-cache-list activate)
+ (add-to-list 'anything-c-file-cache-files (expand-file-name file)))
+ (setq anything-c-source-file-cache-initialized t))))
+ (candidates . anything-c-file-cache-files)
+ (match . (anything-c-match-on-file-name
+ anything-c-match-on-directory-name))
+ (type . file)))
+
+;;;; Locate
+
+(defvar anything-c-locate-options (if (eq system-type 'darwin)
+ '("locate")
+ '("locate" "-i" "-r"))
+ "A list where the `car' is the name of the locat program
+followed by options. The search pattern will be appended, so the
+\"-r\" option should be the last option.")
+
+(defvar anything-c-source-locate
+ '((name . "Locate")
+ (candidates . (lambda ()
+ (apply 'start-process "locate-process" nil
+ (append anything-c-locate-options
+ (list anything-pattern)))))
+ (type . file)
+ (requires-pattern . 3)
+ (delayed))
+ "Source for retrieving files matching the current input pattern
+with locate.")
+
+;;;; Tracker desktop search
+
+(defvar anything-c-source-tracker-search
+ '((name . "Tracker Search")
+ (candidates . (lambda ()
+ (start-process "tracker-search-process" nil
+ "tracker-search"
+ anything-pattern)))
+ (type . file)
+ (requires-pattern . 3)
+ (delayed))
+ "Source for retrieving files matching the current input pattern
+with the tracker desktop search.")
+
+;;;; Spotlight (MacOS X desktop search)
+
+(defvar anything-c-source-mac-spotlight
+ '((name . "mdfind")
+ (candidates . (lambda ()
+ (start-process "mdfind-process" nil
+ "mdfind" anything-pattern)))
+ (type . file)
+ (requires-pattern . 3)
+ (delayed))
+ "Source for retrieving files via Spotlight's command line
+utility mdfind.")
+
+;;;; BBDB
+
+(defun anything-c-bbdb-candidates ()
+ "Return a list of all names in the bbdb database. The format
+is \"Firstname Lastname\"."
+ (mapcar (lambda (bbdb-record)
+ (concat (aref bbdb-record 0) " " (aref bbdb-record 1)))
+ (bbdb-records)))
+
+(defun anything-c-bbdb-create-contact (actions candidate)
+ "Action transformer that returns only an entry to add the
+current `anything-pattern' as new contact. All other actions are
+removed."
+ (if (string= candidate "*Add to contacts*")
+ '(("Add to contacts"
+ . (lambda (actions)
+ (bbdb-create-internal
+ (read-from-minibuffer "Name: " anything-c-bbdb-name)
+ (read-from-minibuffer "Company: ")
+ (read-from-minibuffer "Email: ")
+ nil
+ nil
+ (read-from-minibuffer "Note: ")))))
+ actions))
+
+(defvar anything-c-bbdb-name nil
+ "Only for internal use.")
+
+(defvar anything-c-source-bbdb
+ '((name . "BBDB")
+ (candidates . anything-c-bbdb-candidates)
+ (volatile)
+ (action ("View person's data" . (lambda (candidate)
+ (bbdb candidate nil)
+ (set-buffer "*BBDB*")
+ (bbdb-redisplay-one-record (bbdb-current-record))))
+ ("Send a mail" . (lambda (candidate)
+ (let ((rec (progn
+ (bbdb candidate nil)
+ (set-buffer "*BBDB*")
+ (bbdb-current-record))))
+ (bbdb-send-mail rec)))))
+ (filtered-candidate-transformer . (lambda (candidates source)
+ (setq anything-c-bbdb-name anything-pattern)
+ (if (not candidates)
+ (list "*Add to contacts*")
+ candidates)))
+ (action-transformer . (lambda (actions candidate)
+ (anything-c-bbdb-create-contact actions candidate)))))
+
+;;;; Evaluation Result
+
+(defvar anything-c-source-evaluation-result
+ '((name . "Evaluation Result")
+ (requires-pattern)
+ (match (lambda (candidate) t))
+ (candidates "dummy")
+ (filtered-candidate-transformer
+ . (lambda (candidates source)
+ (list
+ (condition-case nil
+ (prin1-to-string
+ (eval (read anything-pattern)))
+ (error "error")))))
+ (volatile)
+ (action ("Do Nothing" . ignore))))
+
+;;;; Calculation Result
+
+(defvar anything-c-source-calculation-result
+ '((name . "Calculation Result")
+ (requires-pattern)
+ (match (lambda (candidate) t))
+ (candidates "dummy")
+ (filtered-candidate-transformer
+ . (lambda (candidates source)
+ (list
+ (condition-case nil
+ (calc-eval anything-pattern)
+ (error "error")))))
+ (volatile)
+ (action ("Do Nothing" . ignore))))
+
+;;;; Google Suggestions
+
+(defvar anything-c-source-google-suggest
+ '((name . "Google Suggest")
+ (candidates
+ . (lambda ()
+ (let ((suggestions (anything-c-google-suggest-fetch anything-input)))
+ (if (some (lambda (suggestion)
+ (equal (cdr suggestion) anything-input))
+ suggestions)
+ suggestions
+ ;; if there is no suggestion exactly matching the input then
+ ;; prepend a Search on Google item to the list
+ (append (list (cons (concat "Search for "
+ "'" anything-input "'"
+ " on Google")
+ anything-input))
+ suggestions)))))
+ (action . (("Google Search" .
+ (lambda (candidate)
+ (browse-url (concat anything-c-google-suggest-search-url
+ (url-hexify-string candidate)))))))
+ (volatile)
+ (requires-pattern . 3)
+ (delayed)))
+
+(defvar anything-c-google-suggest-url
+ "http://www.google.com/complete/search?hl=en&js=true&qu="
+ "URL used for looking up suggestions.")
+
+(defvar anything-c-google-suggest-search-url
+ "http://www.google.com/search?ie=utf-8&oe=utf-8&q="
+ "URL used for searching.")
+
+(defun anything-c-google-suggest-fetch (input)
+ "Fetch suggestions for INPUT."
+ (let* ((result (with-current-buffer
+ (url-retrieve-synchronously
+ (concat anything-c-google-suggest-url
+ (url-hexify-string input)))
+ (buffer-substring (point-min) (point-max))))
+ (split (split-string result "new Array("))
+ (suggestions (anything-c-google-suggest-get-items (second split)))
+ (numbers (anything-c-google-suggest-get-items (third split)))
+ (longest (+ (apply 'max 0 (let (lengths)
+ (dotimes (i (length suggestions))
+ (push (+ (length (nth i suggestions))
+ (length (nth i numbers)))
+ lengths))
+ lengths))
+ 10))
+ items)
+ (dotimes (i (length suggestions))
+ (let ((suggestion (nth i suggestions))
+ (number (nth i numbers)))
+ (push (cons (concat suggestion
+ (make-string (- longest
+ (length suggestion)
+ (length number))
+ 32)
+ number)
+ suggestion)
+ items)))
+ items))
+
+(defun anything-c-google-suggest-get-items (str)
+ "Extract items from STR returned by Google Suggest."
+ (let ((start nil)
+ items)
+ (while (string-match "\"\\([^\"]+?\\)\"" str start)
+ (push (match-string 1 str) items)
+ (setq start (1+ (match-end 1))))
+ items))
+
+;;;; Jabber Contacts (jabber.el)
+
+(defun anything-c-jabber-online-contacts ()
+ "List online Jabber contacts."
+ (let (jids)
+ (dolist (item (jabber-concat-rosters) jids)
+ (when (get item 'connected)
+ (push (if (get item 'name)
+ (cons (get item 'name) item)
+ (cons (symbol-name item) item)) jids)))))
+
+(defvar anything-c-source-jabber-contacts
+ '((name . "Jabber Contacts")
+ (init . (lambda () (require 'jabber)))
+ (candidates . (lambda ()
+ (mapcar
+ 'car
+ (anything-c-jabber-online-contacts))))
+ (action . (lambda (x)
+ (jabber-chat-with
+ (jabber-read-account)
+ (symbol-name
+ (cdr (assoc x (anything-c-jabber-online-contacts)))))))))
+
+;;; Type Action helpers
+
+;;;; Files
+
+(defvar anything-c-external-commands-list nil
+ "A list of all external commands the user can execute. If this
+variable is not set by the user, it will be calculated
+automatically.")
+
+(defun anything-c-external-commands-list-1 ()
+ "Returns a list of all external commands the user can execute.
+
+If `anything-c-external-commands-list' is non-nil it will
+return its contents. Else it calculates all external commands
+and sets `anything-c-external-commands-list'.
+
+The code is ripped out of `eshell-complete-commands-list'."
+ (if anything-c-external-commands-list
+ anything-c-external-commands-list
+ (setq anything-c-external-commands-list
+ (let* ((paths (split-string (getenv "PATH") path-separator))
+ (cwd (file-name-as-directory
+ (expand-file-name default-directory)))
+ (path "") (comps-in-path ())
+ (file "") (filepath "") (completions ()))
+ ;; Go thru each path in the search path, finding completions.
+ (while paths
+ (setq path (file-name-as-directory
+ (expand-file-name (or (car paths) ".")))
+ comps-in-path
+ (and (file-accessible-directory-p path)
+ (file-name-all-completions "" path)))
+ ;; Go thru each completion found, to see whether it should be
+ ;; used, e.g. see if it's executable.
+ (while comps-in-path
+ (setq file (car comps-in-path)
+ filepath (concat path file))
+ (if (and (not (member file completions))
+ (or (string-equal path cwd)
+ (not (file-directory-p filepath)))
+ (file-executable-p filepath))
+ (setq completions (cons file completions)))
+ (setq comps-in-path (cdr comps-in-path)))
+ (setq paths (cdr paths)))
+ completions))))
+
+(defun anything-c-file-buffers (filename)
+ "Returns a list of those buffer names which correspond to the
+file given by FILENAME."
+ (let (name ret)
+ (dolist (buf (buffer-list) ret)
+ (let ((bfn (buffer-file-name buf)))
+ (when (and bfn
+ (string= filename bfn))
+ (push (buffer-name buf) ret)))
+ ret)))
+
+(defun anything-c-delete-file (file)
+ "Delete the given file after querying the user. Ask to kill
+buffers associated with that file, too."
+ (if (y-or-n-p (format "Really delete file %s? " file))
+ (progn
+ (let ((buffers (anything-c-file-buffers file)))
+ (delete-file file)
+ (dolist (buf buffers)
+ (when (y-or-n-p (format "Kill buffer %s, too? " buf))
+ (kill-buffer buf)))))
+ (message "Nothing deleted.")))
+
+(defun anything-c-open-file-externally (file)
+ "Open FILE with an external tool. Query the user which tool to
+use."
+ (start-process "anything-c-open-file-externally"
+ nil
+ (completing-read "Program: "
+ (anything-c-external-commands-list-1))
+ file))
+
+(defun w32-shell-execute-open-file (file)
+ (interactive "fOpen file:")
+ (w32-shell-execute "open" (replace-regexp-in-string ;for UNC paths
+ "/" "\\"
+ (replace-regexp-in-string ; strip cygdrive paths
+ "/cygdrive/\\(.\\)" "\\1:" file nil nil) nil t)))
+(defun anything-c-open-file-with-default-tool (file)
+ "Open FILE with the default tool on this platform."
+ (if (eq system-type 'windows-nt)
+ (w32-shell-execute-open-file file)
+ (start-process "anything-c-open-file-with-default-tool"
+ nil
+ (cond ((eq system-type 'gnu/linux)
+ "xdg-open")
+ ((or (eq system-type 'darwin) ;; Mac OS X
+ (eq system-type 'macos)) ;; Mac OS 9
+ "open"))
+ file)))
+
+(defun anything-c-open-dired (file)
+ "Opens a dired buffer in FILE's directory. If FILE is a
+directory, open this directory."
+ (if (file-directory-p file)
+ (dired file)
+ (dired (file-name-directory file))
+ (dired-goto-file file)))
+
+;;; Action Transformers
+
+;;;; Files
+
+(defun anything-c-transform-file-load-el (actions candidate)
+ "Add action to load the file CANDIDATE if it is an emacs lisp
+file. Else return ACTIONS unmodified."
+ (if (or (string= (file-name-extension candidate) "el")
+ (string= (file-name-extension candidate) "elc"))
+ (append actions '(("Load Emacs Lisp File" . load-file)))
+ actions))
+
+(defun anything-c-transform-file-browse-url (actions candidate)
+ "Add an action to browse the file CANDIDATE if it in a html
+file. Else return ACTIONS unmodified."
+ (if (or (string= (file-name-extension candidate) "htm")
+ (string= (file-name-extension candidate) "html"))
+ (append actions '(("Browse with Browser" . browse-url)))
+ actions))
+
+;;;; Function
+
+(defun anything-c-transform-function-call-interactively (actions candidate)
+ "Add an action to call the function CANDIDATE interactively if
+it is a command. Else return ACTIONS unmodified."
+ (if (commandp (intern candidate))
+ (append actions '(("Call Interactively"
+ .
+ (lambda (c)
+ (call-interactively (intern c))))))
+ actions))
+
+;;;; S-Expressions
+
+(defun anything-c-transform-sexp-eval-command-sexp (actions candidate)
+ "If CANDIDATE's `car' is a command, then add an action to
+evaluate it and put it onto the `command-history'."
+ (if (commandp (car (read candidate)))
+ ;; Make it first entry
+ (cons '("Eval and put onto command-history" .
+ (lambda (sexp)
+ (let ((sym (read sexp)))
+ (eval sym)
+ (setq command-history
+ (cons sym command-history)))))
+ actions)
+ actions))
+
+;;; Candidate Transformers
+
+;;;; Files
+
+(defvar anything-c-boring-file-regexp
+ (rx (or
+ ;; Boring directories
+ (and "/" (or ".svn" "CVS" "_darcs" ".git" ".hg") (or "/" eol))
+ ;; Boring files
+ (and (or ".class" ".la" ".o" "~") eol)))
+ "File candidates matching this regular expression will be
+filtered from the list of candidates if the
+`anything-c-skip-boring-files' candidate transformer is used, or
+they will be displayed with face `file-name-shadow' if
+`anything-c-shadow-boring-files' is used.")
+
+(defun anything-c-shadow-boring-files (files)
+ "Files matching `anything-c-boring-file-regexp' will be
+displayed with the `file-name-shadow' face if available."
+ (mapcar (lambda (file)
+ ;; Add shadow face property to boring files.
+ (let ((face (if (facep 'file-name-shadow)
+ 'file-name-shadow
+ ;; fall back to default on XEmacs
+ 'default)))
+ (if (string-match anything-c-boring-file-regexp file)
+ (setq file (propertize file 'face face))))
+ file)
+ files))
+
+(defun anything-c-skip-boring-files (files)
+ "Files matching `anything-c-boring-file-regexp' will be
+skipped."
+ (let (filtered-files)
+ (loop for file in files
+ do (when (not (string-match anything-c-boring-file-regexp file))
+ (push file filtered-files))
+ finally (return (nreverse filtered-files)))))
+
+(defun anything-c-w32-pathname-transformer (args)
+ "Change undesirable features of windows pathnames to ones more acceptable to
+other candidate transformers."
+ (if (eq system-type 'windows-nt)
+ (mapcar (lambda (x)
+ (replace-regexp-in-string "/cygdrive/\\(.\\)" "\\1:" x))
+ (mapcar (lambda (y)
+ (replace-regexp-in-string "\\\\" "/" y)) args))
+ args))
+
+
+(defun anything-c-shorten-home-path (files)
+ "Replaces /home/user with ~."
+ (mapcar (lambda (file)
+ (let ((home (replace-regexp-in-string "\\\\" "/" ; stupid Windows...
+ (getenv "HOME"))))
+ (if (string-match home file)
+ (cons (replace-match "~" nil nil file) file)
+ file)))
+ files))
+
+;;;; Functions
+
+(defun anything-c-mark-interactive-functions (functions)
+ "Mark interactive functions (commands) with (i) after the function name."
+ (let (list)
+ (loop for function in functions
+ do (push (cons (concat function
+ (when (commandp (intern function)) " (i)"))
+ function)
+ list)
+ finally (return (nreverse list)))))
+
+;;; Filtered Candidate Transformers
+
+;;;; Adaptive Sorting of Candidates
+
+;; User config
+
+(defvar anything-c-adaptive-history-file "~/.emacs.d/anything-c-adaptive-history"
+ "Path of file where history information is stored.")
+
+(defvar anything-c-adaptive-history-length 50
+ "Maximum number of candidates stored for a source.")
+
+;;----------------------------------------------------------------------
+
+(defvar anything-c-adaptive-done nil
+ "nil if history information is not yet stored for the current
+selection.")
+
+(defvar anything-c-adaptive-history nil
+ "Contains the stored history information.
+Format: ((SOURCE-NAME (SELECTED-CANDIDATE (PATTERN . NUMBER-OF-USE) ...) ...) ...)")
+
+(defadvice anything-initialize (before anything-c-adaptive-initialize activate)
+ "Advise `anything-initialize' to reset `anything-c-adaptive-done'
+when anything is started."
+ (setq anything-c-adaptive-done nil))
+
+(defadvice anything-exit-minibuffer (before anything-c-adaptive-exit-minibuffer activate)
+ "Advise `anything-exit-minibuffer' to store history information
+when a candidate is selected with RET."
+ (anything-c-adaptive-store-selection))
+
+(defadvice anything-select-action (before anything-c-adaptive-select-action activate)
+ "Advise `anything-select-action' to store history information
+when the user goes to the action list with TAB."
+ (anything-c-adaptive-store-selection))
+
+(defun anything-c-adaptive-store-selection ()
+ "Store history information for the selected candidate."
+ (unless anything-c-adaptive-done
+ (setq anything-c-adaptive-done t)
+ (let* ((source (anything-get-current-source))
+ (source-name (or (assoc-default 'type source)
+ (assoc-default 'name source)))
+ (source-info (or (assoc source-name anything-c-adaptive-history)
+ (progn
+ (push (list source-name) anything-c-adaptive-history)
+ (car anything-c-adaptive-history))))
+ (selection (anything-get-selection))
+ (selection-info (progn
+ (setcdr source-info
+ (cons
+ (let ((found (assoc selection (cdr source-info))))
+ (if (not found)
+ ;; new entry
+ (list selection)
+
+ ;; move entry to the beginning of the
+ ;; list, so that it doesn't get
+ ;; trimmed when the history is
+ ;; truncated
+ (setcdr source-info
+ (delete found (cdr source-info)))
+ found))
+ (cdr source-info)))
+ (cadr source-info)))
+ (pattern-info (progn
+ (setcdr selection-info
+ (cons
+ (let ((found (assoc anything-pattern (cdr selection-info))))
+ (if (not found)
+ ;; new entry
+ (cons anything-pattern 0)
+
+ ;; move entry to the beginning of the
+ ;; list, so if two patterns used the
+ ;; same number of times then the one
+ ;; used last appears first in the list
+ (setcdr selection-info
+ (delete found (cdr selection-info)))
+ found))
+ (cdr selection-info)))
+ (cadr selection-info))))
+
+ ;; increase usage count
+ (setcdr pattern-info (1+ (cdr pattern-info)))
+
+ ;; truncate history if needed
+ (if (> (length (cdr selection-info)) anything-c-adaptive-history-length)
+ (setcdr selection-info
+ (subseq (cdr selection-info) 0 anything-c-adaptive-history-length))))))
+
+(if (file-readable-p anything-c-adaptive-history-file)
+ (load-file anything-c-adaptive-history-file))
+(add-hook 'kill-emacs-hook 'anything-c-adaptive-save-history)
+
+(defun anything-c-adaptive-save-history ()
+ "Save history information to file given by
+`anything-c-adaptive-history-file'."
+ (interactive)
+ (with-temp-buffer
+ (insert
+ ";; -*- mode: emacs-lisp -*-\n"
+ ";; History entries used for anything adaptive display.\n")
+ (prin1 `(setq anything-c-adaptive-history ',anything-c-adaptive-history)
+ (current-buffer))
+ (insert ?\n)
+ (write-region (point-min) (point-max) anything-c-adaptive-history-file nil
+ (unless (interactive-p) 'quiet))))
+
+(defun anything-c-adaptive-sort (candidates source)
+ "Sort the CANDIDATES for SOURCE by usage frequency.
+This is a filtered candidate transformer you can use for the
+attribute `filtered-candidate-transformer' of a source in
+`anything-sources' or a type in `anything-type-attributes'."
+ (let* ((source-name (or (assoc-default 'type source)
+ (assoc-default 'name source)))
+ (source-info (assoc source-name anything-c-adaptive-history)))
+ (if (not source-info)
+ ;; if there is no information stored for this source then do nothing
+ candidates
+ ;; else...
+ (let ((usage
+ ;; ... assemble a list containing the (CANIDATE . USAGE-COUNT)
+ ;; pairs
+ (mapcar (lambda (candidate-info)
+ (let ((count 0))
+ (dolist (pattern-info (cdr candidate-info))
+ (if (not (equal (car pattern-info)
+ anything-pattern))
+ (incf count (cdr pattern-info))
+
+ ;; if current pattern is equal to the previously
+ ;; used one then this candidate has priority
+ ;; (that's why its count is boosted by 10000) and
+ ;; it only has to compete with other candidates
+ ;; which were also selected with the same pattern
+ (setq count (+ 10000 (cdr pattern-info)))
+ (return)))
+ (cons (car candidate-info) count)))
+ (cdr source-info)))
+ sorted)
+
+ ;; sort the list in descending order, so candidates with highest
+ ;; priorty come first
+ (setq usage (sort usage (lambda (first second)
+ (> (cdr first) (cdr second)))))
+
+ ;; put those candidates first which have the highest usage count
+ (dolist (info usage)
+ (when (member* (car info) candidates
+ :test 'anything-c-adaptive-compare)
+ (push (car info) sorted)
+ (setq candidates (remove* (car info) candidates
+ :test 'anything-c-adaptive-compare))))
+
+ ;; and append the rest
+ (append (reverse sorted) candidates nil)))))
+
+(defun anything-c-adaptive-compare (x y)
+ "Compare candidates X and Y taking into account that the
+candidate can be in (DISPLAY . REAL) format."
+ (equal (if (listp x)
+ (cdr x)
+ x)
+ (if (listp y)
+ (cdr y)
+ y)))
+
+;;; Default Configuration
+
+;;;; Helper Functions
+
+(defun anything-c-compose (arg-lst func-lst)
+ "Call each function in FUNC-LST with the arguments specified in
+ARG-LST. The result of each function will be the new `car' of
+ARG-LST.
+
+This function allows easy sequencing of transformer functions."
+ (dolist (func func-lst)
+ (setcar arg-lst (apply func arg-lst)))
+ (car arg-lst))
+
+;;;; Sources
+
+(setq anything-sources
+ (list anything-c-source-buffers
+ anything-c-source-buffer-not-found
+ anything-c-source-file-name-history
+ anything-c-source-info-pages
+ anything-c-source-man-pages
+ anything-c-source-locate
+ anything-c-source-emacs-commands
+ anything-c-source-google-suggest))
+
+;;;; Type Attributes
+
+(setq anything-type-attributes
+ `((buffer
+ (action
+ ,@(if pop-up-frames
+ '(("Switch to buffer other window" . switch-to-buffer-other-window)
+ ("Switch to buffer" . switch-to-buffer))
+ '(("Switch to buffer" . switch-to-buffer)
+ ("Switch to buffer other window" . switch-to-buffer-other-window)
+ ("Switch to buffer other frame" . switch-to-buffer-other-frame)))
+ ("Display buffer" . display-buffer)
+ ("Kill buffer" . kill-buffer)))
+ (file
+ (action
+ ,@(if pop-up-frames
+ '(("Find file other window" . find-file-other-window)
+ ("Find file" . find-file))
+ '(("Find file" . find-file)
+ ("Find file other window" . find-file-other-window)
+ ("Find file other frame" . find-file-other-frame)))
+ ("Open dired in file's directory" . anything-c-open-dired)
+ ("Delete file" . anything-c-delete-file)
+ ("Open file externally" . anything-c-open-file-externally)
+ ("Open file with default tool" . anything-c-open-file-with-default-tool))
+ (action-transformer . (lambda (actions candidate)
+ (anything-c-compose
+ (list actions candidate)
+ '(anything-c-transform-file-load-el
+ anything-c-transform-file-browse-url))))
+ (candidate-transformer . (lambda (candidates)
+ (anything-c-compose
+ (list candidates)
+ '(anything-c-w32-pathname-transformer
+ anything-c-skip-boring-files
+ anything-c-shorten-home-path)))))
+ (command (action ("Call interactively" . (lambda (command-name)
+ (call-interactively (intern command-name))))
+ ("Describe command" . (lambda (command-name)
+ (describe-function (intern command-name))))
+ ("Add command to kill ring" . kill-new)
+ ("Go to command's definition" . (lambda (command-name)
+ (find-function
+ (intern command-name)))))
+ ;; Sort commands according to their usage count.
+ (filtered-candidate-transformer . anything-c-adaptive-sort))
+ (function (action ("Describe function" . (lambda (function-name)
+ (describe-function (intern function-name))))
+ ("Add function to kill ring" . kill-new)
+ ("Go to function's definition" . (lambda (function-name)
+ (find-function
+ (intern function-name)))))
+ (action-transformer . (lambda (actions candidate)
+ (anything-c-compose
+ (list actions candidate)
+ '(anything-c-transform-function-call-interactively))))
+ (candidate-transformer . (lambda (candidates)
+ (anything-c-compose
+ (list candidates)
+ '(anything-c-mark-interactive-functions)))))
+ (sexp (action ("Eval s-expression" . (lambda (c)
+ (eval (read c))))
+ ("Add s-expression to kill ring" . kill-new))
+ (action-transformer . (lambda (actions candidate)
+ (anything-c-compose
+ (list actions candidate)
+ '(anything-c-transform-sexp-eval-command-sexp)))))
+ (bookmark (action ("Jump to bookmark" . bookmark-jump)
+ ("Delete bookmark" . bookmark-delete)))))
+
+;;; Provide anything-config
+
+(provide 'anything-config)
+
+;; Local Variables:
+;; mode: outline-minor
+;; End:
+
+;;; anything-config.el ends here
--- /dev/null
+;;; anything-config.el --- predefined configurations for anything
+
+;; Copyright (C) 2007 Tassilo Horn
+
+;; Maintainer: Tassilo Horn <tassilo@member.fsf.org>
+
+;; Contributors:
+;; Tamas Patrovics
+;; Tassilo Horn <tassilo@member.fsf.org>
+;; Vagn Johansen <gonz808@hotmail.com>
+;; Mathias Dahl <mathias.dahl@gmail.com>
+;; Bill Clementson <billclem@gmail.com>
+;; Stefan Kamphausen (see http://www.skamphausen.de for more informations)
+;; Drew Adams <drew.adams@oracle.com>
+;; Jason McBrayer <jmcbray@carcosa.net>
+
+;; This file is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation; either version 2, or (at your option)
+;; any later version.
+
+;; This file is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs; see the file COPYING. If not, write to the
+;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
+
+;;; Commentary:
+
+;;
+;; This package provides predefined configurations for anything.el. To enable
+;; it, put this into your `user-init-file'.
+;;
+;; (require 'anything-config) ; loads anything.el too
+;;
+;; To configure anything you should tweak the variables `anything-sources' and
+;; `anything-type-attributes'. See the default configuration at the bottom of
+;; this file. Copy and modify it to your needs.
+;;
+;; (setq anything-sources ...)
+;; (setq anything-type-attributes ...)
+;;
+
+;;; Bugs and TODOs:
+
+;;
+;; - TODO: anything-c-adaptive stores infos for sources/types that don't have
+;; set it as `filtered-candidate-transformer'.
+;;
+;; - TODO: The Imenu source is broken for very recent emacsen. It seems to
+;; work with 22.1, though.
+;;
+
+;;; Startup
+
+;;; (require 'anything)
+
+;;; Version
+
+(defvar anything-c-version "<2008-08-13 Wed 14:49>"
+ "The version of anything-config.el, or better the date of the
+last change.")
+
+;;; Keymaps
+
+(defvar anything-c-use-standard-keys t
+ "If non-nil the keybindings of anything will be the standard
+bindings used in most parts of emacs, e.g. M-p/M-n for minibuffer
+history, C-s for isearch, etc.
+
+If it's nil anything uses some bindings that don't conflict with
+`iswitchb', e.g. C-p/C-n for the minibuffer history. If you use
+`iswitchb' you probably should say nil here.")
+
+(when anything-c-use-standard-keys
+ (setq anything-map
+ (let ((map (copy-keymap minibuffer-local-map)))
+ (define-key map (kbd "<down>") 'anything-next-line)
+ (define-key map (kbd "<up>") 'anything-previous-line)
+ (define-key map (kbd "C-n") 'anything-next-line)
+ (define-key map (kbd "C-p") 'anything-previous-line)
+ (define-key map (kbd "<prior>") 'anything-previous-page)
+ (define-key map (kbd "<next>") 'anything-next-page)
+ (define-key map (kbd "M-v") 'anything-previous-page)
+ (define-key map (kbd "C-v") 'anything-next-page)
+ (define-key map (kbd "<right>") 'anything-next-source)
+ (define-key map (kbd "<left>") 'anything-previous-source)
+ (define-key map (kbd "<RET>") 'anything-exit-minibuffer)
+ (define-key map (kbd "C-1") 'anything-select-with-digit-shortcut)
+ (define-key map (kbd "C-2") 'anything-select-with-digit-shortcut)
+ (define-key map (kbd "C-3") 'anything-select-with-digit-shortcut)
+ (define-key map (kbd "C-4") 'anything-select-with-digit-shortcut)
+ (define-key map (kbd "C-5") 'anything-select-with-digit-shortcut)
+ (define-key map (kbd "C-6") 'anything-select-with-digit-shortcut)
+ (define-key map (kbd "C-7") 'anything-select-with-digit-shortcut)
+ (define-key map (kbd "C-8") 'anything-select-with-digit-shortcut)
+ (define-key map (kbd "C-9") 'anything-select-with-digit-shortcut)
+ (define-key map (kbd "<tab>") 'anything-select-action)
+ (defalias 'anything-next-history-element 'next-history-element)
+ (defalias 'anything-previous-history-element 'previous-history-element)
+ (define-key map (kbd "M-p") 'anything-previous-history-element)
+ (define-key map (kbd "M-n") 'anything-next-history-element)
+ (define-key map (kbd "C-s") 'anything-isearch)
+ (define-key map (kbd "C-r") 'undefined)
+ map))
+
+ (setq anything-isearch-map
+ (let ((map (copy-keymap (current-global-map))))
+ (define-key map (kbd "<return>") 'anything-isearch-default-action)
+ (define-key map (kbd "<tab>") 'anything-isearch-select-action)
+ (define-key map (kbd "C-g") 'anything-isearch-cancel)
+ (define-key map (kbd "C-s") 'anything-isearch-again)
+ (define-key map (kbd "C-r") 'undefined)
+ (define-key map (kbd "<backspace>") 'anything-isearch-delete)
+ ;; add printing chars
+ (let ((i ?\s))
+ (while (< i 256)
+ (define-key map (vector i) 'anything-isearch-printing-char)
+ (setq i (1+ i))))
+ map)))
+
+;;; Sources
+
+;;;; Match functions
+
+(defun anything-c-match-on-file-name (candidate)
+ "Return non-nil if `anything-pattern' matches the
+filename (without directory part) of CANDIDATE."
+ (string-match anything-pattern (file-name-nondirectory candidate)))
+
+(defun anything-c-match-on-directory-name (candidate)
+ "Return non-nil if `anything-pattern' matches the directory
+part of CANDIDATE (a file)."
+ (let ((dir (file-name-directory candidate)))
+ (when dir
+ (string-match anything-pattern dir))))
+
+(defun anything-c-string-match (candidate)
+ "Return non-nil if `anything-pattern' matches CANDIDATE.
+The match is done with `string-match'."
+ (string-match anything-pattern candidate))
+
+;;;; Buffers
+
+(defun anything-c-buffer-list ()
+ "Return the list of names of buffers with the `anything-buffer'
+and hidden buffers filtered out. The first buffer in the list
+will be the last recently used buffer that is not the current
+buffer."
+ (let ((buffers (remove-if (lambda (name)
+ (or (equal name anything-buffer)
+ (eq ?\ (aref name 0))))
+ (mapcar 'buffer-name (buffer-list)))))
+ (append (cdr buffers) (list (car buffers)))))
+
+(defvar anything-c-source-buffers
+ '((name . "Buffers")
+ (candidates . anything-c-buffer-list)
+ (volatile)
+ (type . buffer)))
+
+(defun anything-c-define-dummy-source (name func &rest other-attrib)
+ `((name . ,name)
+ (candidates "dummy")
+ ,@other-attrib
+ (filtered-candidate-transformer
+ . (lambda (candidates source)
+ (funcall ',func)))
+ (requires-pattern . 1)
+ (volatile)
+ (category create)))
+
+(defun anything-c-dummy-candidate ()
+ ;; `source' is defined in filtered-candidate-transformer
+ (list (cons (concat (assoc-default 'name source)
+ " '" anything-input "'")
+ anything-input)))
+
+(defvar anything-c-source-buffer-not-found
+ (anything-c-define-dummy-source
+ "Create buffer"
+ (lambda () (unless (get-buffer anything-input)
+ (anything-c-dummy-candidate)))
+ '(type . buffer)))
+
+;;;; File name history
+
+(defvar anything-c-source-file-name-history
+ '((name . "File Name History")
+ (candidates . file-name-history)
+ (match . (anything-c-match-on-file-name
+ anything-c-match-on-directory-name))
+ (type . file)))
+
+;;;; Recentf files
+
+(defvar anything-c-source-recentf
+ '((name . "Recentf")
+ (candidates . recentf-list)
+ (match . (anything-c-match-on-file-name
+ anything-c-match-on-directory-name))
+ (type . file))
+ "See (info \"(emacs)File Conveniences\").")
+
+;;;; Files in current dir
+
+(defvar anything-c-source-files-in-current-dir
+ '((name . "Files from Current Directory")
+ (init . (lambda ()
+ (setq anything-c-default-directory
+ default-directory)))
+ (candidates . (lambda ()
+ (directory-files
+ anything-c-default-directory)))
+ (volatile)
+ (type . file)))
+
+;;;; Man Pages
+
+(defvar anything-c-man-pages nil
+ "All man pages on system.
+Will be calculated the first time you invoke anything with this
+source.")
+
+(defvar anything-c-source-man-pages
+ `((name . "Manual Pages")
+ (candidates . (lambda ()
+ (if anything-c-man-pages
+ anything-c-man-pages
+ ;; XEmacs doesn't have a woman :)
+ (setq anything-c-man-pages
+ (condition-case nil
+ (progn
+ (require 'woman)
+ (woman-file-name "")
+ (sort (mapcar 'car
+ woman-topic-all-completions)
+ 'string-lessp))
+ (error nil))))))
+ (action . (("Show with Woman" . woman)))
+ (requires-pattern . 2)))
+
+;;;; Info pages
+
+(defvar anything-c-info-pages nil
+ "All info pages on system.
+Will be calculated the first time you invoke anything with this
+source.")
+
+(defvar anything-c-source-info-pages
+ `((name . "Info Pages")
+ (candidates
+ . (lambda ()
+ (if anything-c-info-pages
+ anything-c-info-pages
+ (setq anything-c-info-pages
+ (save-window-excursion
+ (save-excursion
+ (require 'info)
+ (Info-find-node "dir" "top")
+ (goto-char (point-min))
+ (let ((info-topic-regexp "\\* +\\([^:]+: ([^)]+)[^.]*\\)\\.")
+ topics)
+ (while (re-search-forward info-topic-regexp nil t)
+ (add-to-list 'topics (match-string-no-properties 1)))
+ (goto-char (point-min))
+ (Info-exit)
+ topics)))))))
+ (action . (("Show with Info" .(lambda (node-str)
+ (info (replace-regexp-in-string "^[^:]+: "
+ ""
+ node-str))))))
+ (requires-pattern . 2)))
+
+;;;; Complex command history
+
+(defvar anything-c-source-complex-command-history
+ '((name . "Complex Command History")
+ (candidates . (lambda ()
+ (mapcar 'prin1-to-string
+ command-history)))
+ (volatile)
+ (type . sexp)))
+
+;;;; Emacs commands
+
+(defvar anything-c-source-emacs-commands
+ '((name . "Emacs Commands")
+ (candidates . (lambda ()
+ (let (commands)
+ (mapatoms (lambda (a)
+ (if (commandp a)
+ (push (symbol-name a)
+ commands))))
+ (sort commands 'string-lessp))))
+ (volatile)
+ (type . command)
+ (requires-pattern . 2))
+ "Source for completing and invoking Emacs commands. A command
+is a function with interactive spec that can be invoked with
+`M-x'.
+
+To get non-interactive functions listed, use
+`anything-c-source-emacs-functions'.")
+
+;;;; Emacs functions
+
+;;;;; Normal
+
+(defvar anything-c-source-emacs-functions
+ '((name . "Emacs Functions")
+ (candidates . (lambda ()
+ (let (commands)
+ (mapatoms (lambda (a)
+ (if (functionp a)
+ (push (symbol-name a)
+ commands))))
+ (sort commands 'string-lessp))))
+ (volatile)
+ (type . function)
+ (requires-pattern . 2))
+ "Source for completing Emacs functions.")
+
+;;;;; With abbrev expansion similar to my exec-abbrev-cmd.el
+
+;; See http://www.tsdh.de/cgi-bin/wiki.pl/exec-abbrev-cmd.el
+
+(defvar anything-c-function-abbrev-regexp nil
+ "Regexp built from the current `anything-pattern' interpreting
+it as abbreviation. Only for internal use.")
+
+(defun anything-c-match-function-by-abbrev (candidate)
+ "Return non-nil if `anything-pattern' is an abbreviation of the
+function CANDIDATE.
+
+Abbreviations are made by taking the first character from each
+word in the function's name, e.g. \"bb\" is an abbrev for
+`bury-buffer', \"stb\" is an abbrev for `switch-to-buffer'."
+ (string-match anything-c-function-abbrev-regexp candidate))
+
+(defvar anything-c-source-emacs-functions-with-abbrevs
+ (append anything-c-source-emacs-functions
+ '((match . (anything-c-match-function-by-abbrev
+ anything-c-string-match)))
+ '((init . (lambda ()
+ (defadvice anything-update
+ (before anything-c-update-function-abbrev-regexp activate)
+ (let ((char-list (append anything-pattern nil))
+ (str "^"))
+ (dolist (c char-list)
+ (setq str (concat str (list c) "[^-]*-")))
+ (setq str (concat (substring str 0 (1- (length str))) "$"))
+ (setq anything-c-function-abbrev-regexp str))))))))
+
+;;;; Bookmarks
+
+(defvar anything-c-source-bookmarks
+ '((name . "Bookmarks")
+ (init . (lambda ()
+ (require 'bookmark)))
+ (candidates . bookmark-all-names)
+ (type . bookmark))
+ "See (info \"(emacs)Bookmarks\").")
+
+;;;; Picklist
+
+(defvar anything-c-source-picklist
+ '((name . "Picklist")
+ (candidates . (lambda ()
+ (mapcar 'car picklist-list)))
+ (volatile)
+ (type . file)))
+
+;;;; Imenu
+
+(defvar anything-c-source-imenu
+ '((name . "Imenu")
+ (init . (lambda ()
+ (setq anything-c-imenu-current-buffer
+ (current-buffer))))
+ (candidates . (lambda ()
+ (condition-case nil
+ (with-current-buffer anything-c-imenu-current-buffer
+ (mapcar (lambda (x)
+ (cons (car x) x))
+ ;; leave only top level completions for
+ ;; simplicity (could be more sophisticated)
+ (remove-if-not (lambda (x)
+ (markerp (cdr x)))
+ (imenu--make-index-alist))))
+ (error nil))))
+ (volatile)
+ (action . imenu)))
+
+;;;; File Cache
+
+(defvar anything-c-source-file-cache-initialized nil)
+
+(defvar anything-c-file-cache-files nil)
+
+(defvar anything-c-source-file-cache
+ '((name . "File Cache")
+ (init . (lambda ()
+ (unless anything-c-source-file-cache-initialized
+ (setq anything-c-file-cache-files
+ (loop for item in file-cache-alist append
+ (destructuring-bind (base &rest dirs) item
+ (loop for dir in dirs collect
+ (concat dir base)))))
+ (defadvice file-cache-add-file (after file-cache-list activate)
+ (add-to-list 'anything-c-file-cache-files (expand-file-name file)))
+ (setq anything-c-source-file-cache-initialized t))))
+ (candidates . anything-c-file-cache-files)
+ (match . (anything-c-match-on-file-name
+ anything-c-match-on-directory-name))
+ (type . file)))
+
+;;;; Locate
+
+(defvar anything-c-locate-options (if (eq system-type 'darwin)
+ '("locate")
+ '("locate" "-i" "-r"))
+ "A list where the `car' is the name of the locat program
+followed by options. The search pattern will be appended, so the
+\"-r\" option should be the last option.")
+
+(defvar anything-c-source-locate
+ '((name . "Locate")
+ (candidates . (lambda ()
+ (apply 'start-process "locate-process" nil
+ (append anything-c-locate-options
+ (list anything-pattern)))))
+ (type . file)
+ (requires-pattern . 3)
+ (delayed))
+ "Source for retrieving files matching the current input pattern
+with locate.")
+
+;;;; Tracker desktop search
+
+(defvar anything-c-source-tracker-search
+ '((name . "Tracker Search")
+ (candidates . (lambda ()
+ (start-process "tracker-search-process" nil
+ "tracker-search"
+ anything-pattern)))
+ (type . file)
+ (requires-pattern . 3)
+ (delayed))
+ "Source for retrieving files matching the current input pattern
+with the tracker desktop search.")
+
+;;;; Spotlight (MacOS X desktop search)
+
+(defvar anything-c-source-mac-spotlight
+ '((name . "mdfind")
+ (candidates . (lambda ()
+ (start-process "mdfind-process" nil
+ "mdfind" anything-pattern)))
+ (type . file)
+ (requires-pattern . 3)
+ (delayed))
+ "Source for retrieving files via Spotlight's command line
+utility mdfind.")
+
+;;;; BBDB
+
+(defun anything-c-bbdb-candidates ()
+ "Return a list of all names in the bbdb database. The format
+is \"Firstname Lastname\"."
+ (mapcar (lambda (bbdb-record)
+ (concat (aref bbdb-record 0) " " (aref bbdb-record 1)))
+ (bbdb-records)))
+
+(defun anything-c-bbdb-create-contact (actions candidate)
+ "Action transformer that returns only an entry to add the
+current `anything-pattern' as new contact. All other actions are
+removed."
+ (if (string= candidate "*Add to contacts*")
+ '(("Add to contacts"
+ . (lambda (actions)
+ (bbdb-create-internal
+ (read-from-minibuffer "Name: " anything-c-bbdb-name)
+ (read-from-minibuffer "Company: ")
+ (read-from-minibuffer "Email: ")
+ nil
+ nil
+ (read-from-minibuffer "Note: ")))))
+ actions))
+
+(defvar anything-c-bbdb-name nil
+ "Only for internal use.")
+
+(defvar anything-c-source-bbdb
+ '((name . "BBDB")
+ (candidates . anything-c-bbdb-candidates)
+ (volatile)
+ (action ("View person's data" . (lambda (candidate)
+ (bbdb candidate nil)
+ (set-buffer "*BBDB*")
+ (bbdb-redisplay-one-record (bbdb-current-record))))
+ ("Send a mail" . (lambda (candidate)
+ (let ((rec (progn
+ (bbdb candidate nil)
+ (set-buffer "*BBDB*")
+ (bbdb-current-record))))
+ (bbdb-send-mail rec)))))
+ (filtered-candidate-transformer . (lambda (candidates source)
+ (setq anything-c-bbdb-name anything-pattern)
+ (if (not candidates)
+ (list "*Add to contacts*")
+ candidates)))
+ (action-transformer . (lambda (actions candidate)
+ (anything-c-bbdb-create-contact actions candidate)))))
+
+;;;; Evaluation Result
+
+(defvar anything-c-source-evaluation-result
+ '((name . "Evaluation Result")
+ (requires-pattern)
+ (match (lambda (candidate) t))
+ (candidates "dummy")
+ (filtered-candidate-transformer
+ . (lambda (candidates source)
+ (list
+ (condition-case nil
+ (prin1-to-string
+ (eval (read anything-pattern)))
+ (error "error")))))
+ (volatile)
+ (action ("Do Nothing" . ignore))))
+
+;;;; Calculation Result
+
+(defvar anything-c-source-calculation-result
+ '((name . "Calculation Result")
+ (requires-pattern)
+ (match (lambda (candidate) t))
+ (candidates "dummy")
+ (filtered-candidate-transformer
+ . (lambda (candidates source)
+ (list
+ (condition-case nil
+ (calc-eval anything-pattern)
+ (error "error")))))
+ (volatile)
+ (action ("Do Nothing" . ignore))))
+
+;;;; Google Suggestions
+
+(defvar anything-c-source-google-suggest
+ '((name . "Google Suggest")
+ (candidates
+ . (lambda ()
+ (let ((suggestions (anything-c-google-suggest-fetch anything-input)))
+ (if (some (lambda (suggestion)
+ (equal (cdr suggestion) anything-input))
+ suggestions)
+ suggestions
+ ;; if there is no suggestion exactly matching the input then
+ ;; prepend a Search on Google item to the list
+ (append (list (cons (concat "Search for "
+ "'" anything-input "'"
+ " on Google")
+ anything-input))
+ suggestions)))))
+ (action . (("Google Search" .
+ (lambda (candidate)
+ (browse-url (concat anything-c-google-suggest-search-url
+ (url-hexify-string candidate)))))))
+ (volatile)
+ (requires-pattern . 3)
+ (delayed)))
+
+(defvar anything-c-google-suggest-url
+ "http://www.google.com/complete/search?hl=en&js=true&qu="
+ "URL used for looking up suggestions.")
+
+(defvar anything-c-google-suggest-search-url
+ "http://www.google.com/search?ie=utf-8&oe=utf-8&q="
+ "URL used for searching.")
+
+(defun anything-c-google-suggest-fetch (input)
+ "Fetch suggestions for INPUT."
+ (let* ((result (with-current-buffer
+ (url-retrieve-synchronously
+ (concat anything-c-google-suggest-url
+ (url-hexify-string input)))
+ (buffer-substring (point-min) (point-max))))
+ (split (split-string result "new Array("))
+ (suggestions (anything-c-google-suggest-get-items (second split)))
+ (numbers (anything-c-google-suggest-get-items (third split)))
+ (longest (+ (apply 'max 0 (let (lengths)
+ (dotimes (i (length suggestions))
+ (push (+ (length (nth i suggestions))
+ (length (nth i numbers)))
+ lengths))
+ lengths))
+ 10))
+ items)
+ (dotimes (i (length suggestions))
+ (let ((suggestion (nth i suggestions))
+ (number (nth i numbers)))
+ (push (cons (concat suggestion
+ (make-string (- longest
+ (length suggestion)
+ (length number))
+ 32)
+ number)
+ suggestion)
+ items)))
+ items))
+
+(defun anything-c-google-suggest-get-items (str)
+ "Extract items from STR returned by Google Suggest."
+ (let ((start nil)
+ items)
+ (while (string-match "\"\\([^\"]+?\\)\"" str start)
+ (push (match-string 1 str) items)
+ (setq start (1+ (match-end 1))))
+ items))
+
+;;;; Jabber Contacts (jabber.el)
+
+(defun anything-c-jabber-online-contacts ()
+ "List online Jabber contacts."
+ (let (jids)
+ (dolist (item (jabber-concat-rosters) jids)
+ (when (get item 'connected)
+ (push (if (get item 'name)
+ (cons (get item 'name) item)
+ (cons (symbol-name item) item)) jids)))))
+
+(defvar anything-c-source-jabber-contacts
+ '((name . "Jabber Contacts")
+ (init . (lambda () (require 'jabber)))
+ (candidates . (lambda ()
+ (mapcar
+ 'car
+ (anything-c-jabber-online-contacts))))
+ (action . (lambda (x)
+ (jabber-chat-with
+ (jabber-read-account)
+ (symbol-name
+ (cdr (assoc x (anything-c-jabber-online-contacts)))))))))
+
+;;; Type Action helpers
+
+;;;; Files
+
+(defvar anything-c-external-commands-list nil
+ "A list of all external commands the user can execute. If this
+variable is not set by the user, it will be calculated
+automatically.")
+
+(defun anything-c-external-commands-list-1 ()
+ "Returns a list of all external commands the user can execute.
+
+If `anything-c-external-commands-list' is non-nil it will
+return its contents. Else it calculates all external commands
+and sets `anything-c-external-commands-list'.
+
+The code is ripped out of `eshell-complete-commands-list'."
+ (if anything-c-external-commands-list
+ anything-c-external-commands-list
+ (setq anything-c-external-commands-list
+ (let* ((paths (split-string (getenv "PATH") path-separator))
+ (cwd (file-name-as-directory
+ (expand-file-name default-directory)))
+ (path "") (comps-in-path ())
+ (file "") (filepath "") (completions ()))
+ ;; Go thru each path in the search path, finding completions.
+ (while paths
+ (setq path (file-name-as-directory
+ (expand-file-name (or (car paths) ".")))
+ comps-in-path
+ (and (file-accessible-directory-p path)
+ (file-name-all-completions "" path)))
+ ;; Go thru each completion found, to see whether it should be
+ ;; used, e.g. see if it's executable.
+ (while comps-in-path
+ (setq file (car comps-in-path)
+ filepath (concat path file))
+ (if (and (not (member file completions))
+ (or (string-equal path cwd)
+ (not (file-directory-p filepath)))
+ (file-executable-p filepath))
+ (setq completions (cons file completions)))
+ (setq comps-in-path (cdr comps-in-path)))
+ (setq paths (cdr paths)))
+ completions))))
+
+(defun anything-c-file-buffers (filename)
+ "Returns a list of those buffer names which correspond to the
+file given by FILENAME."
+ (let (name ret)
+ (dolist (buf (buffer-list) ret)
+ (let ((bfn (buffer-file-name buf)))
+ (when (and bfn
+ (string= filename bfn))
+ (push (buffer-name buf) ret)))
+ ret)))
+
+(defun anything-c-delete-file (file)
+ "Delete the given file after querying the user. Ask to kill
+buffers associated with that file, too."
+ (if (y-or-n-p (format "Really delete file %s? " file))
+ (progn
+ (let ((buffers (anything-c-file-buffers file)))
+ (delete-file file)
+ (dolist (buf buffers)
+ (when (y-or-n-p (format "Kill buffer %s, too? " buf))
+ (kill-buffer buf)))))
+ (message "Nothing deleted.")))
+
+(defun anything-c-open-file-externally (file)
+ "Open FILE with an external tool. Query the user which tool to
+use."
+ (start-process "anything-c-open-file-externally"
+ nil
+ (completing-read "Program: "
+ (anything-c-external-commands-list-1))
+ file))
+
+(defun w32-shell-execute-open-file (file)
+ (interactive "fOpen file:")
+ (w32-shell-execute "open" (replace-regexp-in-string ;for UNC paths
+ "/" "\\"
+ (replace-regexp-in-string ; strip cygdrive paths
+ "/cygdrive/\\(.\\)" "\\1:" file nil nil) nil t)))
+(defun anything-c-open-file-with-default-tool (file)
+ "Open FILE with the default tool on this platform."
+ (if (eq system-type 'windows-nt)
+ (w32-shell-execute-open-file file)
+ (start-process "anything-c-open-file-with-default-tool"
+ nil
+ (cond ((eq system-type 'gnu/linux)
+ "xdg-open")
+ ((or (eq system-type 'darwin) ;; Mac OS X
+ (eq system-type 'macos)) ;; Mac OS 9
+ "open"))
+ file)))
+
+(defun anything-c-open-dired (file)
+ "Opens a dired buffer in FILE's directory. If FILE is a
+directory, open this directory."
+ (if (file-directory-p file)
+ (dired file)
+ (dired (file-name-directory file))
+ (dired-goto-file file)))
+
+;;; Action Transformers
+
+;;;; Files
+
+(defun anything-c-transform-file-load-el (actions candidate)
+ "Add action to load the file CANDIDATE if it is an emacs lisp
+file. Else return ACTIONS unmodified."
+ (if (or (string= (file-name-extension candidate) "el")
+ (string= (file-name-extension candidate) "elc"))
+ (append actions '(("Load Emacs Lisp File" . load-file)))
+ actions))
+
+(defun anything-c-transform-file-browse-url (actions candidate)
+ "Add an action to browse the file CANDIDATE if it in a html
+file. Else return ACTIONS unmodified."
+ (if (or (string= (file-name-extension candidate) "htm")
+ (string= (file-name-extension candidate) "html"))
+ (append actions '(("Browse with Browser" . browse-url)))
+ actions))
+
+;;;; Function
+
+(defun anything-c-transform-function-call-interactively (actions candidate)
+ "Add an action to call the function CANDIDATE interactively if
+it is a command. Else return ACTIONS unmodified."
+ (if (commandp (intern candidate))
+ (append actions '(("Call Interactively"
+ .
+ (lambda (c)
+ (call-interactively (intern c))))))
+ actions))
+
+;;;; S-Expressions
+
+(defun anything-c-transform-sexp-eval-command-sexp (actions candidate)
+ "If CANDIDATE's `car' is a command, then add an action to
+evaluate it and put it onto the `command-history'."
+ (if (commandp (car (read candidate)))
+ ;; Make it first entry
+ (cons '("Eval and put onto command-history" .
+ (lambda (sexp)
+ (let ((sym (read sexp)))
+ (eval sym)
+ (setq command-history
+ (cons sym command-history)))))
+ actions)
+ actions))
+
+;;; Candidate Transformers
+
+;;;; Files
+
+(defvar anything-c-boring-file-regexp
+ (rx (or
+ ;; Boring directories
+ (and "/" (or ".svn" "CVS" "_darcs" ".git" ".hg") (or "/" eol))
+ ;; Boring files
+ (and (or ".class" ".la" ".o" "~") eol)))
+ "File candidates matching this regular expression will be
+filtered from the list of candidates if the
+`anything-c-skip-boring-files' candidate transformer is used, or
+they will be displayed with face `file-name-shadow' if
+`anything-c-shadow-boring-files' is used.")
+
+(defun anything-c-shadow-boring-files (files)
+ "Files matching `anything-c-boring-file-regexp' will be
+displayed with the `file-name-shadow' face if available."
+ (mapcar (lambda (file)
+ ;; Add shadow face property to boring files.
+ (let ((face (if (facep 'file-name-shadow)
+ 'file-name-shadow
+ ;; fall back to default on XEmacs
+ 'default)))
+ (if (string-match anything-c-boring-file-regexp file)
+ (setq file (propertize file 'face face))))
+ file)
+ files))
+
+(defun anything-c-skip-boring-files (files)
+ "Files matching `anything-c-boring-file-regexp' will be
+skipped."
+ (let (filtered-files)
+ (loop for file in files
+ do (when (not (string-match anything-c-boring-file-regexp file))
+ (push file filtered-files))
+ finally (return (nreverse filtered-files)))))
+
+(defun anything-c-w32-pathname-transformer (args)
+ "Change undesirable features of windows pathnames to ones more acceptable to
+other candidate transformers."
+ (if (eq system-type 'windows-nt)
+ (mapcar (lambda (x)
+ (replace-regexp-in-string "/cygdrive/\\(.\\)" "\\1:" x))
+ (mapcar (lambda (y)
+ (replace-regexp-in-string "\\\\" "/" y)) args))
+ args))
+
+
+(defun anything-c-shorten-home-path (files)
+ "Replaces /home/user with ~."
+ (mapcar (lambda (file)
+ (let ((home (replace-regexp-in-string "\\\\" "/" ; stupid Windows...
+ (getenv "HOME"))))
+ (if (string-match home file)
+ (cons (replace-match "~" nil nil file) file)
+ file)))
+ files))
+
+;;;; Functions
+
+(defun anything-c-mark-interactive-functions (functions)
+ "Mark interactive functions (commands) with (i) after the function name."
+ (let (list)
+ (loop for function in functions
+ do (push (cons (concat function
+ (when (commandp (intern function)) " (i)"))
+ function)
+ list)
+ finally (return (nreverse list)))))
+
+;;; Filtered Candidate Transformers
+
+;;;; Adaptive Sorting of Candidates
+
+;; User config
+
+(defvar anything-c-adaptive-history-file "~/.emacs.d/anything-c-adaptive-history"
+ "Path of file where history information is stored.")
+
+(defvar anything-c-adaptive-history-length 50
+ "Maximum number of candidates stored for a source.")
+
+;;----------------------------------------------------------------------
+
+(defvar anything-c-adaptive-done nil
+ "nil if history information is not yet stored for the current
+selection.")
+
+(defvar anything-c-adaptive-history nil
+ "Contains the stored history information.
+Format: ((SOURCE-NAME (SELECTED-CANDIDATE (PATTERN . NUMBER-OF-USE) ...) ...) ...)")
+
+(defadvice anything-initialize (before anything-c-adaptive-initialize activate)
+ "Advise `anything-initialize' to reset `anything-c-adaptive-done'
+when anything is started."
+ (setq anything-c-adaptive-done nil))
+
+(defadvice anything-exit-minibuffer (before anything-c-adaptive-exit-minibuffer activate)
+ "Advise `anything-exit-minibuffer' to store history information
+when a candidate is selected with RET."
+ (anything-c-adaptive-store-selection))
+
+(defadvice anything-select-action (before anything-c-adaptive-select-action activate)
+ "Advise `anything-select-action' to store history information
+when the user goes to the action list with TAB."
+ (anything-c-adaptive-store-selection))
+
+(defun anything-c-adaptive-store-selection ()
+ "Store history information for the selected candidate."
+ (unless anything-c-adaptive-done
+ (setq anything-c-adaptive-done t)
+ (let* ((source (anything-get-current-source))
+ (source-name (or (assoc-default 'type source)
+ (assoc-default 'name source)))
+ (source-info (or (assoc source-name anything-c-adaptive-history)
+ (progn
+ (push (list source-name) anything-c-adaptive-history)
+ (car anything-c-adaptive-history))))
+ (selection (anything-get-selection))
+ (selection-info (progn
+ (setcdr source-info
+ (cons
+ (let ((found (assoc selection (cdr source-info))))
+ (if (not found)
+ ;; new entry
+ (list selection)
+
+ ;; move entry to the beginning of the
+ ;; list, so that it doesn't get
+ ;; trimmed when the history is
+ ;; truncated
+ (setcdr source-info
+ (delete found (cdr source-info)))
+ found))
+ (cdr source-info)))
+ (cadr source-info)))
+ (pattern-info (progn
+ (setcdr selection-info
+ (cons
+ (let ((found (assoc anything-pattern (cdr selection-info))))
+ (if (not found)
+ ;; new entry
+ (cons anything-pattern 0)
+
+ ;; move entry to the beginning of the
+ ;; list, so if two patterns used the
+ ;; same number of times then the one
+ ;; used last appears first in the list
+ (setcdr selection-info
+ (delete found (cdr selection-info)))
+ found))
+ (cdr selection-info)))
+ (cadr selection-info))))
+
+ ;; increase usage count
+ (setcdr pattern-info (1+ (cdr pattern-info)))
+
+ ;; truncate history if needed
+ (if (> (length (cdr selection-info)) anything-c-adaptive-history-length)
+ (setcdr selection-info
+ (subseq (cdr selection-info) 0 anything-c-adaptive-history-length))))))
+
+(if (file-readable-p anything-c-adaptive-history-file)
+ (load-file anything-c-adaptive-history-file))
+(add-hook 'kill-emacs-hook 'anything-c-adaptive-save-history)
+
+(defun anything-c-adaptive-save-history ()
+ "Save history information to file given by
+`anything-c-adaptive-history-file'."
+ (interactive)
+ (with-temp-buffer
+ (insert
+ ";; -*- mode: emacs-lisp -*-\n"
+ ";; History entries used for anything adaptive display.\n")
+ (prin1 `(setq anything-c-adaptive-history ',anything-c-adaptive-history)
+ (current-buffer))
+ (insert ?\n)
+ (write-region (point-min) (point-max) anything-c-adaptive-history-file nil
+ (unless (interactive-p) 'quiet))))
+
+(defun anything-c-adaptive-sort (candidates source)
+ "Sort the CANDIDATES for SOURCE by usage frequency.
+This is a filtered candidate transformer you can use for the
+attribute `filtered-candidate-transformer' of a source in
+`anything-sources' or a type in `anything-type-attributes'."
+ (let* ((source-name (or (assoc-default 'type source)
+ (assoc-default 'name source)))
+ (source-info (assoc source-name anything-c-adaptive-history)))
+ (if (not source-info)
+ ;; if there is no information stored for this source then do nothing
+ candidates
+ ;; else...
+ (let ((usage
+ ;; ... assemble a list containing the (CANIDATE . USAGE-COUNT)
+ ;; pairs
+ (mapcar (lambda (candidate-info)
+ (let ((count 0))
+ (dolist (pattern-info (cdr candidate-info))
+ (if (not (equal (car pattern-info)
+ anything-pattern))
+ (incf count (cdr pattern-info))
+
+ ;; if current pattern is equal to the previously
+ ;; used one then this candidate has priority
+ ;; (that's why its count is boosted by 10000) and
+ ;; it only has to compete with other candidates
+ ;; which were also selected with the same pattern
+ (setq count (+ 10000 (cdr pattern-info)))
+ (return)))
+ (cons (car candidate-info) count)))
+ (cdr source-info)))
+ sorted)
+
+ ;; sort the list in descending order, so candidates with highest
+ ;; priorty come first
+ (setq usage (sort usage (lambda (first second)
+ (> (cdr first) (cdr second)))))
+
+ ;; put those candidates first which have the highest usage count
+ (dolist (info usage)
+ (when (member* (car info) candidates
+ :test 'anything-c-adaptive-compare)
+ (push (car info) sorted)
+ (setq candidates (remove* (car info) candidates
+ :test 'anything-c-adaptive-compare))))
+
+ ;; and append the rest
+ (append (reverse sorted) candidates nil)))))
+
+(defun anything-c-adaptive-compare (x y)
+ "Compare candidates X and Y taking into account that the
+candidate can be in (DISPLAY . REAL) format."
+ (equal (if (listp x)
+ (cdr x)
+ x)
+ (if (listp y)
+ (cdr y)
+ y)))
+
+;;; Default Configuration
+
+;;;; Helper Functions
+
+(defun anything-c-compose (arg-lst func-lst)
+ "Call each function in FUNC-LST with the arguments specified in
+ARG-LST. The result of each function will be the new `car' of
+ARG-LST.
+
+This function allows easy sequencing of transformer functions."
+ (dolist (func func-lst)
+ (setcar arg-lst (apply func arg-lst)))
+ (car arg-lst))
+
+;;;; Sources
+
+(setq anything-sources
+ (list anything-c-source-buffers
+ anything-c-source-buffer-not-found
+ anything-c-source-file-name-history
+ anything-c-source-info-pages
+ anything-c-source-man-pages
+ anything-c-source-locate
+ anything-c-source-emacs-commands))
+
+;;;; Type Attributes
+
+(setq anything-type-attributes
+ `((buffer
+ (action
+ ,@(if pop-up-frames
+ '(("Switch to buffer other window" . switch-to-buffer-other-window)
+ ("Switch to buffer" . switch-to-buffer))
+ '(("Switch to buffer" . switch-to-buffer)
+ ("Switch to buffer other window" . switch-to-buffer-other-window)
+ ("Switch to buffer other frame" . switch-to-buffer-other-frame)))
+ ("Display buffer" . display-buffer)
+ ("Kill buffer" . kill-buffer)))
+ (file
+ (action
+ ,@(if pop-up-frames
+ '(("Find file other window" . find-file-other-window)
+ ("Find file" . find-file))
+ '(("Find file" . find-file)
+ ("Find file other window" . find-file-other-window)
+ ("Find file other frame" . find-file-other-frame)))
+ ("Open dired in file's directory" . anything-c-open-dired)
+ ("Delete file" . anything-c-delete-file)
+ ("Open file externally" . anything-c-open-file-externally)
+ ("Open file with default tool" . anything-c-open-file-with-default-tool))
+ (action-transformer . (lambda (actions candidate)
+ (anything-c-compose
+ (list actions candidate)
+ '(anything-c-transform-file-load-el
+ anything-c-transform-file-browse-url))))
+ (candidate-transformer . (lambda (candidates)
+ (anything-c-compose
+ (list candidates)
+ '(anything-c-w32-pathname-transformer
+ anything-c-skip-boring-files
+ anything-c-shorten-home-path)))))
+ (command (action ("Call interactively" . (lambda (command-name)
+ (call-interactively (intern command-name))))
+ ("Describe command" . (lambda (command-name)
+ (describe-function (intern command-name))))
+ ("Add command to kill ring" . kill-new)
+ ("Go to command's definition" . (lambda (command-name)
+ (find-function
+ (intern command-name)))))
+ ;; Sort commands according to their usage count.
+ (filtered-candidate-transformer . anything-c-adaptive-sort))
+ (function (action ("Describe function" . (lambda (function-name)
+ (describe-function (intern function-name))))
+ ("Add function to kill ring" . kill-new)
+ ("Go to function's definition" . (lambda (function-name)
+ (find-function
+ (intern function-name)))))
+ (action-transformer . (lambda (actions candidate)
+ (anything-c-compose
+ (list actions candidate)
+ '(anything-c-transform-function-call-interactively))))
+ (candidate-transformer . (lambda (candidates)
+ (anything-c-compose
+ (list candidates)
+ '(anything-c-mark-interactive-functions)))))
+ (sexp (action ("Eval s-expression" . (lambda (c)
+ (eval (read c))))
+ ("Add s-expression to kill ring" . kill-new))
+ (action-transformer . (lambda (actions candidate)
+ (anything-c-compose
+ (list actions candidate)
+ '(anything-c-transform-sexp-eval-command-sexp)))))
+ (bookmark (action ("Jump to bookmark" . bookmark-jump)
+ ("Delete bookmark" . bookmark-delete)))))
+
+;;; Provide anything-config
+
+(provide 'anything-config)
+
+;; Local Variables:
+;; mode: outline-minor
+;; End:
+
+;;; anything-config.el ends here
--- /dev/null
+;; some extensions to anything.el
+
+;; websearch
+;; Created : mar-01/20/09
+(defun make-anything-c-source-websearch (name url &rest extra)
+ (anything-c-define-dummy-source
+ (concat "Websearch for " name)
+ #'anything-c-dummy-candidate
+ `(action . ,(eval `(lambda (args)
+ (browse-url (apply 'concat ,url anything-pattern (quote ,extra))))))))
+
+(make-anything-c-source-websearch "Stack overflow"
+ "http://stackoverflow.com/questions/tagged/")
--- /dev/null
+;;; anything.el --- open anything / QuickSilver-like candidate-selection framework
+;; $Id: anything.el,v 1.138 2008/12/21 16:56:05 rubikitch Exp $
+
+;; Copyright (C) 2007 Tamas Patrovics
+;; 2008 rubikitch <rubikitch@ruby-lang.org>
+
+;; Author: Tamas Patrovics
+;; Maintainer: rubikitch <rubikitch@ruby-lang.org>
+;; Keywords: files, frames, help, matching, outlines, processes, tools, convenience, anything
+;; URL: http://www.emacswiki.org/cgi-bin/wiki/download/anything.el
+;; Site: http://www.emacswiki.org/cgi-bin/emacs/Anything
+
+;; This file is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation; either version 2, or (at your option)
+;; any later version.
+
+;; This file is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs; see the file COPYING. If not, write to the
+;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
+
+;;; Commentary:
+
+;;
+;; Start with M-x anything, narrow the list by typing some pattern,
+;; select with up/down/pgup/pgdown, choose with enter, left/right
+;; moves between sources. With TAB actions can be selected if the
+;; selected candidate has more than one possible action.
+;;
+;; Note that anything.el provides only the framework and some example
+;; configurations for demonstration purposes. See anything-config.el
+;; for practical, polished, easy to use configurations which can be
+;; used to assemble a custom personalized configuration. And many
+;; other configurations are in the EmacsWiki.
+;;
+;; http://www.emacswiki.org/cgi-bin/wiki/download/anything-config.el
+;; http://www.emacswiki.org/cgi-bin/emacs/AnythingSources
+;;
+;; Maintainer's configuration is in the EmacsWiki. It would tell you
+;; many tips to write smart sources!
+;;
+;; http://www.emacswiki.org/cgi-bin/emacs/RubikitchAnythingConfiguration
+
+;; You can extend `anything' by writing plug-ins. As soon as
+;; `anything' is invoked, `anything-sources' is compiled into basic
+;; attributes, then compiled one is used during invocation.
+;;
+;; The oldest built-in plug-in is `type' attribute: appends
+;; appropriate element of `anything-type-attributes'. Second built-in
+;; plug-in is `candidates-in-buffer': selecting a line from candidates
+;; buffer.
+;;
+;; To write a plug-in:
+;; 1. Define a compiler: anything-compile-source--*
+;; 2. Add compier function to `anything-compile-source-functions'.
+;; 3. (optional) Write helper functions.
+;;
+;; Anything plug-ins are found in the EmacsWiki.
+;;
+;; http://www.emacswiki.org/cgi-bin/emacs/AnythingPlugins
+
+;; Tested on Emacs 22.
+;;
+;;
+;; Thanks to Vagn Johansen for ideas.
+;; Thanks to Stefan Kamphausen for fixes and XEmacs support.
+;; Thanks to Tassilo Horn for fixes.
+;; Thanks to Drew Adams for various fixes (frame, isearch, customization, etc.)
+;; Thanks to IMAKADO for candidates-in-buffer idea.
+;; Thanks to Tomohiro MATSUYAMA for multiline patch.
+;;
+
+;;; (@* "Index")
+
+;; If you have library `linkd.el', load
+;; `linkd.el' and turn on `linkd-mode' now. It lets you easily
+;; navigate around the sections Linkd mode will
+;; highlight this Index. You can get `linkd.el' here:
+;; http://www.emacswiki.org/cgi-bin/wiki/download/linkd.el
+;;
+
+
+;;; (@* "INCOMPATIBLE CHANGES")
+
+;; v1.114
+;;
+;; `anything-attr' returns nil when the source attribute is defined
+;; but the value of attribute is nil, eg. (volatile) cell. Use
+;; `anything-attr-defined' when testing whether the attribute is
+;; defined.
+
+;;; (@* "Tips")
+
+;;
+;; `set-frame-configuration' arises flickering. If you hate
+;; flickering, eval:
+;; (setq anything-save-configuration-functions
+;; '(set-window-configuration . current-window-configuration))
+;; at the cost of restoring frame configuration (only window configuration).
+
+;;
+;; `anything-delete-current-selection' deletes the current line.
+;; It is useful when deleting a candidate in persistent action.
+;; eg. `kill-buffer'.
+;;
+;; [EVAL IT] (describe-function 'anything-delete-current-selection)
+
+;;
+;; `anything-attr' gets the attribute. `anything-attrset' sets the
+;; attribute. `anything-attr-defined' tests whether the attribute is
+;; defined. They handles source-local variables.
+;;
+;; [EVAL IT] (describe-function 'anything-attr)
+;; [EVAL IT] (describe-function 'anything-attrset)
+;; [EVAL IT] (describe-function 'anything-attr-defined)
+
+;;
+;; `anything-sources' accepts many attributes to make your life easier.
+;; Now `anything-sources' accepts a list of symbols.
+;;
+;; [EVAL IT] (describe-variable 'anything-sources)
+
+;;
+;; `anything' has optional arguments. Now you do not have to let-bind
+;; `anything-sources'.
+;;
+;; [EVAL IT] (describe-function 'anything)
+
+;;
+;; `anything-resume' resumes last `anything' session. Now you do not
+;; have to retype pattern.
+;;
+;; [EVAL IT] (describe-function 'anything-resume)
+
+;;
+;; `anything-execute-persistent-action' executes action without
+;; quitting `anything'. When popping up a buffer in other window by
+;; persistent action, you can scroll with `anything-scroll-other-window' and
+;; `anything-scroll-other-window-down'. See also `anything-sources' docstring.
+;;
+;; [EVAL IT] (describe-function 'anything-execute-persistent-action)
+;; [EVAL IT] (describe-variable 'anything-sources)
+
+;;
+;; `anything-select-2nd-action', `anything-select-3rd-action' and
+;; `anything-select-4th-action' select other than default action
+;; without pressing Tab.
+
+;;
+;; Using `anything-candidate-buffer' and the candidates-in-buffer
+;; attribute is much faster than traditional "candidates and match"
+;; way. And `anything-current-buffer-is-modified' avoids to
+;; recalculate candidates for unmodified buffer. See docstring of
+;; them.
+;;
+;; [EVAL IT] (describe-function 'anything-candidate-buffer)
+;; [EVAL IT] (describe-function 'anything-candidates-in-buffer)
+;; [EVAL IT] (describe-function 'anything-current-buffer-is-modified)
+
+;;
+;; `anything-current-buffer' and `anything-buffer-file-name' stores
+;; `(current-buffer)' and `buffer-file-name' in the buffer `anything'
+;; is invoked. Use them freely.
+;;
+;; [EVAL IT] (describe-variable 'anything-current-buffer)
+;; [EVAL IT] (describe-variable 'anything-buffer-file-name)
+
+;;
+;; `anything-completing-read' and `anything-read-file-name' are
+;; experimental implementation. If you are curious, type M-x
+;; anything-read-string-mode. It is a minor mode and toggles on/off.
+
+;;
+;; Use `anything-test-candidates' to test your handmade anything
+;; sources. It simulates contents of *anything* buffer with pseudo
+;; `anything-sources' and `anything-pattern', without side-effect. So
+;; you can unit-test your anything sources! Let's TDD!
+;;
+;; [EVAL IT] (describe-function 'anything-test-candidates)
+;;
+;; There are many unit-testing framework in Emacs Lisp. See the EmacsWiki.
+;; http://www.emacswiki.org/cgi-bin/emacs/UnitTesting
+;;
+;; There is an unit-test by Emacs Lisp Expectations at the tail of this file.
+;; http://www.emacswiki.org/cgi-bin/wiki/download/el-expectations.el
+;; http://www.emacswiki.org/cgi-bin/wiki/download/el-mock.el
+
+
+;; (@* "TODO")
+;;
+;; - process status indication
+;;
+;; - results from async sources should appear in the order they are
+;; specified in anything-sources
+;;
+;; - async sources doesn't honor digit-shortcut-count
+;;
+;; - anything-candidate-number-limit can't be nil everywhere
+;;
+;; - support multi line candidates
+
+;; (@* "HISTORY")
+;; $Log: anything.el,v $
+;; Revision 1.138 2008/12/21 16:56:05 rubikitch
+;; Fixed an error when action attribute is a function symbol and press TAB,
+;;
+;; Revision 1.137 2008/12/20 19:38:47 rubikitch
+;; `anything-check-minibuffer-input-1': proper quit handling
+;; `anything-process-delayed-sources': ditto
+;;
+;; Revision 1.136 2008/10/27 17:41:27 rubikitch
+;; `anything-process-delayed-sources', `anything-check-minibuffer-input-1': quittable
+;;
+;; Revision 1.135 2008/10/27 17:04:25 rubikitch
+;; arranged source, added more linkd tags (no code change)
+;;
+;; Revision 1.134 2008/10/27 15:02:25 rubikitch
+;; New variable: `anything-save-configuration-functions'
+;; Delete variable: `anything-save-configuration-type'
+;;
+;; Revision 1.133 2008/10/27 11:16:13 rubikitch
+;; New variable: `anything-save-configuration-type'
+;;
+;; Revision 1.132 2008/10/26 22:34:59 rubikitch
+;; `anything-delete-current-selection' with multiline
+;;
+;; Revision 1.131 2008/10/26 21:44:43 rubikitch
+;; New command: `anything-delete-current-selection'
+;;
+;; Revision 1.130 2008/10/22 10:41:09 rubikitch
+;; `anything-insert-match': do not override 'anything-realvalue property
+;;
+;; Revision 1.129 2008/10/21 17:01:37 rubikitch
+;; `anything-resume' per buffer.
+;; `anything-last-sources': obsolete
+;;
+;; Revision 1.128 2008/10/20 06:27:54 rubikitch
+;; `anything-quick-update': new user option
+;;
+;; Revision 1.127 2008/10/20 05:47:49 rubikitch
+;; refactoring
+;;
+;; Revision 1.126 2008/10/20 03:47:58 rubikitch
+;; `anything-update': reversed order of delayed sources
+;;
+;; Revision 1.125 2008/10/19 00:29:54 rubikitch
+;; kill buffer-local candidate buffers when creating global candidate buffers.
+;;
+;; Revision 1.124 2008/10/18 13:04:20 rubikitch
+;; Remove tick entry from `anything-tick-hash' when killing a buffer.
+;;
+;; Revision 1.123 2008/10/18 10:23:36 rubikitch
+;; multiline patch by Tomohiro MATSUYAMA.
+;;
+;; Revision 1.122 2008/10/13 03:10:07 rubikitch
+;; `anything': do `anything-mark-current-line' when resuming
+;;
+;; Revision 1.121 2008/10/13 03:08:08 rubikitch
+;; always set `anything-current-position'
+;;
+;; Revision 1.120 2008/10/07 14:12:02 rubikitch
+;; `anything-execute-persistent-action': optional arg
+;;
+;; Revision 1.119 2008/10/06 06:43:29 rubikitch
+;; `anything-candidate-buffer': return nil when the buffer is dead
+;;
+;; Revision 1.118 2008/09/30 22:21:28 rubikitch
+;; New `anything-sources' attribute: accept-empty
+;; dummy: include accept-empty
+;;
+;; Revision 1.117 2008/09/30 21:59:10 rubikitch
+;; New function: `anything-buffer-is-modified'
+;;
+;; Revision 1.116 2008/09/22 11:27:29 rubikitch
+;; *** empty log message ***
+;;
+;; Revision 1.115 2008/09/20 20:21:11 rubikitch
+;; added linkd index. (no code change)
+;;
+;; Revision 1.114 2008/09/20 20:09:57 rubikitch
+;; INCOMPATIBLE CHANGES: `anything-attr'
+;; New functions: `anything-attrset', `anything-attr-defined'
+;;
+;; Revision 1.113 2008/09/14 15:15:32 rubikitch
+;; bugfix: volatile and match attribute / process and match attribute
+;;
+;; Revision 1.112 2008/09/12 01:57:17 rubikitch
+;; When resuming anything, reinitialize overlays.
+;;
+;; Revision 1.111 2008/09/10 22:53:11 rubikitch
+;; anything: bug fix of `anything-buffer'
+;; New macro: `anything-test-update'
+;;
+;; Revision 1.110 2008/09/10 22:17:11 rubikitch
+;; New `anything-sources' attribute: header-name
+;;
+;; Revision 1.109 2008/09/10 21:12:26 rubikitch
+;; New hook: `anything-after-action-hook'
+;;
+;; Revision 1.108 2008/09/06 06:07:56 rubikitch
+;; Extended `anything-set-sources' optional arguments.
+;;
+;; Revision 1.107 2008/09/05 03:14:35 rubikitch
+;; reimplement `anything-current-buffer-is-modified' in the right way
+;;
+;; Revision 1.106 2008/09/05 00:11:05 rubikitch
+;; Moved `anything-read-string-mode' and read functions to anything-complete.el.
+;;
+;; Revision 1.105 2008/09/04 12:45:06 rubikitch
+;; New hook: `anything-after-persistent-action-hook'
+;;
+;; Revision 1.104 2008/09/04 12:27:05 rubikitch
+;; `anything': prefixed optional arguments
+;;
+;; Revision 1.103 2008/09/04 09:16:28 rubikitch
+;; fixed a bug of `anything-read-file-name'.
+;;
+;; Revision 1.102 2008/09/03 11:25:19 rubikitch
+;; Extended `anything' optional arguments: buffer
+;;
+;; Revision 1.101 2008/09/03 11:15:13 rubikitch
+;; `anything': return nil when keybord-quitted
+;;
+;; Revision 1.100 2008/09/01 23:11:02 rubikitch
+;; bug fix of search-from-end
+;;
+;; Revision 1.99 2008/09/01 13:45:55 rubikitch
+;; bug fix of search-from-end
+;;
+;; Revision 1.98 2008/09/01 11:23:38 rubikitch
+;; New `anything-sources' attribute: search-from-end
+;;
+;; Revision 1.97 2008/09/01 00:44:34 rubikitch
+;; Make sure to display the other window when persistent action.
+;;
+;; Revision 1.96 2008/08/31 20:55:20 rubikitch
+;; define `buffer-modified-tick' for older emacs.
+;;
+;; Revision 1.95 2008/08/30 04:55:51 rubikitch
+;; fixed a bug of `anything-completing-read'
+;;
+;; Revision 1.94 2008/08/28 20:18:03 rubikitch
+;; added some tests
+;;
+;; Revision 1.93 2008/08/25 20:18:46 rubikitch
+;; `anything': set `anything-input' and `anything-pattern' before `anything-update'
+;;
+;; Revision 1.92 2008/08/24 22:38:46 rubikitch
+;; *** empty log message ***
+;;
+;; Revision 1.91 2008/08/24 21:34:35 rubikitch
+;; rewrite `with-anything-restore-variables'
+;;
+;; Revision 1.90 2008/08/24 20:33:02 rubikitch
+;; prevent the unit test from byte-compiled.
+;; macro bug fix.
+;;
+;; Revision 1.89 2008/08/24 08:35:27 rubikitch
+;; *** empty log message ***
+;;
+;; Revision 1.88 2008/08/24 08:22:19 rubikitch
+;; Rename `anything-candidates-buffer' -> `anything-candidate-buffer'
+;;
+;; Revision 1.87 2008/08/23 22:27:04 rubikitch
+;; New hook: `anything-cleanup-hook'
+;;
+;; Revision 1.86 2008/08/23 22:05:42 rubikitch
+;; `anything-original-source-filter' is removed.
+;; Now use `anything-restored-variables' and `with-anything-restore-variables'.
+;;
+;; Revision 1.85 2008/08/23 21:23:21 rubikitch
+;; inhibit-read-only = t in anything-buffer
+;;
+;; Revision 1.84 2008/08/23 21:18:33 rubikitch
+;; *** empty log message ***
+;;
+;; Revision 1.83 2008/08/23 20:44:20 rubikitch
+;; `anything-execute-persistent-action': display-to-real bug fix
+;;
+;; Revision 1.82 2008/08/23 20:19:12 rubikitch
+;; New `anything-sources' attribute: get-line
+;;
+;; Revision 1.81 2008/08/23 19:32:14 rubikitch
+;; `anything-attr': Return t in (attribute-name) case.
+;;
+;; Revision 1.80 2008/08/22 21:25:05 rubikitch
+;; anything-candidates-in-buffer-1:
+;; Open a line at the BOB to make use of `search-forward' for faster exact/prefix match.
+;; Of course, restore the buffer contents after search.
+;;
+;; Revision 1.79 2008/08/22 17:11:00 rubikitch
+;; New hook: `anything-before-initialize-hook', `anything-after-initialize-hook'
+;;
+;; Revision 1.78 2008/08/21 18:37:03 rubikitch
+;; Implemented dummy sources as plug-in.
+;;
+;; Revision 1.77 2008/08/21 17:40:40 rubikitch
+;; New function: `anything-set-sources'
+;;
+;; Revision 1.76 2008/08/21 12:25:02 rubikitch
+;; New variable: `anything-version'
+;;
+;; Revision 1.75 2008/08/21 12:13:46 rubikitch
+;; New variable: `anything-in-persistent-action'
+;;
+;; Revision 1.74 2008/08/21 10:34:22 rubikitch
+;; New function `anything-mklist'
+;;
+;; Revision 1.73 2008/08/21 09:41:38 rubikitch
+;; accept multiple init/cleanup functions so that plug-ins can add new function.
+;;
+;; Revision 1.72 2008/08/20 22:51:53 rubikitch
+;; New `anything-sources' attribute: candidate-number-limit
+;;
+;; Revision 1.71 2008/08/20 21:45:42 rubikitch
+;; added many tests.
+;;
+;; Revision 1.70 2008/08/20 18:51:45 rubikitch
+;; `anything-preselect' bug fix.
+;; refactoring.
+;;
+;; Revision 1.69 2008/08/20 17:57:51 rubikitch
+;; Extended `anything' optional arguments: preselect
+;;
+;; Revision 1.68 2008/08/20 16:39:07 rubikitch
+;; Nested `anything' invocation support, ie. `anything' can be invoked by anything action.
+;;
+;; (anything '(((name . "nested anything invocation test")
+;; (candidates "anything-c-source-buffers" "anything-c-source-man-pages")
+;; (display-to-real . intern)
+;; (action . anything))))
+;;
+;; Revision 1.67 2008/08/20 00:08:28 rubikitch
+;; `anything-candidates-in-buffer-1': add code when pattern == ""
+;;
+;; Revision 1.66 2008/08/19 23:31:52 rubikitch
+;; Removed `anything-show-exact-match-first' because it should be provided as a plug-in.
+;;
+;; Revision 1.65 2008/08/19 23:18:47 rubikitch
+;; *** empty log message ***
+;;
+;; Revision 1.64 2008/08/19 23:15:43 rubikitch
+;; `anything-compute-matches': short-cut when match == '(identity)
+;;
+;; Revision 1.63 2008/08/19 23:06:42 rubikitch
+;; Use hash table to speed uniquify candidates.
+;;
+;; Revision 1.62 2008/08/19 22:40:57 rubikitch
+;; `anything-test-candidates': additional optonal argument
+;;
+;; Revision 1.61 2008/08/19 18:13:39 rubikitch
+;; search attribute: multiple search functions
+;;
+;; Revision 1.60 2008/08/19 15:07:39 rubikitch
+;; New function: `anything-attr'
+;;
+;; Revision 1.59 2008/08/19 15:01:59 rubikitch
+;; arranged code
+;; added unit tests
+;; update doc
+;;
+;; Revision 1.58 2008/08/19 13:40:52 rubikitch
+;; `anything-get-current-source': This function can be used in
+;; init/candidates/action/candidate-transformer/filtered-candidate-transformer
+;; display-to-real/cleanup function.
+;;
+;; Revision 1.57 2008/08/19 03:43:57 rubikitch
+;; `anything-process-delayed-sources': delay = anything-idle-delay - anything-input-idle-delay
+;;
+;; Revision 1.56 2008/08/18 06:37:51 rubikitch
+;; Make `anything-input-idle-delay' ineffective when the action list is shown.
+;;
+;; Revision 1.55 2008/08/18 06:35:00 rubikitch
+;; New variable: `anything-show-exact-match-first'
+;;
+;; Revision 1.54 2008/08/17 23:22:24 rubikitch
+;; *** empty log message ***
+;;
+;; Revision 1.53 2008/08/17 23:15:38 rubikitch
+;; bind `anything-source-name' when executing action to enable to use `anything-candidate-buffer' in action.
+;;
+;; Revision 1.52 2008/08/17 15:21:27 rubikitch
+;; `anything-test-candidates': accept a symbol for source
+;; New variable: `anything-input-idle-delay'
+;;
+;; Revision 1.51 2008/08/17 12:45:30 rubikitch
+;; (buffer-disable-undo) in anything-buffer
+;;
+;; Revision 1.50 2008/08/16 22:21:37 rubikitch
+;; `anything-saved-sources': removed
+;; `anything-action-buffer': action selection buffer
+;; `anything-select-action': toggle actions <=> candidates
+;;
+;; Revision 1.49 2008/08/16 19:46:11 rubikitch
+;; New function: `anything-action-list-is-shown'
+;;
+;; Revision 1.48 2008/08/16 17:03:02 rubikitch
+;; bugfix: cleanup
+;;
+;; Revision 1.47 2008/08/16 16:35:24 rubikitch
+;; silence byte compiler
+;;
+;; Revision 1.46 2008/08/16 14:51:27 rubikitch
+;; *** empty log message ***
+;;
+;; Revision 1.45 2008/08/16 11:27:59 rubikitch
+;; refactoring
+;; `anything-aif': Anaphoric if.
+;; `anything-compile-source-functions': make `anything-get-sources' customizable.
+;;
+;; Revision 1.44 2008/08/16 09:38:15 rubikitch
+;; *** empty log message ***
+;;
+;; Revision 1.43 2008/08/15 11:44:28 rubikitch
+;; `anything-read-string-mode': minor mode for `anything' version of read functions. (experimental)
+;;
+;; Revision 1.42 2008/08/15 11:03:20 rubikitch
+;; update docs
+;;
+;; Revision 1.41 2008/08/14 20:51:28 rubikitch
+;; New `anything-sources' attribute: cleanup
+;;
+;; Revision 1.40 2008/08/14 10:34:04 rubikitch
+;; `anything': SOURCES: accept symbols
+;;
+;; Revision 1.39 2008/08/10 22:46:01 rubikitch
+;; `anything-move-selection': avoid infinite loop
+;;
+;; Revision 1.38 2008/08/09 21:38:25 rubikitch
+;; `anything-read-file-name': experimental implementation.
+;;
+;; Revision 1.37 2008/08/09 17:54:25 rubikitch
+;; action test
+;;
+;; Revision 1.36 2008/08/09 17:13:00 rubikitch
+;; fixed test
+;;
+;; Revision 1.35 2008/08/09 10:43:08 rubikitch
+;; New `anything-sources' attribute: display-to-real
+;;
+;; Revision 1.34 2008/08/07 13:15:44 rubikitch
+;; New `anything-sources' attribute: search
+;;
+;; Revision 1.33 2008/08/05 23:14:20 rubikitch
+;; `anything-candidate-buffer': bugfix
+;;
+;; Revision 1.32 2008/08/05 21:42:15 rubikitch
+;; *** empty log message ***
+;;
+;; Revision 1.31 2008/08/05 21:06:23 rubikitch
+;; `anything-candidate-buffer': candidates buffer registration
+;;
+;; Revision 1.30 2008/08/05 19:46:36 rubikitch
+;; New `anything-sources' attribute: candidates-in-buffer
+;;
+;; Revision 1.29 2008/08/05 17:58:31 rubikitch
+;; *** empty log message ***
+;;
+;; Revision 1.28 2008/08/05 17:46:04 rubikitch
+;; memoized `anything-get-sources'
+;;
+;; Revision 1.27 2008/08/05 17:29:40 rubikitch
+;; update doc
+;;
+;; Revision 1.26 2008/08/05 08:35:45 rubikitch
+;; `anything-completing-read': accept obarray
+;;
+;; Revision 1.25 2008/08/05 07:26:17 rubikitch
+;; `anything-completing-read': guard from non-string return value
+;;
+;; Revision 1.24 2008/08/04 12:05:41 rubikitch
+;; Wrote Tips and some docstrings.
+;; `anything-candidate-buffer': buffer-local by default
+;;
+;; Revision 1.23 2008/08/04 05:29:46 rubikitch
+;; `anything-buffer-file-name': `buffer-file-name' when `anything' is invoked.
+;;
+;; Revision 1.22 2008/08/04 00:10:13 rubikitch
+;; `anything-candidate-buffer': new API
+;;
+;; Revision 1.21 2008/08/03 22:05:08 rubikitch
+;; `anything-candidate-buffer': Return a buffer containing candidates of current source.
+;;
+;; Revision 1.20 2008/08/03 20:47:56 rubikitch
+;; `anything-current-buffer-is-modified': modify checker
+;;
+;; Revision 1.19 2008/08/03 19:06:18 rubikitch
+;; `anything-candidates-in-buffer': use `with-current-buffer' instead.
+;;
+;; Revision 1.18 2008/08/03 05:55:01 rubikitch
+;; `anything-candidates-in-buffer': extract candidates in a buffer for speed.
+;;
+;; Revision 1.17 2008/08/02 21:31:29 rubikitch
+;; Extended `anything' optional arguments.
+;; `anything-completing-read': experimental implementation.
+;;
+;; Revision 1.16 2008/08/02 20:32:54 rubikitch
+;; Extended `anything' optional arguments.
+;;
+;; Revision 1.15 2008/08/02 16:53:40 rubikitch
+;; Fixed a small bug of `anything-test-candidates'.
+;;
+;; Revision 1.14 2008/08/02 16:48:29 rubikitch
+;; Refactored to testable code.
+;; Added many candidate tests with `anything-test-candidates'.
+;;
+;; Revision 1.13 2008/08/02 15:08:14 rubikitch
+;; *** empty log message ***
+;;
+;; Revision 1.12 2008/08/02 14:29:31 rubikitch
+;; `anything-sources' accepts symbols. (patched by Sugawara)
+;;
+;; Revision 1.11 2008/08/02 10:20:36 rubikitch
+;; `anything-resume' is usable with other (let-binded) `anything-sources'.
+;;
+;; Revision 1.10 2008/08/01 19:44:01 rubikitch
+;; `anything-resume': resurrect previously invoked `anything'.
+;;
+;; Revision 1.9 2008/07/30 15:44:49 rubikitch
+;; *** empty log message ***
+;;
+;; Revision 1.8 2008/07/30 15:38:51 rubikitch
+;; *** empty log message ***
+;;
+;; Revision 1.7 2008/07/30 15:21:48 rubikitch
+;; `anything-scroll-other-window', `anything-scroll-other-window-down':
+;; Scroll other window (for persistent action).
+;;
+;; Revision 1.6 2008/07/30 15:12:36 rubikitch
+;; *** empty log message ***
+;;
+;; Revision 1.5 2008/07/30 15:06:32 rubikitch
+;; `anything-select-2nd-action', `anything-select-3rd-action', `anything-select-4th-action':
+;; Select other than default action without pressing Tab.
+;;
+;; Revision 1.4 2008/07/30 14:58:27 rubikitch
+;; `anything-current-buffer': Store current buffer when `anything' is invoked.
+;; `anything-current-position': Restore position when keyboard-quitted.
+;;
+;; Revision 1.3 2008/07/30 14:38:04 rubikitch
+;; Implemented persistent action.
+;;
+;; Revision 1.2 2008/07/30 13:37:16 rubikitch
+;; Update doc.
+;;
+;; Revision 1.1 2008/07/30 13:22:06 rubikitch
+;; New maintainer.
+;;
+
+(defvar anything-version "$Id: anything.el,v 1.138 2008/12/21 16:56:05 rubikitch Exp $")
+(require 'cl)
+
+;; (@* "User Configuration")
+
+;; This is only an example. Customize it to your own taste!
+(defvar anything-sources `(((name . "Buffers")
+ (candidates
+ . (lambda ()
+ (remove-if (lambda (name)
+ (or (equal name anything-buffer)
+ (eq ?\ (aref name 0))))
+ (mapcar 'buffer-name (buffer-list)))))
+ (type . buffer))
+
+ ((name . "File Name History")
+ (candidates . file-name-history)
+ (match (lambda (candidate)
+ ;; list basename matches first
+ (string-match
+ anything-pattern
+ (file-name-nondirectory candidate)))
+
+ (lambda (candidate)
+ ;; and then directory part matches
+ (let ((dir (file-name-directory candidate)))
+ (if dir
+ (string-match anything-pattern dir)))))
+ (type . file))
+
+ ((name . "Files from Current Directory")
+ (init . (lambda ()
+ (setq anything-default-directory
+ default-directory)))
+ (candidates . (lambda ()
+ (directory-files
+ anything-default-directory)))
+ (type . file))
+
+ ((name . "Manual Pages")
+ (candidates . ,(progn
+ ;; XEmacs doesn't have a woman :)
+ (declare (special woman-file-name
+ woman-topic-all-completions))
+ (condition-case nil
+ (progn
+ (require 'woman)
+ (woman-file-name "")
+ (sort (mapcar 'car
+ woman-topic-all-completions)
+ 'string-lessp))
+ (error nil))))
+ (action . (("Open Manual Page" . woman)))
+ (requires-pattern . 2))
+
+ ((name . "Complex Command History")
+ (candidates . (lambda ()
+ (mapcar 'prin1-to-string
+ command-history)))
+ (action . (("Repeat Complex Command" .
+ (lambda (c)
+ (eval (read c))))))
+ (delayed)))
+ "The source of candidates for anything.
+It accepts symbols:
+ (setq anything-sources (list anything-c-foo anything-c-bar))
+can be written as
+ (setq anything-sources '(anything-c-foo anything-c-bar))
+The latter is recommended because if you change anything-c-* variable,
+you do not have to update `anything-sources'.
+
+If you want to change `anything-sources' during `anything' invocation,
+use `anything-set-sources', never use `setq'.
+
+Attributes:
+
+- name (mandatory)
+
+ The name of the source. It is also the heading which appears
+ above the list of matches from the source. Must be unique.
+
+- header-name (optional)
+
+ A function returning the display string of the header. Its
+ argument is the name of the source. This attribute is useful to
+ add an additional information with the source name.
+
+- candidates (mandatory if candidates-in-buffer attribute is not provided)
+
+ Specifies how to retrieve candidates from the source. It can
+ either be a variable name, a function called with no parameters
+ or the actual list of candidates.
+
+ The list must be a list of strings, so it's the responsibility
+ of the source to convert candidates to strings if necessary.
+
+ If the candidates have to be retrieved asynchronously (for
+ example, by an external command which takes a while to run)
+ then the function should start the external command
+ asynchronously and return the associated process object.
+ Anything will take care of managing the process (receiving the
+ output from it, killing it if necessary, etc.). The process
+ should return candidates matching the current pattern (see
+ variable `anything-pattern'.)
+
+ Note that currently results from asynchronous sources appear
+ last in the anything buffer regardless of their position in
+ `anything-sources'.
+
+- action (mandatory if type attribute is not provided)
+
+ It is a list of (DISPLAY . FUNCTION) pairs or FUNCTION.
+ FUNCTION is called with one parameter: the selected candidate.
+
+ An action other than the default can be chosen from this list
+ of actions for the currently selected candidate (by default
+ with TAB). The DISPLAY string is shown in the completions
+ buffer and the FUNCTION is invoked when an action is
+ selected. The first action of the list is the default.
+
+- type (optional if action attribute is provided)
+
+ Indicates the type of the items the source returns.
+
+ Merge attributes not specified in the source itself from
+ `anything-type-attributes'.
+
+ This attribute is implemented by plug-in.
+
+- init (optional)
+
+ Function called with no parameters when anything is started. It
+ is useful for collecting current state information which can be
+ used to create the list of candidates later.
+
+ For example, if a source needs to work with the current
+ directory then it can store its value here, because later
+ anything does its job in the minibuffer and in the
+ `anything-buffer' and the current directory can be different
+ there.
+
+- match (optional)
+
+ List of functions called with one parameter: a candidate. The
+ function should return non-nil if the candidate matches the
+ current pattern (see variable `anything-pattern').
+
+ This attribute allows the source to override the default
+ pattern matching based on `string-match'. It can be used, for
+ example, to implement a source for file names and do the
+ pattern matching on the basename of files, since it's more
+ likely one is typing part of the basename when searching for a
+ file, instead of some string anywhere else in its path.
+
+ If the list contains more than one function then the list of
+ matching candidates from the source is constructed by appending
+ the results after invoking the first function on all the
+ potential candidates, then the next function, and so on. The
+ matching candidates supplied by the first function appear first
+ in the list of results and then results from the other
+ functions, respectively.
+
+ This attribute has no effect for asynchronous sources (see
+ attribute `candidates'), since they perform pattern matching
+ themselves.
+
+- candidate-transformer (optional)
+
+ It's a function called with one argument when the completion
+ list from the source is built. The argument is the list of
+ candidates retrieved from the source. The function should
+ return a transformed list of candidates which will be used for
+ the actual completion.
+
+ This can be used to transform or remove items from the list of
+ candidates.
+
+ The function can also substitute candidates in the returned
+ list with (DISPLAY . REAL) pairs. In this case the DISPLAY
+ string is shown in the Anything buffer, but the REAL one is
+ used as action argument when the candidate is selected. This
+ allows a more readable presentation for candidates which would
+ otherwise be, for example, too long or have a common part
+ shared with other candidates which can be safely replaced with
+ an abbreviated string for display purposes.
+
+ Note that if the (DISPLAY . REAL) form is used then pattern
+ matching is done on the displayed string, not on the real
+ value.
+
+- filtered-candidate-transformer (optional)
+
+ It has the same format as `candidate-transformer', except the
+ function is called with two parameters: the candidate list and
+ the source.
+
+ This transformer is run on the candidate list which is already
+ filtered by the current pattern. While `candidate-transformer'
+ is run only once, it is run every time the input pattern is
+ changed.
+
+ It can be used to transform the candidate list dynamically, for
+ example, based on the current pattern.
+
+ In some cases it may also be more efficent to perform candidate
+ transformation here, instead of with `candidate-transformer'
+ even if this transformation is done every time the pattern is
+ changed. For example, if a candidate set is very large then
+ `candidate-transformer' transforms every candidate while only
+ some of them will actually be dislpayed due to the limit
+ imposed by `anything-candidate-number-limit'.
+
+ Note that `candidate-transformer' is run already, so the given
+ transformer function should also be able to handle candidates
+ with (DISPLAY . REAL) format.
+
+ This option has no effect for asynchronous sources. (Not yet,
+ at least.
+
+- action-transformer (optional)
+
+ It's a function called with two arguments when the action list
+ from the source is assembled. The first argument is the list of
+ actions, the second is the current selection.
+
+ The function should return a transformed action list.
+
+ This can be used to customize the list of actions based on the
+ currently selected candidate.
+
+- delayed (optional)
+
+ Candidates from the source are shown only if the user stops
+ typing and is idle for `anything-idle-delay' seconds.
+
+- volatile (optional)
+
+ Indicates the source assembles the candidate list dynamically,
+ so it shouldn't be cached within a single Anything
+ invocation. It is only applicable to synchronous sources,
+ because asynchronous sources are not cached.
+
+- requires-pattern (optional)
+
+ If present matches from the source are shown only if the
+ pattern is not empty. Optionally, it can have an integer
+ parameter specifying the required length of input which is
+ useful in case of sources with lots of candidates.
+
+- persistent-action (optional)
+
+ Function called with one parameter; the selected candidate.
+
+ An action performed by `anything-execute-persistent-action'.
+ If none, use the default action.
+
+- candidates-in-buffer (optional)
+
+ Shortcut attribute for making and narrowing candidates using
+ buffers. This newly-introduced attribute prevents us from
+ forgetting to add volatile and match attributes.
+
+ See docstring of `anything-candidates-in-buffer'.
+
+ (candidates-in-buffer) is equivalent of three attributes:
+ (candidates . anything-candidates-in-buffer)
+ (volatile)
+ (match identity)
+
+ (candidates-in-buffer . candidates-function) is equivalent of:
+ (candidates . candidates-function)
+ (volatile)
+ (match identity)
+
+ This attribute is implemented by plug-in.
+
+- search (optional)
+
+ List of functions like `re-search-forward' or `search-forward'.
+ Buffer search function used by `anything-candidates-in-buffer'.
+ By default, `anything-candidates-in-buffer' uses `re-search-forward'.
+ This attribute is meant to be used with
+ (candidates . anything-candidates-in-buffer) or
+ (candidates-in-buffer) in short.
+
+- search-from-end (optional)
+
+ Make `anything-candidates-in-buffer' search from the end of buffer.
+ If this attribute is specified, `anything-candidates-in-buffer' uses
+ `re-search-backward' instead.
+
+- get-line (optional)
+
+ A function like `buffer-substring-no-properties' or `buffer-substring'.
+ This function converts point of line-beginning and point of line-end,
+ which represents a candidate computed by `anything-candidates-in-buffer'.
+ By default, `anything-candidates-in-buffer' uses
+ `buffer-substring-no-properties'.
+
+- display-to-real (optional)
+
+ Function called with one parameter; the selected candidate.
+
+ The function transforms the selected candidate, and the result
+ is passed to the action function. The display-to-real
+ attribute provides another way to pass other string than one
+ shown in Anything buffer.
+
+ Traditionally, it is possible to make candidates,
+ candidate-transformer or filtered-candidate-transformer
+ function return a list with (DISPLAY . REAL) pairs. But if REAL
+ can be generated from DISPLAY, display-to-real is more
+ convenient and faster.
+
+- cleanup (optional)
+
+ Function called with no parameters when *anything* buffer is closed. It
+ is useful for killing unneeded candidates buffer.
+
+ Note that the function is executed BEFORE performing action.
+
+- candidate-number-limit (optional)
+
+ Override `anything-candidate-number-limit' only for this source.
+
+- accept-empty (optional)
+
+ Pass empty string \"\" to action function.
+
+- dummy (optional)
+
+ Set `anything-pattern' to candidate. If this attribute is
+ specified, The candidates attribute is ignored.
+
+ This attribute is implemented by plug-in.
+
+- multiline (optional)
+
+ Enable to selection multiline candidates.
+")
+
+
+;; This value is only provided as an example. Customize it to your own
+;; taste!
+(defvar anything-type-attributes
+ '((file (action . (("Find File" . find-file)
+ ("Delete File" . (lambda (file)
+ (if (y-or-n-p (format "Really delete file %s? "
+ file))
+ (delete-file file)))))))
+ (buffer (action . (("Switch to Buffer" . switch-to-buffer)
+ ("Pop to Buffer" . pop-to-buffer)
+ ("Display Buffer" . display-buffer)
+ ("Kill Buffer" . kill-buffer)))))
+ "It's a list of (TYPE ATTRIBUTES ...). ATTRIBUTES are the same
+ as attributes for `anything-sources'. TYPE connects the value
+ to the appropriate sources in `anything-sources'.
+
+ This allows specifying common attributes for several
+ sources. For example, sources which provide files can specify
+ common attributes with a `file' type.")
+
+
+(defvar anything-enable-digit-shortcuts nil
+ "*If t then the first nine matches can be selected using
+ Ctrl+<number>.")
+
+
+(defvar anything-candidate-number-limit 50
+ "*Do not show more candidates than this limit from inidividual
+ sources. It is usually pointless to show hundreds of matches
+ when the pattern is empty, because it is much simpler to type a
+ few characters to narrow down the list of potential candidates.
+
+ Set it to nil if you don't want this limit.")
+
+
+(defvar anything-idle-delay 0.5
+ "*The user has to be idle for this many seconds, before
+ candidates from delayed sources are collected. This is useful
+ for sources involving heavy operations (like launching external
+ programs), so that candidates from the source are not retrieved
+ unnecessarily if the user keeps typing.
+
+ It also can be used to declutter the results anything displays,
+ so that results from certain sources are not shown with every
+ character typed, only if the user hesitates a bit.")
+
+
+(defvar anything-input-idle-delay nil
+ "The user has to be idle for this many seconds, before ALL candidates are collected.
+Unlink `anything-input-idle', it is also effective for non-delayed sources.
+If nil, candidates are collected immediately. ")
+
+
+(defvar anything-samewindow nil
+ "If t then Anything doesn't pop up a new window, it uses the
+current window to show the candidates.")
+
+
+(defvar anything-source-filter nil
+ "A list of source names to be displayed. Other sources won't
+appear in the search results. If nil then there is no filtering.
+See also `anything-set-source-filter'.")
+
+
+(defvar anything-map
+ (let ((map (copy-keymap minibuffer-local-map)))
+ (define-key map (kbd "<down>") 'anything-next-line)
+ (define-key map (kbd "<up>") 'anything-previous-line)
+ (define-key map (kbd "<prior>") 'anything-previous-page)
+ (define-key map (kbd "<next>") 'anything-next-page)
+ (define-key map (kbd "<right>") 'anything-next-source)
+ (define-key map (kbd "<left>") 'anything-previous-source)
+ (define-key map (kbd "<RET>") 'anything-exit-minibuffer)
+ (define-key map (kbd "C-1") 'anything-select-with-digit-shortcut)
+ (define-key map (kbd "C-2") 'anything-select-with-digit-shortcut)
+ (define-key map (kbd "C-3") 'anything-select-with-digit-shortcut)
+ (define-key map (kbd "C-4") 'anything-select-with-digit-shortcut)
+ (define-key map (kbd "C-5") 'anything-select-with-digit-shortcut)
+ (define-key map (kbd "C-6") 'anything-select-with-digit-shortcut)
+ (define-key map (kbd "C-7") 'anything-select-with-digit-shortcut)
+ (define-key map (kbd "C-8") 'anything-select-with-digit-shortcut)
+ (define-key map (kbd "C-9") 'anything-select-with-digit-shortcut)
+ (define-key map (kbd "C-i") 'anything-select-action)
+ ;; the defalias is needed because commands are bound by name when
+ ;; using iswitchb, so only commands having the prefix anything-
+ ;; get rebound
+ (defalias 'anything-previous-history-element 'previous-history-element)
+ ;; C-p is used instead of M-p, because anything uses ESC
+ ;; (currently hardcoded) for `anything-iswitchb-cancel-anything' and
+ ;; Emacs handles ESC and Meta as synonyms, so ESC overrides
+ ;; other commands with Meta prefix.
+ ;;
+ ;; Note that iswitchb uses M-p and M-n by default for history
+ ;; navigation, so you should bind C-p and C-n in
+ ;; `iswitchb-mode-map' if you use the history keys and don't want
+ ;; to use different keys for iswitchb while anything is not yet
+ ;; kicked in. These keys are not bound automatically by anything
+ ;; in `iswitchb-mode-map' because they (C-n at least) already have
+ ;; a standard iswitchb binding which you might be accustomed to.
+ (define-key map (kbd "C-p") 'anything-previous-history-element)
+ (defalias 'anything-next-history-element 'next-history-element)
+ (define-key map (kbd "C-n") 'anything-next-history-element)
+ ;; Binding M-s is used instead of C-s, because C-s has a binding in
+ ;; iswitchb. You can rebind it, of course.
+ (define-key map (kbd "M-s") 'anything-isearch)
+ ;; unbind C-r to prevent problems during anything-isearch
+ (define-key map (kbd "C-r") nil)
+ map)
+ "Keymap for anything.")
+
+
+(defvar anything-isearch-map
+ (let ((map (copy-keymap (current-global-map))))
+ (define-key map (kbd "<return>") 'anything-isearch-default-action)
+ (define-key map (kbd "C-i") 'anything-isearch-select-action)
+ (define-key map (kbd "C-g") 'anything-isearch-cancel)
+ (define-key map (kbd "M-s") 'anything-isearch-again)
+ (define-key map (kbd "<backspace>") 'anything-isearch-delete)
+ ;; add printing chars
+ (let ((i 32))
+ (while (< i 256)
+ (define-key map (vector i) 'anything-isearch-printing-char)
+ (setq i (1+ i))))
+ map)
+ "Keymap for anything incremental search.")
+
+
+(defgroup anything nil
+ "Open anything." :prefix "anything-" :group 'convenience)
+
+(if (facep 'header-line)
+ (copy-face 'header-line 'anything-header)
+
+ (defface anything-header
+ '((t (:bold t :underline t)))
+ "Face for header lines in the anything buffer." :group 'anything))
+
+(defvar anything-header-face 'anything-header
+ "Face for header lines in the anything buffer.")
+
+(defface anything-isearch-match '((t (:background "Yellow")))
+ "Face for isearch in the anything buffer." :group 'anything)
+
+(defvar anything-isearch-match-face 'anything-isearch-match
+ "Face for matches during incremental search.")
+
+(defvar anything-iswitchb-idle-delay 1
+ "Show anything completions if the user is idle that many
+ seconds after typing.")
+
+(defvar anything-iswitchb-dont-touch-iswithcb-keys nil
+ "If t then those commands are not bound from `anything-map'
+ under iswitchb which would override standard iswithcb keys.
+
+This allows an even more seamless integration with iswitchb for
+those who prefer using iswitchb bindings even if the anything
+completions buffer is popped up.
+
+Note that you can bind alternative keys for the same command in
+`anything-map', so that you can use different keys for anything
+under iswitchb. For example, I bind the character \ to
+`anything-exit-minibuffer' which key is just above Enter on my
+keyboard. This way I can switch buffers with Enter and choose
+anything completions with \.")
+
+
+;;----------------------------------------------------------------------
+
+(defvar anything-buffer "*anything*"
+ "Buffer showing completions.")
+
+(defvar anything-action-buffer "*anything action*"
+ "Buffer showing actions.")
+
+(defvar anything-selection-overlay nil
+ "Overlay used to highlight the currently selected file.")
+
+(defvar anything-isearch-overlay nil
+ "Overlay used to highlight the current match during isearch.")
+
+(defvar anything-digit-overlays nil
+ "Overlays for digit shortcuts. See `anything-enable-digit-shortcuts'.")
+
+(defvar anything-candidate-cache nil
+ "Holds the available candidate withing a single anything invocation.")
+
+(defvar anything-pattern
+ "The input pattern used to update the anything buffer.")
+
+(defvar anything-input
+ "The input typed in the candidates panel.")
+
+(defvar anything-async-processes nil
+ "List of information about asynchronous processes managed by anything.")
+
+(defvar anything-digit-shortcut-count 0
+ "Number of digit shortcuts shown in the anything buffer.")
+
+(defvar anything-before-initialize-hook nil
+ "Run before anything initialization.
+This hook is run before init functions in `anything-sources'.")
+
+(defvar anything-after-initialize-hook nil
+ "Run after anything initialization.
+Global variables are initialized and the anything buffer is created.
+But the anything buffer has no contents. ")
+
+(defvar anything-update-hook nil
+ "Run after the anything buffer was updated according the new
+ input pattern.")
+
+(defvar anything-cleanup-hook nil
+ "Run after anything minibuffer is closed, IOW this hook is executed BEFORE performing action. ")
+
+(defvar anything-after-action-hook nil
+ "Run after executing action.")
+
+(defvar anything-after-persistent-action-hook nil
+ "Run after executing persistent action.")
+
+(defvar anything-restored-variables
+ '( anything-candidate-number-limit
+ anything-source-filter)
+ "Variables which are restored after `anything' invocation.")
+;; `anything-saved-sources' is removed
+
+(defvar anything-saved-selection nil
+ "Saved value of the currently selected object when the action
+ list is shown.")
+
+;; `anything-original-source-filter' is removed
+
+(defvar anything-candidate-separator
+ "--------------------"
+ "Candidates separator of `multiline' source.")
+
+(defvar anything-current-buffer nil
+ "Current buffer when `anything' is invoked.")
+
+(defvar anything-buffer-file-name nil
+ "`buffer-file-name' when `anything' is invoked.")
+
+(defvar anything-current-position nil
+ "Cons of (point) and (window-start) when `anything' is invoked.
+It is needed because restoring position when `anything' is keyboard-quitted.")
+
+(defvar anything-saved-action nil
+ "Saved value of the currently selected action by key.")
+
+(defvar anything-last-sources nil
+ "OBSOLETE!! Sources of previously invoked `anything'.")
+
+(defvar anything-saved-current-source nil
+ "Saved value of the original (anything-get-current-source) when the action
+ list is shown.")
+
+(defvar anything-compiled-sources nil
+ "Compiled version of `anything-sources'. ")
+
+(defvar anything-in-persistent-action nil
+ "Flag whether in persistent-action or not.")
+
+(defvar anything-quick-update nil
+ "If non-nil, suppress displaying sources which are out of screen at first.
+They are treated as delayed sources at this input.
+This flag makes `anything' a bit faster with many sources.")
+
+(defvar anything-last-sources-local nil
+ "Buffer local value of `anything-sources'.")
+(defvar anything-last-buffer nil
+ "`anything-buffer' of previously `anything' session.")
+
+(defvar anything-save-configuration-functions
+ '(set-frame-configuration . current-frame-configuration)
+ "If you hate flickering, set this variable to
+ '(set-window-configuration . current-window-configuration)
+")
+
+(put 'anything 'timid-completion 'disabled)
+
+;; (@* "Internal Variables")
+(defvar anything-test-candidate-list nil)
+(defvar anything-test-mode nil)
+(defvar anything-source-name nil)
+(defvar anything-candidate-buffer-alist nil)
+(defvar anything-check-minibuffer-input-timer nil)
+(defvar anything-match-hash (make-hash-table :test 'equal))
+(defvar anything-cib-hash (make-hash-table :test 'equal))
+(defvar anything-tick-hash (make-hash-table :test 'equal))
+
+;; (@* "Programming Tools")
+(defmacro anything-aif (test-form then-form &rest else-forms)
+ "Anaphoric if. Temporary variable `it' is the result of test-form."
+ `(let ((it ,test-form))
+ (if it ,then-form ,@else-forms)))
+(put 'anything-aif 'lisp-indent-function 2)
+
+(defun anything-mklist (obj)
+ "If OBJ is a list, return itself, otherwise make a list with one element."
+ (if (listp obj) obj (list obj)))
+
+;; (@* "Anything API")
+(defun anything-buffer-get ()
+ "If *anything action* buffer is shown, return `anything-action-buffer', otherwise `anything-buffer'."
+ (if (anything-action-window)
+ anything-action-buffer
+ anything-buffer))
+
+(defun anything-window ()
+ "Window of `anything-buffer'."
+ (get-buffer-window (anything-buffer-get) 'visible))
+
+(defun anything-action-window ()
+ "Window of `anything-action-buffer'."
+ (get-buffer-window anything-action-buffer 'visible))
+
+(defmacro with-anything-window (&rest body)
+ `(let ((--tmpfunc-- (lambda () ,@body)))
+ (if anything-test-mode
+ (with-current-buffer (anything-buffer-get)
+ (funcall --tmpfunc--))
+ (with-selected-window (anything-window)
+ (funcall --tmpfunc--)))))
+(put 'with-anything-window 'lisp-indent-function 0)
+
+(defmacro with-anything-restore-variables(&rest body)
+ "Restore variables specified by `anything-restored-variables' after executing BODY ."
+ `(let ((--orig-vars (mapcar (lambda (v) (cons v (symbol-value v))) anything-restored-variables)))
+ (unwind-protect (progn ,@body)
+ (loop for (var . value) in --orig-vars
+ do (set var value)))))
+(put 'with-anything-restore-variables 'lisp-indent-function 0)
+
+(defun* anything-attr (attribute-name &optional (src (anything-get-current-source)))
+ "Get the value of ATTRIBUTE-NAME of SRC (source).
+if SRC is omitted, use current source.
+It is useful to write your sources."
+ (anything-aif (assq attribute-name src)
+ (cdr it)))
+
+(defun* anything-attr-defined (attribute-name &optional (src (anything-get-current-source)))
+ "Return non-nil if ATTRIBUTE-NAME of SRC (source) is defined.
+if SRC is omitted, use current source.
+It is useful to write your sources."
+ (and (assq attribute-name src) t))
+
+(defun* anything-attrset (attribute-name value &optional (src (anything-get-current-source)))
+ "Set the value of ATTRIBUTE-NAME of SRC (source) to VALUE.
+if SRC is omitted, use current source.
+It is useful to write your sources."
+ (anything-aif (assq attribute-name src)
+ (setcdr it value)
+ (setcdr src (cons (cons attribute-name value) (cdr src))))
+ value)
+
+;; anything-set-source-filter
+;;
+;; This function sets a filter for anything sources and it may be
+;; called while anything is running. It can be used to toggle
+;; displaying of sources dinamically. For example, additional keys
+;; can be bound into `anything-map' to display only the file-related
+;; results if there are too many matches from other sources and
+;; you're after files only:
+;;
+;; Shift+F shows only file results from some sources:
+;;
+;; (define-key anything-map "F" 'anything-my-show-files-only)
+;;
+;; (defun anything-my-show-files-only ()
+;; (interactive)
+;; (anything-set-source-filter '("File Name History"
+;; "Files from Current Directory")))
+;;
+;; Shift+A shows all results:
+;;
+;; (define-key anything-map "A" 'anything-my-show-all)
+;;
+;; (defun anything-my-show-all ()
+;; (interactive)
+;; (anything-set-source-filter nil))
+;;
+;;
+;; Note that you have to prefix the functions with anything- prefix,
+;; otherwise they won't be bound when Anything is used under
+;; Iswitchb. The -my- part is added to avoid collisions with
+;; existing Anything function names.
+;;
+(defun anything-set-source-filter (sources)
+ "Sets the value of `anything-source-filter' and updates the list of results."
+ (setq anything-source-filter sources)
+ (anything-update))
+
+(defun anything-set-sources (sources &optional no-init no-update)
+ "Set `anything-sources' during `anything' invocation.
+If NO-INIT is non-nil, skip executing init functions of SOURCES.
+If NO-UPDATE is non-nil, skip executing `anything-update'."
+ (setq anything-compiled-sources nil
+ anything-sources sources)
+ (unless no-init (anything-funcall-foreach 'init))
+ (unless no-update (anything-update)))
+
+(defun anything-get-sources ()
+ "Return compiled `anything-sources', which is memoized.
+
+Attributes:
+
+- type
+ `anything-type-attributes' are merged in.
+- candidates-buffer
+ candidates, volatile and match attrubute are created.
+"
+ (cond
+ ;; action
+ ((anything-action-window)
+ anything-sources)
+ ;; memoized
+ (anything-compiled-sources)
+ ;; first time
+ (t
+ (setq anything-compiled-sources
+ (anything-compile-sources anything-sources anything-compile-source-functions)))))
+
+(defun* anything-get-selection (&optional (buffer anything-buffer))
+ "Return the currently selected item or nil."
+ (unless (zerop (buffer-size (get-buffer buffer)))
+ (with-current-buffer buffer
+ (let ((selection
+ (or (get-text-property (overlay-start
+ anything-selection-overlay)
+ 'anything-realvalue)
+ (buffer-substring-no-properties
+ (overlay-start anything-selection-overlay)
+ (1- (overlay-end anything-selection-overlay))))))
+ (unless (equal selection "")
+ selection)))))
+
+(defun anything-get-action ()
+ "Return the associated action for the selected candidate."
+ (unless (zerop (buffer-size (get-buffer (anything-buffer-get))))
+ (let* ((source (anything-get-current-source))
+ (actions (assoc-default 'action source)))
+
+ (anything-aif (assoc-default 'action-transformer source)
+ (funcall it actions (anything-get-selection))
+ actions))))
+
+(defun anything-get-current-source ()
+ "Return the source for the current selection / in init/candidates/action/candidate-transformer/filtered-candidate-transformer function."
+ (declare (special source))
+ ;; The name `anything-get-current-source' should be used in init function etc.
+ (if (and (boundp 'anything-source-name) (stringp anything-source-name))
+ source
+ (with-current-buffer (anything-buffer-get)
+ ;; This goto-char shouldn't be necessary, but point is moved to
+ ;; point-min somewhere else which shouldn't happen.
+ (goto-char (overlay-start anything-selection-overlay))
+ (let* ((header-pos (anything-get-previous-header-pos))
+ (source-name
+ (save-excursion
+ (assert header-pos)
+ (goto-char header-pos)
+ (buffer-substring-no-properties
+ (line-beginning-position) (line-end-position)))))
+ (some (lambda (source)
+ (if (equal (assoc-default 'name source)
+ source-name)
+ source))
+ (anything-get-sources))))))
+
+(defun anything-buffer-is-modified (buffer)
+ "Return non-nil when BUFFER is modified since `anything' was invoked."
+ (let* ((b (get-buffer buffer))
+ (key (concat (buffer-name b)
+ "/"
+ (anything-attr 'name)))
+ (source-tick (or (gethash key anything-tick-hash) 0))
+ (buffer-tick (buffer-chars-modified-tick b)))
+ (prog1 (/= source-tick buffer-tick)
+ (puthash key buffer-tick anything-tick-hash))))
+(defun anything-current-buffer-is-modified ()
+ "Return non-nil when `anything-current-buffer' is modified since `anything' was invoked."
+ (anything-buffer-is-modified anything-current-buffer))
+
+;; (@* "Core: tools")
+(defun anything-current-frame/window-configuration ()
+ (funcall (cdr anything-save-configuration-functions)))
+
+(defun anything-set-frame/window-configuration (conf)
+ (funcall (car anything-save-configuration-functions) conf))
+
+(defun anything-funcall-with-source (source func &rest args)
+ (let ((anything-source-name (assoc-default 'name source)))
+ (apply func args)))
+
+(defun anything-funcall-foreach (sym)
+ "Call the sym function(s) for each source if any."
+ (dolist (source (anything-get-sources))
+ (when (symbolp source)
+ (setq source (symbol-value source)))
+ (anything-aif (assoc-default sym source)
+ (dolist (func (if (functionp it) (list it) it))
+ (anything-funcall-with-source source func)))))
+
+(defun anything-normalize-sources (sources)
+ (cond ((and sources (symbolp sources)) (list sources))
+ (sources)
+ (t anything-sources)))
+
+(defvar anything-quit nil)
+(defmacro with-anything-quittable (&rest body)
+ `(let (inhibit-quit)
+ (condition-case v
+ (progn ,@body)
+ (quit (setq anything-quit t)
+ (exit-minibuffer)
+ (keyboard-quit)))))
+(put 'with-anything-quittable 'lisp-indent-function 0)
+
+;; (@* "Core: entry point")
+(defun anything (&optional any-sources any-input any-prompt any-resume any-preselect any-buffer)
+ "Select anything. In Lisp program, some optional arguments can be used.
+
+Note that all the optional arguments are prefixed because of
+dynamic scope problem, IOW argument variables may eat
+already-bound variables. Yuck!
+
+- ANY-SOURCES
+
+ Temporary value of `anything-sources'. ANY-SOURCES accepts a
+ symbol, interpreted as a variable of an anything source.
+
+- ANY-INPUT
+
+ Temporary value of `anything-pattern', ie. initial input of minibuffer.
+
+- ANY-PROMPT
+
+ Prompt other than \"pattern: \".
+
+- ANY-RESUME
+
+ Resurrect previously instance of `anything'. Skip the initialization.
+
+- ANY-PRESELECT
+
+ Initially selected candidate. Specified by exact candidate or a regexp.
+
+- ANY-BUFFER
+
+ `anything-buffer' instead of *anything*.
+"
+ ;; TODO more document
+ (interactive)
+ (condition-case v
+ (with-anything-restore-variables
+ (let ((frameconfig (anything-current-frame/window-configuration))
+ ;; It is needed because `anything-source-name' is non-nil
+ ;; when `anything' is invoked by action. Awful global scope.
+ anything-source-name anything-in-persistent-action
+ anything-quit
+ (anything-buffer (or any-buffer anything-buffer))
+ (anything-sources (anything-normalize-sources any-sources)))
+
+ (add-hook 'post-command-hook 'anything-check-minibuffer-input)
+
+ (setq anything-current-position (cons (point) (window-start)))
+ (if any-resume
+ (anything-initialize-overlays (anything-buffer-get))
+ (anything-initialize))
+ (setq anything-last-buffer anything-buffer)
+ (when any-input (setq anything-input any-input anything-pattern any-input))
+ (if anything-samewindow
+ (switch-to-buffer anything-buffer)
+ (pop-to-buffer anything-buffer))
+
+ (unwind-protect
+ (progn
+ (if any-resume (anything-mark-current-line) (anything-update))
+ (select-frame-set-input-focus (window-frame (minibuffer-window)))
+ (anything-preselect any-preselect)
+ (let ((minibuffer-local-map anything-map))
+ (read-string (or any-prompt "pattern: ") (if any-resume anything-pattern any-input))))
+
+ (anything-cleanup)
+ (remove-hook 'post-command-hook 'anything-check-minibuffer-input)
+ (anything-set-frame/window-configuration frameconfig))
+ (unless anything-quit
+ (unwind-protect
+ (anything-execute-selection-action)
+ (anything-aif (get-buffer anything-action-buffer)
+ (kill-buffer it))
+ (run-hooks 'anything-after-action-hook)))))
+ (quit
+ (goto-char (car anything-current-position))
+ (set-window-start (selected-window) (cdr anything-current-position))
+ nil)))
+
+(defun* anything-resume (&optional (any-buffer anything-last-buffer))
+ "Resurrect previously invoked `anything'."
+ (interactive)
+ (when current-prefix-arg
+ (setq any-buffer
+ (completing-read
+ "Resume anything buffer: "
+ (delq nil
+ (mapcar (lambda (b)
+ (when (buffer-local-value 'anything-last-sources-local b)
+ (list (buffer-name b)))) (buffer-list)))
+ nil t nil nil anything-buffer)))
+ (setq anything-compiled-sources nil)
+ (anything
+ (or (buffer-local-value 'anything-last-sources-local (get-buffer any-buffer))
+ anything-last-sources anything-sources)
+ nil nil t nil any-buffer))
+
+;; (@* "Core: initialize")
+(defun anything-initialize ()
+ "Initialize anything settings and set up the anything buffer."
+ (run-hooks 'anything-before-initialize-hook)
+ (setq anything-current-buffer (current-buffer))
+ (setq anything-buffer-file-name buffer-file-name)
+ (setq anything-compiled-sources nil)
+ (setq anything-saved-current-source nil)
+ ;; Call the init function for sources where appropriate
+ (anything-funcall-foreach 'init)
+
+ (setq anything-pattern "")
+ (setq anything-input "")
+ (setq anything-candidate-cache nil)
+ (setq anything-last-sources anything-sources)
+
+ (anything-create-anything-buffer)
+ (run-hooks 'anything-after-initialize-hook))
+
+(defun anything-create-anything-buffer (&optional test-mode)
+ "Create newly created `anything-buffer'.
+If TEST-MODE is non-nil, clear `anything-candidate-cache'."
+ (when test-mode
+ (setq anything-candidate-cache nil))
+ (with-current-buffer (get-buffer-create anything-buffer)
+ (buffer-disable-undo)
+ (erase-buffer)
+ (set (make-local-variable 'inhibit-read-only) t)
+ (set (make-local-variable 'anything-last-sources-local) anything-sources)
+ (setq cursor-type nil)
+ (setq mode-name "Anything"))
+ (anything-initialize-overlays anything-buffer)
+ (get-buffer anything-buffer))
+
+(defun anything-initialize-overlays (buffer)
+ (if anything-selection-overlay
+ ;; make sure the overlay belongs to the anything buffer if
+ ;; it's newly created
+ (move-overlay anything-selection-overlay (point-min) (point-min)
+ (get-buffer buffer))
+
+ (setq anything-selection-overlay
+ (make-overlay (point-min) (point-min) (get-buffer buffer)))
+ (overlay-put anything-selection-overlay 'face 'highlight))
+
+ (if anything-enable-digit-shortcuts
+ (unless anything-digit-overlays
+ (dotimes (i 9)
+ (push (make-overlay (point-min) (point-min)
+ (get-buffer buffer))
+ anything-digit-overlays)
+ (overlay-put (car anything-digit-overlays)
+ 'before-string (concat (int-to-string (1+ i)) " - ")))
+ (setq anything-digit-overlays (nreverse anything-digit-overlays)))
+
+ (when anything-digit-overlays
+ (dolist (overlay anything-digit-overlays)
+ (delete-overlay overlay))
+ (setq anything-digit-overlays nil))))
+
+;; (@* "Core: clean up")
+(defun anything-cleanup ()
+ "Clean up the mess."
+ (with-current-buffer anything-buffer
+ (setq cursor-type t))
+ (bury-buffer anything-buffer)
+ (anything-funcall-foreach 'cleanup)
+ (anything-kill-async-processes)
+ (run-hooks 'anything-cleanup-hook))
+
+;; (@* "Core: input handling")
+(defun anything-check-minibuffer-input ()
+ "Extract input string from the minibuffer and check if it needs
+to be handled."
+ (if (or (not anything-input-idle-delay) (anything-action-window))
+ (anything-check-minibuffer-input-1)
+ (if anything-check-minibuffer-input-timer
+ (cancel-timer anything-check-minibuffer-input-timer))
+ (setq anything-check-minibuffer-input-timer
+ (run-with-idle-timer anything-input-idle-delay nil
+ 'anything-check-minibuffer-input-1))))
+
+(defun anything-check-minibuffer-input-1 ()
+ (let (inhibit-quit)
+ (with-selected-window (minibuffer-window)
+ (anything-check-new-input (minibuffer-contents)))))
+
+
+(defun anything-check-minibuffer-input-1 ()
+ (with-anything-quittable
+ (with-selected-window (minibuffer-window)
+ (anything-check-new-input (minibuffer-contents)))))
+
+(defun anything-check-new-input (input)
+ "Check input string and update the anything buffer if
+necessary."
+ (unless (equal input anything-pattern)
+ (setq anything-pattern input)
+ (unless (anything-action-window)
+ (setq anything-input anything-pattern))
+ (anything-update)))
+
+;; (@* "Core: source compiler")
+(defvar anything-compile-source-functions
+ '(anything-compile-source--type anything-compile-source--dummy anything-compile-source--candidates-in-buffer)
+ "Functions to compile elements of `anything-sources' (plug-in).")
+(defvar anything-compile-source-functions-default anything-compile-source-functions
+ "Plug-ins this file provides.")
+(defun anything-compile-sources (sources funcs)
+ "Compile sources (`anything-sources') with funcs (`anything-compile-source-functions').
+Anything plug-ins are realized by this function."
+ (mapcar
+ (lambda (source)
+ (loop with source = (if (listp source) source (symbol-value source))
+ for f in funcs
+ do (setq source (funcall f source))
+ finally (return source)))
+ sources))
+
+;; (@* "Core: all candidates")
+(defun anything-get-candidates (source)
+ "Retrieve and return the list of candidates from
+SOURCE."
+ (let* ((candidate-source (assoc-default 'candidates source))
+ (candidates
+ (if (functionp candidate-source)
+ (anything-funcall-with-source source candidate-source)
+ (if (listp candidate-source)
+ candidate-source
+ (if (and (symbolp candidate-source)
+ (boundp candidate-source))
+ (symbol-value candidate-source)
+ (error (concat "Candidates must either be a function, "
+ " a variable or a list: %s")
+ candidate-source))))))
+ (if (processp candidates)
+ candidates
+ (anything-transform-candidates candidates source))))
+
+
+(defun anything-transform-candidates (candidates source)
+ "Transform CANDIDATES according to candidate transformers."
+ (anything-aif (assoc-default 'candidate-transformer source)
+ (anything-funcall-with-source source it candidates)
+ candidates))
+
+
+(defun anything-get-cached-candidates (source)
+ "Return the cached value of candidates for SOURCE.
+Cache the candidates if there is not yet a cached value."
+ (let* ((name (assoc-default 'name source))
+ (candidate-cache (assoc name anything-candidate-cache))
+ candidates)
+
+ (if candidate-cache
+ (setq candidates (cdr candidate-cache))
+
+ (setq candidates (anything-get-candidates source))
+
+ (if (processp candidates)
+ (progn
+ (push (cons candidates
+ (append source
+ (list (cons 'item-count 0)
+ (cons 'incomplete-line ""))))
+ anything-async-processes)
+ (set-process-filter candidates 'anything-output-filter)
+ (setq candidates nil))
+
+ (unless (assoc 'volatile source)
+ (setq candidate-cache (cons name candidates))
+ (push candidate-cache anything-candidate-cache))))
+
+ candidates))
+
+;; (@* "Core: narrowing candidates")
+(defun anything-candidate-number-limit (source)
+ "`anything-candidate-number-limit' variable may be overridden by SOURCE."
+ (or (assoc-default 'candidate-number-limit source)
+ anything-candidate-number-limit
+ 99999999))
+
+(defun anything-compute-matches (source)
+ "Compute matches from SOURCE according to its settings."
+ (let ((functions (assoc-default 'match source))
+ (limit (anything-candidate-number-limit source))
+ matches)
+ (if (or (equal anything-pattern "") (equal functions '(identity)))
+ (progn
+ (setq matches (anything-get-cached-candidates source))
+ (if (> (length matches) limit)
+ (setq matches
+ (subseq matches 0 limit))))
+
+ (condition-case nil
+ (let ((item-count 0)
+ (cands (anything-get-cached-candidates source))
+ exit)
+
+ (unless functions
+ (setq functions
+ (list (lambda (candidate)
+ (string-match anything-pattern candidate)))))
+
+ (clrhash anything-match-hash)
+ (dolist (function functions)
+ (let (newmatches)
+ (dolist (candidate cands)
+ (when (and (not (gethash candidate anything-match-hash))
+ (funcall function (if (listp candidate)
+ (car candidate)
+ candidate)))
+ (puthash candidate t anything-match-hash)
+ (push candidate newmatches)
+
+ (when limit
+ (incf item-count)
+ (when (= item-count limit)
+ (setq exit t)
+ (return)))))
+
+ (setq matches (append matches (reverse newmatches)))
+
+ (if exit
+ (return)))))
+
+ (invalid-regexp (setq matches nil))))
+
+ (anything-aif (assoc-default 'filtered-candidate-transformer source)
+ (setq matches
+ (anything-funcall-with-source source it matches source)))
+ matches))
+
+(defun anything-process-source (source)
+ "Display matches from SOURCE according to its settings."
+ (let ((matches (anything-compute-matches source)))
+ (when matches
+ (when anything-test-mode
+ (setq anything-test-candidate-list
+ `(,@anything-test-candidate-list
+ (,(assoc-default 'name source)
+ ,matches))))
+ (let ((multiline (assoc 'multiline source))
+ (start (point))
+ separate)
+ (anything-insert-header-from-source source)
+ (dolist (match matches)
+ (when (and anything-enable-digit-shortcuts
+ (not (eq anything-digit-shortcut-count 9)))
+ (move-overlay (nth anything-digit-shortcut-count
+ anything-digit-overlays)
+ (line-beginning-position)
+ (line-beginning-position))
+ (incf anything-digit-shortcut-count))
+
+ (if (and multiline separate)
+ (anything-insert-candidate-separator)
+ (setq separate t))
+ (anything-insert-match match 'insert))
+
+ (if multiline
+ (put-text-property start (point) 'anything-multiline t))))))
+
+(defun anything-process-delayed-sources (delayed-sources)
+ "Process delayed sources if the user is idle for
+`anything-idle-delay' seconds."
+ (with-anything-quittable
+ (if (sit-for (if anything-input-idle-delay
+ (max 0 (- anything-idle-delay anything-input-idle-delay))
+ anything-idle-delay))
+ (with-current-buffer anything-buffer
+ (save-excursion
+ (goto-char (point-max))
+ (dolist (source delayed-sources)
+ (anything-process-source source))
+
+ (when (and (not (equal (buffer-size) 0))
+ ;; no selection yet
+ (= (overlay-start anything-selection-overlay)
+ (overlay-end anything-selection-overlay)))
+ (goto-char (point-min))
+ (run-hooks 'anything-update-hook)
+ (anything-next-line)))
+
+ (anything-maybe-fit-frame)))))
+
+;; (@* "Core: *anything* buffer contents")
+(defun anything-update ()
+ "Update the list of matches in the anything buffer according to
+the current pattern."
+ (setq anything-digit-shortcut-count 0)
+ (anything-kill-async-processes)
+ (with-current-buffer (anything-buffer-get)
+ (erase-buffer)
+
+ (if anything-enable-digit-shortcuts
+ (dolist (overlay anything-digit-overlays)
+ (delete-overlay overlay)))
+
+ (let (delayed-sources)
+ (dolist (source (anything-get-sources))
+ (when (and (or (not anything-source-filter)
+ (member (assoc-default 'name source) anything-source-filter))
+ (>= (length anything-pattern)
+ (anything-aif (assoc 'requires-pattern source)
+ (or (cdr it) 1)
+ 0)))
+ (if (or (assoc 'delayed source)
+ (and anything-quick-update
+ (< (window-height (get-buffer-window (current-buffer)))
+ (line-number-at-pos (point-max)))))
+ (push source delayed-sources)
+ (anything-process-source source))))
+
+ (goto-char (point-min))
+ (run-hooks 'anything-update-hook)
+ (anything-next-line)
+
+ (setq delayed-sources (nreverse delayed-sources))
+ (if anything-test-mode
+ (dolist (source delayed-sources)
+ (anything-process-source source))
+ (anything-maybe-fit-frame)
+ (run-with-idle-timer (if (featurep 'xemacs)
+ 0.1
+ 0)
+ nil
+ 'anything-process-delayed-sources
+ delayed-sources)))))
+
+(defun anything-insert-match (match insert-function)
+ "Insert MATCH into the anything buffer. If MATCH is a list then
+insert the string inteneded to appear on the display and store
+the real value in a text property."
+ (let ((start (line-beginning-position (point)))
+ (string (if (listp match) (car match) match))
+ (realvalue (if (listp match) (cdr match) match)))
+ (funcall insert-function string)
+ ;; Some sources with candidates-in-buffer have already added
+ ;; 'anything-realvalue property when creating candidate buffer.
+ (unless (get-text-property start 'anything-realvalue)
+ (put-text-property start (line-end-position)
+ 'anything-realvalue realvalue)))
+ (funcall insert-function "\n"))
+
+(defun anything-insert-header-from-source (source)
+ (let ((name (assoc-default 'name source)))
+ (anything-insert-header name
+ (anything-aif (assoc-default 'header-name source)
+ (funcall it name)))))
+
+(defun anything-insert-header (name &optional display-string)
+ "Insert header of source NAME into the anything buffer."
+ (unless (bobp)
+ (let ((start (point)))
+ (insert "\n")
+ (put-text-property start (point) 'anything-header-separator t)))
+
+ (let ((start (point)))
+ (insert name)
+ (put-text-property (line-beginning-position)
+ (line-end-position) 'anything-header t)
+ (when display-string
+ (overlay-put (make-overlay (line-beginning-position) (line-end-position))
+ 'display display-string))
+ (insert "\n")
+ (put-text-property start (point) 'face anything-header-face)))
+
+
+(defun anything-insert-candidate-separator ()
+ "Insert separator of candidates into the anything buffer."
+ (insert anything-candidate-separator)
+ (put-text-property (line-beginning-position)
+ (line-end-position) 'anything-candidate-separator t)
+ (insert "\n"))
+
+
+
+
+;; (@* "Core: async process")
+(defun anything-output-filter (process string)
+ "Process output from PROCESS."
+ (let* ((process-assoc (assoc process anything-async-processes))
+ (process-info (cdr process-assoc))
+ (insertion-marker (assoc-default 'insertion-marker process-info))
+ (incomplete-line-info (assoc 'incomplete-line process-info))
+ (item-count-info (assoc 'item-count process-info)))
+
+ (with-current-buffer anything-buffer
+ (save-excursion
+ (if insertion-marker
+ (goto-char insertion-marker)
+
+ (goto-char (point-max))
+ (anything-insert-header-from-source process-info)
+ (setcdr process-assoc
+ (append process-info `((insertion-marker . ,(point-marker))))))
+
+ (let ((lines (split-string string "\n"))
+ candidates)
+ (while lines
+ (if (not (cdr lines))
+ ;; store last incomplete line until new output arrives
+ (setcdr incomplete-line-info (car lines))
+
+ (if (cdr incomplete-line-info)
+ (progn
+ (push (concat (cdr incomplete-line-info) (car lines))
+ candidates)
+ (setcdr incomplete-line-info nil))
+
+ (push (car lines) candidates)))
+
+ (pop lines))
+
+ (setq candidates (reverse candidates))
+ (dolist (candidate (anything-transform-candidates candidates process-info))
+ (anything-insert-match candidate 'insert-before-markers)
+ (incf (cdr item-count-info))
+ (when (>= (cdr item-count-info) anything-candidate-number-limit)
+ (anything-kill-async-process process)
+ (return)))))
+
+ (anything-maybe-fit-frame)
+
+ (run-hooks 'anything-update-hook)
+
+ (if (bobp)
+ (anything-next-line)
+
+ (save-selected-window
+ (select-window (get-buffer-window anything-buffer 'visible))
+ (anything-mark-current-line))))))
+
+
+(defun anything-kill-async-processes ()
+ "Kill all known asynchronous processes according to
+`anything-async-processes'."
+ "Kill locate process."
+ (dolist (process-info anything-async-processes)
+ (anything-kill-async-process (car process-info)))
+ (setq anything-async-processes nil))
+
+
+(defun anything-kill-async-process (process)
+ "Kill PROCESS and detach the associated functions."
+ (set-process-filter process nil)
+ (delete-process process))
+
+
+;; (@* "Core: action")
+(defun anything-execute-selection-action (&optional selection action clear-saved-action display-to-real)
+ "If a candidate was selected then perform the associated
+action."
+ (setq selection (or selection (anything-get-selection)))
+ (setq action (or action
+ anything-saved-action
+ (if (get-buffer anything-action-buffer)
+ (anything-get-selection anything-action-buffer)
+ (anything-get-action))))
+ (let ((source (or anything-saved-current-source (anything-get-current-source))))
+ (if (and (not selection) (assoc 'accept-empty source))
+ (setq selection ""))
+ (setq display-to-real
+ (or display-to-real (assoc-default 'display-to-real source)
+ #'identity))
+ (if (and (listp action)
+ (not (functionp action))) ; lambda
+ ;;select the default action
+ (setq action (cdar action)))
+ (unless clear-saved-action (setq anything-saved-action nil))
+ (if (and selection action)
+ (anything-funcall-with-source
+ source action
+ (anything-funcall-with-source source display-to-real selection)))))
+
+(defun anything-select-action ()
+ "Select an action for the currently selected candidate.
+If action buffer is selected, back to the anything buffer."
+ (interactive)
+ (cond ((get-buffer-window anything-action-buffer 'visible)
+ (set-window-buffer (get-buffer-window anything-action-buffer) anything-buffer)
+ (kill-buffer anything-action-buffer))
+ (t
+ (setq anything-saved-selection (anything-get-selection))
+ (unless anything-saved-selection
+ (error "Nothing is selected."))
+ (setq anything-saved-current-source (anything-get-current-source))
+ (let ((actions (anything-get-action)))
+ (if (functionp actions)
+ (message "Sole action: %s" actions)
+ (with-current-buffer (get-buffer-create anything-action-buffer)
+ (erase-buffer)
+ (buffer-disable-undo)
+ (set-window-buffer (get-buffer-window anything-buffer) anything-action-buffer)
+ (set (make-local-variable 'anything-sources)
+ `(((name . "Actions")
+ (candidates . ,actions))))
+ (set (make-local-variable 'anything-source-filter) nil)
+ (set (make-local-variable 'anything-selection-overlay) nil)
+ (set (make-local-variable 'anything-digit-overlays) nil)
+ (anything-initialize-overlays anything-action-buffer))
+ (with-selected-window (minibuffer-window)
+ (delete-minibuffer-contents))
+ (setq anything-pattern 'dummy) ; so that it differs from the
+ ; previous one
+
+ (anything-check-minibuffer-input))))))
+
+;; (@* "Core: selection")
+(defun anything-previous-line ()
+ "Move selection to the previous line."
+ (interactive)
+ (anything-move-selection 'line 'previous))
+
+(defun anything-next-line ()
+ "Move selection to the next line."
+ (interactive)
+ (anything-move-selection 'line 'next))
+
+(defun anything-previous-page ()
+ "Move selection back with a pageful."
+ (interactive)
+ (anything-move-selection 'page 'previous))
+
+(defun anything-next-page ()
+ "Move selection forward with a pageful."
+ (interactive)
+ (anything-move-selection 'page 'next))
+
+
+(defun anything-previous-source ()
+ "Move selection to the previous source."
+ (interactive)
+ (anything-move-selection 'source 'previous))
+
+
+(defun anything-next-source ()
+ "Move selection to the next source."
+ (interactive)
+ (anything-move-selection 'source 'next))
+
+
+(defun anything-move-selection (unit direction)
+ "Move the selection marker to a new position determined by
+UNIT and DIRECTION."
+ (unless (or (zerop (buffer-size (get-buffer (anything-buffer-get))))
+ (not (anything-window)))
+ (with-anything-window
+ (case unit
+ (line (case direction
+ (next (if (not (anything-pos-multiline-p))
+ (forward-line 1)
+ (let ((header-pos (anything-get-next-header-pos))
+ (candidate-pos (anything-get-next-candidate-separator-pos)))
+ (if (and candidate-pos
+ (or (null header-pos)
+ (< candidate-pos header-pos)))
+ (goto-char candidate-pos)
+ (if header-pos
+ (goto-char header-pos)))
+ (if candidate-pos
+ (forward-line 1)))))
+
+ (previous (progn
+ (forward-line -1)
+ (when (anything-pos-multiline-p)
+ (if (or (anything-pos-header-line-p)
+ (anything-pos-candidate-separator-p))
+ (forward-line -1)
+ (forward-line 1))
+ (let ((header-pos (anything-get-previous-header-pos))
+ (candidate-pos (anything-get-previous-candidate-separator-pos)))
+ (when header-pos
+ (if (or (null candidate-pos) (< candidate-pos header-pos))
+ (goto-char header-pos)
+ (goto-char candidate-pos))
+ (forward-line 1))))))
+
+ (t (error "Invalid direction."))))
+
+ (page (case direction
+ (next (condition-case nil
+ (scroll-up)
+ (end-of-buffer (goto-char (point-max)))))
+ (previous (condition-case nil
+ (scroll-down)
+ (beginning-of-buffer (goto-char (point-min)))))
+ (t (error "Invalid direction."))))
+
+ (source (case direction
+ (next (goto-char (or (anything-get-next-header-pos)
+ (point-min))))
+ (previous (progn
+ (forward-line -1)
+ (if (bobp)
+ (goto-char (point-max))
+ (if (anything-pos-header-line-p)
+ (forward-line -1)
+ (forward-line 1)))
+ (goto-char (anything-get-previous-header-pos))
+ (forward-line 1)))
+ (t (error "Invalid direction."))))
+
+ (t (error "Invalid unit.")))
+
+ (while (and (not (bobp))
+ (or (anything-pos-header-line-p)
+ (anything-pos-candidate-separator-p)))
+ (forward-line (if (and (eq direction 'previous)
+ (not (eq (line-beginning-position)
+ (point-min))))
+ -1
+ 1)))
+ (if (bobp)
+ (forward-line 1))
+ (if (eobp)
+ (forward-line -1))
+
+ (anything-mark-current-line))))
+
+
+(defun anything-mark-current-line ()
+ "Move selection overlay to current line."
+ (move-overlay anything-selection-overlay
+ (line-beginning-position)
+ (if (anything-pos-multiline-p)
+ (let ((header-pos (anything-get-next-header-pos))
+ (candidate-pos (anything-get-next-candidate-separator-pos)))
+ (or (and (null header-pos) candidate-pos candidate-pos)
+ (and header-pos candidate-pos (< candidate-pos header-pos) candidate-pos)
+ header-pos
+ (point-max)))
+ (1+ (line-end-position)))))
+
+
+(defun anything-select-with-digit-shortcut ()
+ (interactive)
+ (if anything-enable-digit-shortcuts
+ (save-selected-window
+ (select-window (anything-window))
+ (let* ((index (- (event-basic-type (elt (this-command-keys-vector) 0)) ?1))
+ (overlay (nth index anything-digit-overlays)))
+ (when (overlay-buffer overlay)
+ (goto-char (overlay-start overlay))
+ (anything-mark-current-line)
+ (anything-exit-minibuffer))))))
+
+
+(defun anything-exit-minibuffer ()
+ "Select the current candidate by exiting the minibuffer."
+ (interactive)
+ (declare (special anything-iswitchb-candidate-selected))
+ (setq anything-iswitchb-candidate-selected (anything-get-selection))
+ (exit-minibuffer))
+
+
+(defun anything-get-next-header-pos ()
+ "Return the position of the next header from point."
+ (next-single-property-change (point) 'anything-header))
+
+
+(defun anything-get-previous-header-pos ()
+ "Return the position of the previous header from point"
+ (previous-single-property-change (point) 'anything-header))
+
+
+(defun anything-pos-multiline-p ()
+ "Return non-nil if the current position is in the multiline source region."
+ (get-text-property (point) 'anything-multiline))
+
+
+(defun anything-get-next-candidate-separator-pos ()
+ "Return the position of the next candidate separator from point."
+ (next-single-property-change (point) 'anything-candidate-separator))
+
+
+(defun anything-get-previous-candidate-separator-pos ()
+ "Return the position of the previous candidate separator from point."
+ (previous-single-property-change (point) 'anything-candidate-separator))
+
+
+(defun anything-pos-header-line-p ()
+ "Return t if the current line is a header line."
+ (or (get-text-property (line-beginning-position) 'anything-header)
+ (get-text-property (line-beginning-position) 'anything-header-separator)))
+
+(defun anything-pos-candidate-separator-p ()
+ "Return t if the current line is a candidate separator."
+ (get-text-property (line-beginning-position) 'anything-candidate-separator))
+
+;; (@* "Core: misc")
+(defun anything-kill-buffer-hook ()
+ "Remove tick entry from `anything-tick-hash' when killing a buffer."
+ (loop for key being the hash-keys in anything-tick-hash
+ if (string-match (format "^%s/" (regexp-quote (buffer-name))) key)
+ do (remhash key anything-tick-hash)))
+(add-hook 'kill-buffer-hook 'anything-kill-buffer-hook)
+
+(defun anything-maybe-fit-frame ()
+ "Fit anything frame to its buffer, and put it at top right of display.
+ To inhibit fitting, set `fit-frame-inhibit-fitting-flag' to t.
+ You can set user options `fit-frame-max-width-percent' and
+ `fit-frame-max-height-percent' to control max frame size."
+ (declare (warn (unresolved 0)))
+ (when (and (require 'fit-frame nil t)
+ (boundp 'fit-frame-inhibit-fitting-flag)
+ (not fit-frame-inhibit-fitting-flag)
+ (anything-window))
+ (with-anything-window
+ (fit-frame nil nil nil t)
+ (modify-frame-parameters
+ (selected-frame)
+ `((left . ,(- (x-display-pixel-width) (+ (frame-pixel-width) 7)))
+ (top . 0)))))) ; The (top . 0) shouldn't be necessary (Emacs bug).
+
+(defun anything-preselect (candidate-or-regexp)
+ (when candidate-or-regexp
+ (with-anything-window
+ (goto-char (point-min))
+ ;; go to first candidate of first source
+ (forward-line 1)
+ (let ((start (point)))
+ (unless (or (re-search-forward (concat "^" (regexp-quote candidate-or-regexp) "$") nil t)
+ (progn (goto-char start)
+ (re-search-forward candidate-or-regexp nil t)))
+ (goto-char start))
+ (anything-mark-current-line)))))
+
+(defun anything-delete-current-selection ()
+ "Delete the currently selected item."
+ (interactive)
+ (with-anything-window
+ (cond ((anything-pos-multiline-p)
+ (anything-aif (anything-get-next-candidate-separator-pos)
+ (delete-region (point-at-bol)
+ (1+ (progn (goto-char it) (point-at-eol))))
+ ;; last candidate
+ (goto-char (anything-get-previous-candidate-separator-pos))
+ (delete-region (point-at-bol) (point-max)))
+ (when (eobp)
+ (goto-char (or (anything-get-previous-candidate-separator-pos)
+ (point-min)))
+ (forward-line 1)))
+ (t
+ (delete-region (point-at-bol) (1+ (point-at-eol)))
+ (when (eobp) (forward-line -1))))
+ (anything-mark-current-line)))
+
+;; (@* "Built-in plug-in: type")
+(defun anything-compile-source--type (source)
+ (anything-aif (assoc-default 'type source)
+ (append source (assoc-default it anything-type-attributes) nil)
+ source))
+
+;; (@* "Built-in plug-in: dummy")
+(defun anything-dummy-candidate (candidate source)
+ ;; `source' is defined in filtered-candidate-transformer
+ (list anything-pattern))
+
+(defun anything-compile-source--dummy (source)
+ (if (assoc 'dummy source)
+ (append '((candidates "dummy")
+ (accept-empty)
+ (match identity)
+ (filtered-candidate-transformer . anything-dummy-candidate)
+ (volatile))
+ source)
+ source))
+
+;; (@* "Built-in plug-in: candidates-in-buffer")
+(defun anything-candidates-in-buffer ()
+ "Get candidates from the candidates buffer according to `anything-pattern'.
+
+BUFFER is `anything-candidate-buffer' by default. Each
+candidate must be placed in one line. This function is meant to
+be used in candidates-in-buffer or candidates attribute of an
+anything source. Especially fast for many (1000+) candidates.
+
+eg.
+ '((name . \"many files\")
+ (init . (lambda () (with-current-buffer (anything-candidate-buffer 'local)
+ (insert-many-filenames))))
+ (search re-search-forward) ; optional
+ (candidates-in-buffer)
+ (type . file))
+
++===============================================================+
+| The new way of making and narrowing candidates: Using buffers |
++===============================================================+
+
+By default, `anything' makes candidates by evaluating the
+candidates function, then narrows them by `string-match' for each
+candidate.
+
+But this way is very slow for many candidates. The new way is
+storing all candidates in a buffer and narrowing them by
+`re-search-forward'. Search function is customizable by search
+attribute. The important point is that buffer processing is MUCH
+FASTER than string list processing and is the Emacs way.
+
+The init function writes all candidates to a newly-created
+candidate buffer. The candidates buffer is created or specified
+by `anything-candidate-buffer'. Candidates are stored in a line.
+
+The candidates function narrows all candidates, IOW creates a
+subset of candidates dynamically. It is the task of
+`anything-candidates-in-buffer'. As long as
+`anything-candidate-buffer' is used,`(candidates-in-buffer)' is
+sufficient in most cases.
+
+Note that `(candidates-in-buffer)' is shortcut of three attributes:
+ (candidates . anything-candidates-in-buffer)
+ (volatile)
+ (match identity)
+And `(candidates-in-buffer . func)' is shortcut of three attributes:
+ (candidates . func)
+ (volatile)
+ (match identity)
+The expansion is performed in `anything-get-sources'.
+
+The candidates-in-buffer attribute implies the volatile attribute.
+The volatile attribute is needed because `anything-candidates-in-buffer'
+creates candidates dynamically and need to be called everytime
+`anything-pattern' changes.
+
+Because `anything-candidates-in-buffer' plays the role of `match' attribute
+function, specifying `(match identity)' makes the source slightly faster.
+
+To customize `anything-candidates-in-buffer' behavior, use search,
+get-line and search-from-end attributes. See also `anything-sources' docstring.
+"
+ (declare (special source))
+ (anything-candidates-in-buffer-1 (anything-candidate-buffer)
+ anything-pattern
+ (or (assoc-default 'get-line source)
+ #'buffer-substring-no-properties)
+ ;; use external variable `source'.
+ (or (assoc-default 'search source)
+ (if (assoc 'search-from-end source)
+ '(re-search-backward)
+ '(re-search-forward)))
+ (anything-candidate-number-limit source)
+ (assoc 'search-from-end source)))
+
+(defun* anything-candidates-in-buffer-1 (buffer &optional (pattern anything-pattern) (get-line-fn 'buffer-substring-no-properties) (search-fns '(re-search-forward)) (limit anything-candidate-number-limit) search-from-end)
+ ;; buffer == nil when candidates buffer does not exist.
+ (when buffer
+ (with-current-buffer buffer
+ (let ((start-point (if search-from-end (point-max) (point-min)))
+ (next-line-fn (if search-from-end
+ (lambda (x) (goto-char (max (1- (point-at-bol)) 1)))
+ #'forward-line))
+ (endp (if search-from-end #'bobp #'eobp)))
+ (goto-char (1- start-point))
+ (if (string= pattern "")
+ (delq nil (loop until (funcall endp)
+ for i from 1 to limit
+ collecting (funcall get-line-fn (point-at-bol) (point-at-eol))
+ do (funcall next-line-fn 1)))
+
+ (let ((i 1)
+ (next-line-fn (if search-from-end
+ (lambda (x) (goto-char (max (point-at-bol) 1)))
+ #'forward-line))
+ buffer-read-only
+ matches exit newmatches)
+ (progn
+ (goto-char (point-min))
+ (insert "\n")
+ (goto-char (point-max))
+ (insert "\n")
+ (setq start-point (if search-from-end (point-max) (point-min)))
+ (clrhash anything-cib-hash)
+ (unwind-protect
+ (dolist (searcher search-fns)
+ (goto-char start-point)
+ (setq newmatches nil)
+ (loop while (funcall searcher pattern nil t)
+ if (or (funcall endp) (< limit i))
+ do (setq exit t) (return)
+ else do
+ (let ((cand (funcall get-line-fn (point-at-bol) (point-at-eol))))
+ (unless (gethash cand anything-cib-hash)
+ (puthash cand t anything-cib-hash)
+ (incf i)
+ (push cand newmatches)))
+ (funcall next-line-fn 1))
+ (setq matches (append matches (nreverse newmatches)))
+ (if exit (return)))
+ (goto-char (point-min))
+ (delete-char 1)
+ (goto-char (1- (point-max)))
+ (delete-char 1)
+
+ (set-buffer-modified-p nil)))
+ (delq nil matches)))))))
+
+
+(defun anything-candidate-buffer (&optional create-or-buffer)
+ "Register and return a buffer containing candidates of current source.
+`anything-candidate-buffer' searches buffer-local candidates buffer first,
+then global candidates buffer.
+
+Acceptable values of CREATE-OR-BUFFER:
+
+- nil (omit)
+ Only return the candidates buffer.
+- a buffer
+ Register a buffer as a candidates buffer.
+- 'global
+ Create a new global candidates buffer,
+ named \" *anything candidates:SOURCE*\".
+- other non-nil value
+ Create a new global candidates buffer,
+ named \" *anything candidates:SOURCE*ANYTHING-CURRENT-BUFFER\".
+"
+ (let* ((gbufname (format " *anything candidates:%s*" anything-source-name))
+ (lbufname (concat gbufname (buffer-name anything-current-buffer)))
+ buf)
+ (when create-or-buffer
+ (if (bufferp create-or-buffer)
+ (add-to-list 'anything-candidate-buffer-alist
+ (cons anything-source-name create-or-buffer))
+ (when (eq create-or-buffer 'global)
+ (loop for b in (buffer-list)
+ if (string-match (format "^%s" (regexp-quote gbufname)) (buffer-name b))
+ do (kill-buffer b)))
+ (with-current-buffer
+ (get-buffer-create (if (eq create-or-buffer 'global) gbufname lbufname))
+ (buffer-disable-undo)
+ (erase-buffer)
+ (font-lock-mode -1))))
+ (or (get-buffer lbufname)
+ (get-buffer gbufname)
+ (anything-aif (assoc-default anything-source-name anything-candidate-buffer-alist)
+ (and (buffer-live-p it) it)))))
+
+(defun anything-compile-source--candidates-in-buffer (source)
+ (anything-aif (assoc 'candidates-in-buffer source)
+ (append source `((candidates . ,(or (cdr it) 'anything-candidates-in-buffer))
+ (volatile) (match identity)))
+ source))
+
+;; (@* "Utility: select another action by key")
+(defun anything-select-nth-action (n)
+ "Select the nth action for the currently selected candidate."
+ (setq anything-saved-selection (anything-get-selection))
+ (unless anything-saved-selection
+ (error "Nothing is selected."))
+ (setq anything-saved-action (cdr (elt (anything-get-action) n)))
+ (anything-exit-minibuffer))
+
+(defun anything-select-2nd-action ()
+ "Select the 2nd action for the currently selected candidate."
+ (interactive)
+ (anything-select-nth-action 1))
+
+(defun anything-select-3rd-action ()
+ "Select the 3rd action for the currently selected candidate."
+ (interactive)
+ (anything-select-nth-action 2))
+
+(defun anything-select-4th-action ()
+ "Select the 4th action for the currently selected candidate."
+ (interactive)
+ (anything-select-nth-action 3))
+
+
+;; (@* "Utility: Persistent Action")
+(defun* anything-execute-persistent-action (&optional (attr 'persistent-action))
+ "If a candidate is selected then perform the associated action without quitting anything."
+ (interactive)
+ (save-selected-window
+ (select-window (get-buffer-window (anything-buffer-get)))
+ (select-window (setq minibuffer-scroll-window
+ (if (one-window-p t) (split-window)
+ (next-window (selected-window) 1))))
+ (let ((anything-in-persistent-action t))
+ (with-anything-display-same-window
+ (anything-execute-selection-action
+ nil
+ (or (assoc-default attr (anything-get-current-source))
+ (anything-get-action))
+ t)
+ (run-hooks 'anything-after-persistent-action-hook)))))
+
+(defmacro with-anything-display-same-window (&rest body)
+ "Make `pop-to-buffer' and `display-buffer' display in the same window."
+ `(let ((same-window-regexps '("."))
+ (pop-up-windows nil)
+ (display-buffer-function nil))
+ ,@body))
+(put 'with-anything-display-same-window 'lisp-indent-function 0)
+
+;; scroll-other-window(-down)? for persistent-action
+(defun anything-scroll-other-window-base (command)
+ (save-selected-window
+ (other-window 2)
+ (call-interactively command)))
+
+(defun anything-scroll-other-window ()
+ "Scroll other window (not *Anything* window) upward."
+ (interactive)
+ (anything-scroll-other-window-base 'scroll-other-window))
+(defun anything-scroll-other-window-down ()
+ "Scroll other window (not *Anything* window) downward."
+ (interactive)
+ (anything-scroll-other-window-base 'scroll-other-window-down))
+
+;; (@* "Utility: Incremental search within results")
+
+(defvar anything-isearch-original-global-map nil
+ "Original global map before Anything isearch is started.")
+
+(defvar anything-isearch-original-message-timeout nil
+ "Original message timeout before Anything isearch is started.")
+
+(defvar anything-isearch-pattern nil
+ "The current isearch pattern.")
+
+(defvar anything-isearch-message-suffix ""
+ "Message suffix indicating the current state of the search.")
+
+(defvar anything-isearch-original-point nil
+ "Original position of point before isearch is started.")
+
+(defvar anything-isearch-original-window nil
+ "Original selected window before isearch is started.")
+
+(defvar anything-isearch-original-cursor-in-non-selected-windows nil
+ "Original value of cursor-in-non-selected-windows before isearch is started.")
+
+(defvar anything-isearch-original-post-command-hook nil
+ "Original value of post-command-hook before isearch is started.")
+
+(defvar anything-isearch-match-positions nil
+ "Stack of positions of matches or non-matches.
+
+It's a list of plists with two properties: `event', the last user
+ event, `start', the start position of the current match, and
+ `pos', the position of point after that event.
+
+The value of `event' can be the following symbols: `char' if a
+character was typed, `error' if a non-matching character was
+typed, `search' if a forward search had to be done after a
+character, and `search-again' if a search was done for the next
+occurrence of the current pattern.")
+
+(defvar anything-isearch-match-start nil
+ "Start position of the current match.")
+
+
+(defun anything-isearch ()
+ "Start incremental search within results."
+ (interactive)
+ (if (zerop (buffer-size (get-buffer (anything-buffer-get))))
+ (message "There are no results.")
+
+ (setq anything-isearch-original-message-timeout minibuffer-message-timeout)
+ (setq minibuffer-message-timeout nil)
+
+ (setq anything-isearch-original-global-map global-map)
+
+ (condition-case nil
+ (progn
+ (setq anything-isearch-original-window (selected-window))
+ (select-window (anything-window))
+ (setq cursor-type t)
+
+ (setq anything-isearch-original-post-command-hook
+ (default-value 'post-command-hook))
+ (setq-default post-command-hook nil)
+ (add-hook 'post-command-hook 'anything-isearch-post-command)
+
+ (use-global-map anything-isearch-map)
+ (setq overriding-terminal-local-map anything-isearch-map)
+
+ (setq anything-isearch-pattern "")
+
+ (setq anything-isearch-original-cursor-in-non-selected-windows
+ cursor-in-non-selected-windows)
+ (setq cursor-in-non-selected-windows nil)
+
+ (setq anything-isearch-original-point (point-marker))
+ (goto-char (point-min))
+ (forward-line)
+ (anything-mark-current-line)
+
+ (setq anything-isearch-match-positions nil)
+ (setq anything-isearch-match-start (point-marker))
+
+ (if anything-isearch-overlay
+ ;; make sure the overlay belongs to the anything buffer
+ (move-overlay anything-isearch-overlay (point-min) (point-min)
+ (get-buffer (anything-buffer-get)))
+
+ (setq anything-isearch-overlay (make-overlay (point-min) (point-min)))
+ (overlay-put anything-isearch-overlay 'face anything-isearch-match-face))
+
+ (setq anything-isearch-message-suffix
+ (substitute-command-keys "cancel with \\[anything-isearch-cancel]")))
+
+ (error (anything-isearch-cleanup)))))
+
+
+(defun anything-isearch-post-command ()
+ "Print the current pattern after every command."
+ (anything-isearch-message)
+ (when (anything-window)
+ (with-anything-window
+ (move-overlay anything-isearch-overlay anything-isearch-match-start (point)
+ (get-buffer (anything-buffer-get))))))
+
+
+(defun anything-isearch-printing-char ()
+ "Add printing char to the pattern."
+ (interactive)
+ (let ((char (char-to-string last-command-char)))
+ (setq anything-isearch-pattern (concat anything-isearch-pattern char))
+
+ (with-anything-window
+ (if (looking-at char)
+ (progn
+ (push (list 'event 'char
+ 'start anything-isearch-match-start
+ 'pos (point-marker))
+ anything-isearch-match-positions)
+ (forward-char))
+
+ (let ((start (point)))
+ (while (and (re-search-forward anything-isearch-pattern nil t)
+ (anything-pos-header-line-p)))
+ (if (or (anything-pos-header-line-p)
+ (eq start (point)))
+ (progn
+ (goto-char start)
+ (push (list 'event 'error
+ 'start anything-isearch-match-start
+ 'pos (point-marker))
+ anything-isearch-match-positions))
+
+ (push (list 'event 'search
+ 'start anything-isearch-match-start
+ 'pos (copy-marker start))
+ anything-isearch-match-positions)
+ (setq anything-isearch-match-start (copy-marker (match-beginning 0))))))
+
+ (anything-mark-current-line))))
+
+
+(defun anything-isearch-again ()
+ "Search again for the current pattern"
+ (interactive)
+ (if (equal anything-isearch-pattern "")
+ (setq anything-isearch-message-suffix "no pattern yet")
+
+ (with-anything-window
+ (let ((start (point)))
+ (while (and (re-search-forward anything-isearch-pattern nil t)
+ (anything-pos-header-line-p)))
+ (if (or (anything-pos-header-line-p)
+ (eq start (point)))
+ (progn
+ (goto-char start)
+ (unless (eq 'error (plist-get (car anything-isearch-match-positions)
+ 'event))
+ (setq anything-isearch-message-suffix "no more matches")))
+
+ (push (list 'event 'search-again
+ 'start anything-isearch-match-start
+ 'pos (copy-marker start))
+ anything-isearch-match-positions)
+ (setq anything-isearch-match-start (copy-marker (match-beginning 0)))
+
+ (anything-mark-current-line))))))
+
+
+(defun anything-isearch-delete ()
+ "Undo last event."
+ (interactive)
+ (unless (equal anything-isearch-pattern "")
+ (let ((last (pop anything-isearch-match-positions)))
+ (unless (eq 'search-again (plist-get last 'event))
+ (setq anything-isearch-pattern
+ (substring anything-isearch-pattern 0 -1)))
+
+ (with-anything-window
+ (goto-char (plist-get last 'pos))
+ (setq anything-isearch-match-start (plist-get last 'start))
+ (anything-mark-current-line)))))
+
+
+(defun anything-isearch-default-action ()
+ "Execute the default action for the selected candidate."
+ (interactive)
+ (anything-isearch-cleanup)
+ (with-current-buffer (anything-buffer-get) (anything-exit-minibuffer)))
+
+
+(defun anything-isearch-select-action ()
+ "Choose an action for the selected candidate."
+ (interactive)
+ (anything-isearch-cleanup)
+ (with-anything-window
+ (anything-select-action)))
+
+
+(defun anything-isearch-cancel ()
+ "Cancel Anything isearch."
+ (interactive)
+ (anything-isearch-cleanup)
+ (when (anything-window)
+ (with-anything-window
+ (goto-char anything-isearch-original-point)
+ (anything-mark-current-line))))
+
+
+(defun anything-isearch-cleanup ()
+ "Clean up the mess."
+ (setq minibuffer-message-timeout anything-isearch-original-message-timeout)
+ (with-current-buffer (anything-buffer-get)
+ (setq overriding-terminal-local-map nil)
+ (setq cursor-type nil)
+ (setq cursor-in-non-selected-windows
+ anything-isearch-original-cursor-in-non-selected-windows))
+ (when anything-isearch-original-window
+ (select-window anything-isearch-original-window))
+
+ (use-global-map anything-isearch-original-global-map)
+ (setq-default post-command-hook anything-isearch-original-post-command-hook)
+ (when (overlayp anything-isearch-overlay)
+ (delete-overlay anything-isearch-overlay)))
+
+
+(defun anything-isearch-message ()
+ "Print prompt."
+ (if (and (equal anything-isearch-message-suffix "")
+ (eq (plist-get (car anything-isearch-match-positions) 'event)
+ 'error))
+ (setq anything-isearch-message-suffix "failing"))
+
+ (unless (equal anything-isearch-message-suffix "")
+ (setq anything-isearch-message-suffix
+ (concat " [" anything-isearch-message-suffix "]")))
+
+ (message (concat "Search within results: "
+ anything-isearch-pattern
+ anything-isearch-message-suffix))
+
+ (setq anything-isearch-message-suffix ""))
+
+
+;; (@* "Utility: Iswitchb integration")
+
+(defvar anything-iswitchb-candidate-selected nil
+ "Indicates whether an anything candidate is selected from iswitchb.")
+
+(defvar anything-iswitchb-frame-configuration nil
+ "Saved frame configuration, before anything buffer was displayed.")
+
+(defvar anything-iswitchb-saved-keys nil
+ "The original in iswitchb before binding anything keys.")
+
+
+(defun anything-iswitchb-setup ()
+ "Integrate anything completion into iswitchb.
+
+If the user is idle for `anything-iswitchb-idle-delay' seconds
+after typing something into iswitchb then anything candidates are
+shown for the current iswitchb input.
+
+ESC cancels anything completion and returns to normal iswitchb."
+ (interactive)
+
+ (require 'iswitchb)
+
+ ;; disable timid completion during iswitchb
+ (put 'iswitchb-buffer 'timid-completion 'disabled)
+ (add-hook 'minibuffer-setup-hook 'anything-iswitchb-minibuffer-setup)
+
+ (defadvice iswitchb-visit-buffer
+ (around anything-iswitchb-visit-buffer activate)
+ (if anything-iswitchb-candidate-selected
+ (anything-execute-selection-action)
+ ad-do-it))
+
+ (defadvice iswitchb-possible-new-buffer
+ (around anything-iswitchb-possible-new-buffer activate)
+ (if anything-iswitchb-candidate-selected
+ (anything-execute-selection-action)
+ ad-do-it))
+
+ (message "Iswitchb integration is activated."))
+
+
+(defun anything-iswitchb-minibuffer-setup ()
+ (when (eq this-command 'iswitchb-buffer)
+ (add-hook 'minibuffer-exit-hook 'anything-iswitchb-minibuffer-exit)
+
+ (setq anything-iswitchb-frame-configuration nil)
+ (setq anything-iswitchb-candidate-selected nil)
+ (add-hook 'anything-update-hook 'anything-iswitchb-handle-update)
+
+ (anything-initialize)
+
+ (add-hook 'post-command-hook 'anything-iswitchb-check-input)))
+
+
+(defun anything-iswitchb-minibuffer-exit ()
+ (remove-hook 'minibuffer-exit-hook 'anything-iswitchb-minibuffer-exit)
+ (remove-hook 'post-command-hook 'anything-iswitchb-check-input)
+ (remove-hook 'anything-update-hook 'anything-iswitchb-handle-update)
+
+ (anything-cleanup)
+
+ (when anything-iswitchb-frame-configuration
+ (anything-set-frame/window-configuration anything-iswitchb-frame-configuration)
+ (setq anything-iswitchb-frame-configuration nil)))
+
+
+(defun anything-iswitchb-check-input ()
+ "Extract iswitchb input and check if it needs to be handled."
+ (declare (special iswitchb-text))
+ (if (or anything-iswitchb-frame-configuration
+ (sit-for anything-iswitchb-idle-delay))
+ (anything-check-new-input iswitchb-text)))
+
+
+(defun anything-iswitchb-handle-update ()
+ "Pop up the anything buffer if it's not empty and it's not
+shown yet and bind anything commands in iswitchb."
+ (unless (or (equal (buffer-size (get-buffer anything-buffer)) 0)
+ anything-iswitchb-frame-configuration)
+ (setq anything-iswitchb-frame-configuration (anything-current-frame/window-configuration))
+
+ (save-selected-window
+ (if (not anything-samewindow)
+ (pop-to-buffer anything-buffer)
+
+ (select-window (get-lru-window))
+ (switch-to-buffer anything-buffer)))
+
+ (with-current-buffer (window-buffer (active-minibuffer-window))
+ (let* ((anything-prefix "anything-")
+ (prefix-length (length anything-prefix))
+ (commands
+ (delete-dups
+ (remove-if 'null
+ (mapcar
+ (lambda (binding)
+ (let ((command (cdr binding)))
+ (when (and (symbolp command)
+ (eq (compare-strings
+ anything-prefix
+ 0 prefix-length
+ (symbol-name command)
+ 0 prefix-length)
+ t))
+ command)))
+ (cdr anything-map)))))
+ (bindings (mapcar (lambda (command)
+ (cons command
+ (where-is-internal command anything-map)))
+ commands)))
+
+ (push (list 'anything-iswitchb-cancel-anything (kbd "<ESC>"))
+ bindings)
+
+ (setq anything-iswitchb-saved-keys nil)
+
+ (let* ((iswitchb-prefix "iswitchb-")
+ (prefix-length (length iswitchb-prefix)))
+ (dolist (binding bindings)
+ (dolist (key (cdr binding))
+ (let ((old-command (lookup-key (current-local-map) key)))
+ (unless (and anything-iswitchb-dont-touch-iswithcb-keys
+ (symbolp old-command)
+ (eq (compare-strings iswitchb-prefix
+ 0 prefix-length
+ (symbol-name old-command)
+ 0 prefix-length)
+ t))
+ (push (cons key old-command)
+ anything-iswitchb-saved-keys)
+ (define-key (current-local-map) key (car binding)))))))))))
+
+
+(defun anything-iswitchb-cancel-anything ()
+ "Cancel anything completion and return to standard iswitchb."
+ (interactive)
+ (save-excursion
+ (dolist (binding anything-iswitchb-saved-keys)
+ (define-key (current-local-map) (car binding) (cdr binding)))
+ (anything-iswitchb-minibuffer-exit)))
+
+;; (@* "Compatibility")
+
+;; Copied assoc-default from XEmacs version 21.5.12
+(unless (fboundp 'assoc-default)
+ (defun assoc-default (key alist &optional test default)
+ "Find object KEY in a pseudo-alist ALIST.
+ALIST is a list of conses or objects. Each element (or the element's car,
+if it is a cons) is compared with KEY by evaluating (TEST (car elt) KEY).
+If that is non-nil, the element matches;
+then `assoc-default' returns the element's cdr, if it is a cons,
+or DEFAULT if the element is not a cons.
+
+If no element matches, the value is nil.
+If TEST is omitted or nil, `equal' is used."
+ (let (found (tail alist) value)
+ (while (and tail (not found))
+ (let ((elt (car tail)))
+ (when (funcall (or test 'equal) (if (consp elt) (car elt) elt) key)
+ (setq found t value (if (consp elt) (cdr elt) default))))
+ (setq tail (cdr tail)))
+ value)))
+
+;; Function not available in XEmacs,
+(unless (fboundp 'minibuffer-contents)
+ (defun minibuffer-contents ()
+ "Return the user input in a minbuffer as a string.
+The current buffer must be a minibuffer."
+ (field-string (point-max)))
+
+ (defun delete-minibuffer-contents ()
+ "Delete all user input in a minibuffer.
+The current buffer must be a minibuffer."
+ (delete-field (point-max))))
+
+;; Function not available in older Emacs (<= 22.1).
+(unless (fboundp 'buffer-chars-modified-tick)
+ (defun buffer-chars-modified-tick (&optional buffer)
+ "Return BUFFER's character-change tick counter.
+Each buffer has a character-change tick counter, which is set to the
+value of the buffer's tick counter (see `buffer-modified-tick'), each
+time text in that buffer is inserted or deleted. By comparing the
+values returned by two individual calls of `buffer-chars-modified-tick',
+you can tell whether a character change occurred in that buffer in
+between these calls. No argument or nil as argument means use current
+buffer as BUFFER."
+ (with-current-buffer (or buffer (current-buffer))
+ (if (listp buffer-undo-list)
+ (length buffer-undo-list)
+ (buffer-modified-tick)))))
+
+
+;; (@* "Unit Tests")
+
+(defun* anything-test-candidates (sources &optional (input "") (compile-source-functions anything-compile-source-functions-default))
+ "Test helper function for anything.
+Given pseudo `anything-sources' and `anything-pattern', returns list like
+ ((\"source name1\" (\"candidate1\" \"candidate2\"))
+ (\"source name2\" (\"candidate3\" \"candidate4\")))
+"
+ (let ((anything-test-mode t)
+ anything-enable-digit-shortcuts
+ anything-candidate-cache
+ (anything-sources (anything-normalize-sources sources))
+ (anything-compile-source-functions compile-source-functions)
+ anything-before-initialize-hook
+ anything-after-initialize-hook
+ anything-update-hook
+ anything-test-candidate-list)
+ (get-buffer-create anything-buffer)
+
+ (anything-initialize)
+ (setq anything-input input anything-pattern input)
+ (anything-update)
+ ;; test-mode spec: select 1st candidate!
+ (with-current-buffer anything-buffer
+ (forward-line 1)
+ (anything-mark-current-line))
+ (prog1
+ anything-test-candidate-list
+ (anything-cleanup))))
+
+(defmacro anything-test-update (sources pattern)
+ "Test helper macro for anything. It is meant for testing *anything* buffer contents."
+ `(progn (stub anything-get-sources => ,sources)
+ (stub run-hooks => nil)
+ (stub anything-maybe-fit-frame => nil)
+ (stub run-with-idle-timer => nil)
+ (let (anything-test-mode (anything-pattern ,pattern)) (anything-update))))
+
+;;;; unit test
+;; (install-elisp "http://www.emacswiki.org/cgi-bin/wiki/download/el-expectations.el")
+;; (install-elisp "http://www.emacswiki.org/cgi-bin/wiki/download/el-mock.el")
+(dont-compile
+ (when (fboundp 'expectations)
+ (expectations
+ (desc "anything-current-buffer")
+ (expect "__a_buffer"
+ (with-current-buffer (get-buffer-create "__a_buffer")
+ (anything-test-candidates '(((name . "FOO"))) "")
+ (prog1
+ (buffer-name anything-current-buffer)
+ (kill-buffer "__a_buffer")
+ )))
+ (desc "anything-buffer-file-name")
+ (expect (regexp "/__a_file__")
+ (with-current-buffer (get-buffer-create "__a_file__")
+ (setq buffer-file-name "/__a_file__")
+ (anything-test-candidates '(((name . "FOO"))) "")
+ (prog1
+ anything-buffer-file-name
+ ;;(kill-buffer "__a_file__")
+ )))
+ (desc "anything-compile-sources")
+ (expect '(((name . "foo")))
+ (anything-compile-sources '(((name . "foo"))) nil)
+ )
+ (expect '(((name . "foo") (type . test) (action . identity)))
+ (let ((anything-type-attributes '((test (action . identity)))))
+ (anything-compile-sources '(((name . "foo") (type . test)))
+ '(anything-compile-source--type))))
+ (desc "anything-sources accepts symbols")
+ (expect '(((name . "foo")))
+ (let* ((foo '((name . "foo"))))
+ (anything-compile-sources '(foo) nil)))
+ (desc "anything-get-sources action")
+ (expect '(((name . "Actions") (candidates . actions)))
+ (stub anything-action-window => t)
+ (let (anything-compiled-sources
+ (anything-sources '(((name . "Actions") (candidates . actions)))))
+ (anything-get-sources)))
+ (desc "get-buffer-create candidates-buffer")
+ (expect '(((name . "many") (init . many-init)
+ (candidates-in-buffer . anything-candidates-in-buffer)
+ (candidates . anything-candidates-in-buffer)
+ (volatile) (match identity)))
+ (anything-compile-sources
+ '(((name . "many") (init . many-init)
+ (candidates-in-buffer . anything-candidates-in-buffer)))
+ '(anything-compile-source--candidates-in-buffer)))
+ (expect '(((name . "many") (init . many-init)
+ (candidates-in-buffer)
+ (candidates . anything-candidates-in-buffer)
+ (volatile) (match identity)))
+ (anything-compile-sources
+ '(((name . "many") (init . many-init)
+ (candidates-in-buffer)))
+ '(anything-compile-source--candidates-in-buffer)))
+ (expect '(((name . "many") (init . many-init)
+ (candidates-in-buffer)
+ (type . test)
+ (action . identity)
+ (candidates . anything-candidates-in-buffer)
+ (volatile) (match identity)))
+ (let ((anything-type-attributes '((test (action . identity)))))
+ (anything-compile-sources
+ '(((name . "many") (init . many-init)
+ (candidates-in-buffer)
+ (type . test)))
+ '(anything-compile-source--type
+ anything-compile-source--candidates-in-buffer))))
+
+ (desc "anything-get-candidates")
+ (expect '("foo" "bar")
+ (anything-get-candidates '((name . "foo") (candidates "foo" "bar"))))
+ (expect '("FOO" "BAR")
+ (anything-get-candidates '((name . "foo") (candidates "foo" "bar")
+ (candidate-transformer
+ . (lambda (cands) (mapcar 'upcase cands))))))
+ (expect '("foo" "bar")
+ (anything-get-candidates '((name . "foo")
+ (candidates . (lambda () '("foo" "bar"))))))
+ (desc "anything-compute-matches")
+ (expect '("foo" "bar")
+ (let ((anything-pattern ""))
+ (anything-compute-matches '((name . "FOO") (candidates "foo" "bar") (volatile)))))
+ (expect '("foo")
+ (let ((anything-pattern "oo"))
+ (anything-compute-matches '((name . "FOO") (candidates "foo" "bar") (volatile)))))
+ (expect '("bar")
+ (let ((anything-pattern "^b"))
+ (anything-compute-matches '((name . "FOO") (candidates "foo" "bar") (volatile)))))
+ (expect '("a" "b")
+ (let ((anything-pattern "")
+ (anything-candidate-number-limit 2))
+ (anything-compute-matches '((name . "FOO") (candidates "a" "b" "c") (volatile)))))
+ (expect '("a" "b")
+ (let ((anything-pattern ".")
+ (anything-candidate-number-limit 2))
+ (anything-compute-matches '((name . "FOO") (candidates "a" "b" "c") (volatile)))))
+ (expect '("a" "b" "c")
+ (let ((anything-pattern "")
+ anything-candidate-number-limit)
+ (anything-compute-matches '((name . "FOO") (candidates "a" "b" "c") (volatile)))))
+ (expect '("a" "b" "c")
+ (let ((anything-pattern "[abc]")
+ anything-candidate-number-limit)
+ (anything-compute-matches '((name . "FOO") (candidates "a" "b" "c") (volatile)))))
+ ;; using anything-test-candidate-list
+ (desc "anything-test-candidates")
+ (expect '(("FOO" ("foo" "bar")))
+ (anything-test-candidates '(((name . "FOO") (candidates "foo" "bar")))))
+ (expect '(("FOO" ("bar")))
+ (anything-test-candidates '(((name . "FOO") (candidates "foo" "bar"))) "ar"))
+ (expect '(("T1" ("hoge" "aiue"))
+ ("T2" ("test" "boke")))
+ (anything-test-candidates '(((name . "T1") (candidates "hoge" "aiue"))
+ ((name . "T2") (candidates "test" "boke")))))
+ (expect '(("T1" ("hoge"))
+ ("T2" ("boke")))
+ (anything-test-candidates '(((name . "T1") (candidates "hoge" "aiue"))
+ ((name . "T2") (candidates "test" "boke"))) "o"))
+ (desc "requires-pattern attribute")
+ (expect nil
+ (anything-test-candidates '(((name . "FOO") (candidates "foo" "bar")
+ (requires-pattern . 1)))))
+ (expect '(("FOO" ("bar")))
+ (anything-test-candidates '(((name . "FOO") (candidates "foo" "bar")
+ (requires-pattern . 1))) "b"))
+ (desc "delayed attribute(for test)")
+ (expect '(("T2" ("boke"))
+ ("T1" ("hoge")))
+ (anything-test-candidates
+ '(((name . "T1") (candidates "hoge" "aiue") (delayed))
+ ((name . "T2") (candidates "test" "boke")))
+ "o"))
+ (desc "match attribute(prefix search)")
+ (expect '(("FOO" ("bar")))
+ (anything-test-candidates
+ '(((name . "FOO") (candidates "foo" "bar")
+ (match (lambda (c) (string-match (concat "^" anything-pattern) c)))))
+ "ba"))
+ (expect nil
+ (anything-test-candidates
+ '(((name . "FOO") (candidates "foo" "bar")
+ (match (lambda (c) (string-match (concat "^" anything-pattern) c)))))
+ "ar"))
+ (desc "init attribute")
+ (expect '(("FOO" ("bar")))
+ (let (v)
+ (anything-test-candidates
+ '(((name . "FOO") (init . (lambda () (setq v '("foo" "bar"))))
+ (candidates . v)))
+ "ar")))
+ (desc "candidate-transformer attribute")
+ (expect '(("FOO" ("BAR")))
+ (anything-test-candidates '(((name . "FOO") (candidates "foo" "bar")
+ (candidate-transformer
+ . (lambda (cands) (mapcar 'upcase cands)))))
+ "ar"))
+ (desc "filtered-candidate-transformer attribute")
+ ;; needs more tests
+ (expect '(("FOO" ("BAR")))
+ (anything-test-candidates '(((name . "FOO") (candidates "foo" "bar")
+ (filtered-candidate-transformer
+ . (lambda (cands src) (mapcar 'upcase cands)))))
+ "ar"))
+ (desc "anything-candidates-in-buffer-1")
+ (expect nil
+ (anything-candidates-in-buffer-1 nil))
+ (expect '("foo+" "bar+" "baz+")
+ (with-temp-buffer
+ (insert "foo+\nbar+\nbaz+\n")
+ (let ((anything-candidate-number-limit 5))
+ (anything-candidates-in-buffer-1 (current-buffer) ""))))
+ (expect '("foo+" "bar+")
+ (with-temp-buffer
+ (insert "foo+\nbar+\nbaz+\n")
+ (let ((anything-candidate-number-limit 2))
+ (anything-candidates-in-buffer-1 (current-buffer) ""))))
+ (expect '("foo+")
+ (with-temp-buffer
+ (insert "foo+\nbar+\nbaz+\n")
+ (anything-candidates-in-buffer-1 (current-buffer) "oo\\+")))
+ (expect '("foo+")
+ (with-temp-buffer
+ (insert "foo+\nbar+\nbaz+\n")
+ (anything-candidates-in-buffer-1
+ (current-buffer) "oo+"
+ #'buffer-substring-no-properties '(search-forward))))
+ (expect '(("foo+" "FOO+"))
+ (with-temp-buffer
+ (insert "foo+\nbar+\nbaz+\n")
+ (anything-candidates-in-buffer-1
+ (current-buffer) "oo\\+"
+ (lambda (s e)
+ (let ((l (buffer-substring-no-properties s e)))
+ (list l (upcase l)))))))
+ (desc "anything-candidates-in-buffer")
+ (expect '(("TEST" ("foo+" "bar+" "baz+")))
+ (anything-test-candidates
+ '(((name . "TEST")
+ (init
+ . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
+ (insert "foo+\nbar+\nbaz+\n"))))
+ (candidates . anything-candidates-in-buffer)
+ (match identity)
+ (volatile)))))
+ (expect '(("TEST" ("foo+" "bar+" "baz+")))
+ (let (anything-candidate-number-limit)
+ (anything-test-candidates
+ '(((name . "TEST")
+ (init
+ . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
+ (insert "foo+\nbar+\nbaz+\n"))))
+ (candidates . anything-candidates-in-buffer)
+ (match identity)
+ (volatile))))))
+ (expect '(("TEST" ("foo+")))
+ (anything-test-candidates
+ '(((name . "TEST")
+ (init
+ . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
+ (insert "foo+\nbar+\nbaz+\n"))))
+ (candidates . anything-candidates-in-buffer)
+ (match identity)
+ (volatile)))
+ "oo\\+"))
+ (desc "search attribute")
+ (expect '(("TEST" ("foo+")))
+ (anything-test-candidates
+ '(((name . "TEST")
+ (init
+ . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
+ (insert "foo+\nbar+\nbaz+\nooo\n"))))
+ (search search-forward)
+ (candidates . anything-candidates-in-buffer)
+ (match identity)
+ (volatile)))
+ "oo+"))
+ (expect '(("TEST" ("foo+" "ooo")))
+ (anything-test-candidates
+ '(((name . "TEST")
+ (init
+ . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
+ (insert "foo+\nbar+\nbaz+\nooo\n"))))
+ (search search-forward re-search-forward)
+ (candidates . anything-candidates-in-buffer)
+ (match identity)
+ (volatile)))
+ "oo+"))
+ (expect '(("TEST" ("foo+" "ooo")))
+ (anything-test-candidates
+ '(((name . "TEST")
+ (init
+ . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
+ (insert "foo+\nbar+\nbaz+\nooo\n"))))
+ (search re-search-forward search-forward)
+ (candidates . anything-candidates-in-buffer)
+ (match identity)
+ (volatile)))
+ "oo+"))
+ (expect '(("TEST" ("ooo" "foo+")))
+ (anything-test-candidates
+ '(((name . "TEST")
+ (init
+ . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
+ (insert "bar+\nbaz+\nooo\nfoo+\n"))))
+ (search re-search-forward search-forward)
+ (candidates . anything-candidates-in-buffer)
+ (match identity)
+ (volatile)))
+ "oo+"))
+ ;; faster exact match
+ (expect '(("TEST" ("bar+")))
+ (anything-test-candidates
+ '(((name . "TEST")
+ (init
+ . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
+ (insert "bar+\nbaz+\nooo\nfoo+\n"))))
+ (search (lambda (pattern &rest _)
+ (and (search-forward (concat "\n" pattern "\n") nil t)
+ (forward-line -1))))
+ (candidates . anything-candidates-in-buffer)
+ (match identity)
+ (volatile)))
+ "bar+"))
+ ;; faster prefix match
+ (expect '(("TEST" ("bar+")))
+ (anything-test-candidates
+ '(((name . "TEST")
+ (init
+ . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
+ (insert "bar+\nbaz+\nooo\nfoo+\n"))))
+ (search (lambda (pattern &rest _)
+ (search-forward (concat "\n" pattern) nil t)))
+ (candidates . anything-candidates-in-buffer)
+ (match identity)
+ (volatile)))
+ "ba"))
+ (desc "anything-current-buffer-is-modified")
+ (expect '(("FOO" ("modified")))
+ (let ((sources '(((name . "FOO")
+ (candidates
+ . (lambda ()
+ (if (anything-current-buffer-is-modified)
+ '("modified")
+ '("unmodified"))))))))
+ (with-temp-buffer
+ (clrhash anything-tick-hash)
+ (insert "1")
+ (anything-test-candidates sources))))
+ (expect '(("FOO" ("unmodified")))
+ (let ((sources '(((name . "FOO")
+ (candidates
+ . (lambda ()
+ (if (anything-current-buffer-is-modified)
+ '("modified")
+ '("unmodified"))))))))
+ (with-temp-buffer
+ (clrhash anything-tick-hash)
+ (insert "1")
+ (anything-test-candidates sources)
+ (anything-test-candidates sources))))
+ (expect '(("FOO" ("modified")))
+ (let ((sources '(((name . "FOO")
+ (candidates
+ . (lambda ()
+ (if (anything-current-buffer-is-modified)
+ '("modified")
+ '("unmodified"))))))))
+ (with-temp-buffer
+ (clrhash anything-tick-hash)
+ (insert "1")
+ (anything-test-candidates sources)
+ (insert "2")
+ (anything-test-candidates sources))))
+ (expect '(("BAR" ("modified")))
+ (let ((sources1 '(((name . "FOO")
+ (candidates
+ . (lambda ()
+ (if (anything-current-buffer-is-modified)
+ '("modified")
+ '("unmodified")))))))
+ (sources2 '(((name . "BAR")
+ (candidates
+ . (lambda ()
+ (if (anything-current-buffer-is-modified)
+ '("modified")
+ '("unmodified"))))))))
+ (with-temp-buffer
+ (clrhash anything-tick-hash)
+ (insert "1")
+ (anything-test-candidates sources1)
+ (anything-test-candidates sources2))))
+ (expect '(("FOO" ("unmodified")))
+ (let ((sources1 '(((name . "FOO")
+ (candidates
+ . (lambda ()
+ (if (anything-current-buffer-is-modified)
+ '("modified")
+ '("unmodified")))))))
+ (sources2 '(((name . "BAR")
+ (candidates
+ . (lambda ()
+ (if (anything-current-buffer-is-modified)
+ '("modified")
+ '("unmodified"))))))))
+ (with-temp-buffer
+ (clrhash anything-tick-hash)
+ (insert "1")
+ (anything-test-candidates sources1)
+ (anything-test-candidates sources2)
+ (anything-test-candidates sources1))))
+ (expect '(("BAR" ("unmodified")))
+ (let ((sources1 '(((name . "FOO")
+ (candidates
+ . (lambda ()
+ (if (anything-current-buffer-is-modified)
+ '("modified")
+ '("unmodified")))))))
+ (sources2 '(((name . "BAR")
+ (candidates
+ . (lambda ()
+ (if (anything-current-buffer-is-modified)
+ '("modified")
+ '("unmodified"))))))))
+ (with-temp-buffer
+ (clrhash anything-tick-hash)
+ (insert "1")
+ (anything-test-candidates sources1)
+ (anything-test-candidates sources2)
+ (anything-test-candidates sources2))))
+ (expect '(("BAR" ("modified")))
+ (let ((sources1 '(((name . "FOO")
+ (candidates
+ . (lambda ()
+ (if (anything-current-buffer-is-modified)
+ '("modified")
+ '("unmodified")))))))
+ (sources2 '(((name . "BAR")
+ (candidates
+ . (lambda ()
+ (if (anything-current-buffer-is-modified)
+ '("modified")
+ '("unmodified"))))))))
+ (with-temp-buffer
+ (clrhash anything-tick-hash)
+ (insert "1")
+ (anything-test-candidates sources1)
+ (anything-test-candidates sources2)
+ (with-temp-buffer
+ (anything-test-candidates sources2)))))
+ (desc "anything-source-name")
+ (expect "FOO"
+ (let (v)
+ (anything-test-candidates '(((name . "FOO")
+ (init
+ . (lambda () (setq v anything-source-name)))
+ (candidates "ok"))))
+ v))
+ (expect "FOO"
+ (let (v)
+ (anything-test-candidates '(((name . "FOO")
+ (candidates
+ . (lambda ()
+ (setq v anything-source-name)
+ '("ok"))))))
+ v))
+ (expect "FOO"
+ (let (v)
+ (anything-test-candidates '(((name . "FOO")
+ (candidates "ok")
+ (candidate-transformer
+ . (lambda (c)
+ (setq v anything-source-name)
+ c)))))
+ v))
+ (expect "FOO"
+ (let (v)
+ (anything-test-candidates '(((name . "FOO")
+ (candidates "ok")
+ (filtered-candidate-transformer
+ . (lambda (c s)
+ (setq v anything-source-name)
+ c)))))
+ v))
+ (expect "FOO"
+ (let (v)
+ (anything-test-candidates '(((name . "FOO")
+ (candidates "ok")
+ (display-to-real
+ . (lambda (c)
+ (setq v anything-source-name)
+ c))
+ (action . identity))))
+ (anything-execute-selection-action)
+ v))
+ (desc "anything-candidate-buffer create")
+ (expect " *anything candidates:FOO*"
+ (let* (anything-candidate-buffer-alist
+ (anything-source-name "FOO")
+ (buf (anything-candidate-buffer 'global)))
+ (prog1 (buffer-name buf)
+ (kill-buffer buf))))
+ (expect " *anything candidates:FOO*aTestBuffer"
+ (let* (anything-candidate-buffer-alist
+ (anything-source-name "FOO")
+ (anything-current-buffer (get-buffer-create "aTestBuffer"))
+ (buf (anything-candidate-buffer 'local)))
+ (prog1 (buffer-name buf)
+ (kill-buffer anything-current-buffer)
+ (kill-buffer buf))))
+ (expect 0
+ (let (anything-candidate-buffer-alist
+ (anything-source-name "FOO") buf)
+ (with-current-buffer (anything-candidate-buffer 'global)
+ (insert "1"))
+ (setq buf (anything-candidate-buffer 'global))
+ (prog1 (buffer-size buf)
+ (kill-buffer buf))))
+ (desc "anything-candidate-buffer get-buffer")
+ (expect " *anything candidates:FOO*"
+ (let* (anything-candidate-buffer-alist
+ (anything-source-name "FOO")
+ (buf (anything-candidate-buffer 'global)))
+ (prog1 (buffer-name (anything-candidate-buffer))
+ (kill-buffer buf))))
+ (expect " *anything candidates:FOO*aTestBuffer"
+ (let* (anything-candidate-buffer-alist
+ (anything-source-name "FOO")
+ (anything-current-buffer (get-buffer-create "aTestBuffer"))
+ (buf (anything-candidate-buffer 'local)))
+ (prog1 (buffer-name (anything-candidate-buffer))
+ (kill-buffer anything-current-buffer)
+ (kill-buffer buf))))
+ (expect " *anything candidates:FOO*"
+ (let* (anything-candidate-buffer-alist
+ (anything-source-name "FOO")
+ (buf-local (anything-candidate-buffer 'local))
+ (buf-global (anything-candidate-buffer 'global)))
+ (prog1 (buffer-name (anything-candidate-buffer))
+ (kill-buffer buf-local)
+ (kill-buffer buf-global))))
+ (expect " *anything candidates:FOO*aTestBuffer"
+ (let* (anything-candidate-buffer-alist
+ (anything-source-name "FOO")
+ (anything-current-buffer (get-buffer-create "aTestBuffer"))
+ (buf-global (anything-candidate-buffer 'global))
+ (buf-local (anything-candidate-buffer 'local)))
+ (prog1 (buffer-name (anything-candidate-buffer))
+ (kill-buffer buf-local)
+ (kill-buffer buf-global))))
+ (expect nil
+ (let* (anything-candidate-buffer-alist
+ (anything-source-name "NOP__"))
+ (anything-candidate-buffer)))
+ (desc "anything-candidate-buffer register-buffer")
+ (expect " *anything test candidates*"
+ (let (anything-candidate-buffer-alist
+ (buf (get-buffer-create " *anything test candidates*")))
+ (with-current-buffer buf
+ (insert "1\n2\n")
+ (prog1 (buffer-name (anything-candidate-buffer buf))
+ (kill-buffer (current-buffer))))))
+ (expect " *anything test candidates*"
+ (let (anything-candidate-buffer-alist
+ (buf (get-buffer-create " *anything test candidates*")))
+ (with-current-buffer buf
+ (insert "1\n2\n")
+ (anything-candidate-buffer buf)
+ (prog1 (buffer-name (anything-candidate-buffer))
+ (kill-buffer (current-buffer))))))
+ (expect "1\n2\n"
+ (let (anything-candidate-buffer-alist
+ (buf (get-buffer-create " *anything test candidates*")))
+ (with-current-buffer buf
+ (insert "1\n2\n")
+ (anything-candidate-buffer buf)
+ (prog1 (buffer-string)
+ (kill-buffer (current-buffer))))))
+ (desc "action attribute")
+ (expect "foo"
+ (anything-test-candidates
+ '(((name . "TEST")
+ (candidates "foo")
+ (action ("identity" . identity)))))
+ (anything-execute-selection-action))
+ (expect "foo"
+ (anything-test-candidates
+ '(((name . "TEST")
+ (candidates "foo")
+ (action ("identity" . (lambda (c) (identity c)))))))
+ (anything-execute-selection-action))
+ (desc "anything-execute-selection-action")
+ (expect "FOO"
+ (anything-execute-selection-action
+ "foo" '(("upcase" . upcase)) nil #'identity))
+ (expect "FOO"
+ (anything-execute-selection-action
+ "foo" '(("upcase" . (lambda (c) (upcase c)))) nil #'identity))
+ (desc "display-to-real attribute")
+ (expect "FOO"
+ (anything-execute-selection-action
+ "foo"
+ '(("identity" . identity))
+ nil
+ #'upcase
+ ))
+ (expect "FOO"
+ (anything-test-candidates
+ '(((name . "TEST")
+ (candidates "foo")
+ (display-to-real . upcase)
+ (action ("identity" . identity)))))
+ (anything-execute-selection-action))
+ (desc "cleanup test")
+ (expect 'cleaned
+ (let (v)
+ (anything-test-candidates
+ '(((name . "TEST")
+ (cleanup . (lambda () (setq v 'cleaned))))))
+ v))
+ (desc "anything-get-current-source")
+ ;; in init/candidates/action/candidate-transformer/filtered-candidate-transformer
+ ;; display-to-real/cleanup function
+ (expect "FOO"
+ (assoc-default
+ 'name
+ (anything-funcall-with-source '((name . "FOO")) 'anything-get-current-source)))
+ ;; init
+ (expect "FOO"
+ (let (v)
+ (anything-test-candidates
+ '(((name . "FOO")
+ (init . (lambda () (setq v (anything-get-current-source)))))))
+ (assoc-default 'name v)))
+ ;; candidates
+ (expect "FOO"
+ (let (v)
+ (anything-test-candidates
+ '(((name . "FOO")
+ (candidates . (lambda () (setq v (anything-get-current-source)) '("a"))))))
+ (assoc-default 'name v)))
+ ;; action
+ (expect "FOO"
+ (let (v)
+ (anything-test-candidates
+ '(((name . "FOO")
+ (candidates "a")
+ (action
+ . (lambda (c) (setq v (anything-get-current-source)) c)))))
+ (anything-execute-selection-action)
+ (assoc-default 'name v)))
+ ;; candidate-transformer
+ (expect "FOO"
+ (let (v)
+ (anything-test-candidates
+ '(((name . "FOO")
+ (candidates "a")
+ (candidate-transformer
+ . (lambda (c) (setq v (anything-get-current-source)) c)))))
+ (assoc-default 'name v)))
+ ;; filtered-candidate-transformer
+ (expect "FOO"
+ (let (v)
+ (anything-test-candidates
+ '(((name . "FOO")
+ (candidates "a")
+ (filtered-candidate-transformer
+ . (lambda (c s) (setq v (anything-get-current-source)) c)))))
+ (assoc-default 'name v)))
+ ;; action-transformer
+ (expect "FOO"
+ (let (v)
+ (anything-test-candidates
+ '(((name . "FOO")
+ (candidates "a")
+ (action-transformer
+ . (lambda (a c) (setq v (anything-get-current-source)) a))
+ (action . identity))))
+ (anything-execute-selection-action)
+ (assoc-default 'name v)))
+ ;; display-to-real
+ (expect "FOO"
+ (let (v)
+ (anything-test-candidates
+ '(((name . "FOO")
+ (init . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
+ (insert "a\n"))))
+ (candidates-in-buffer)
+ (display-to-real
+ . (lambda (c) (setq v (anything-get-current-source)) c))
+ (action . identity))))
+ (anything-execute-selection-action)
+ (assoc-default 'name v)))
+ ;; cleanup
+ (expect "FOO"
+ (let (v)
+ (anything-test-candidates
+ '(((name . "FOO")
+ (candidates "a")
+ (cleanup
+ . (lambda () (setq v (anything-get-current-source)))))))
+ (assoc-default 'name v)))
+ ;; candidates are displayed
+ (expect "TEST"
+ (anything-test-candidates
+ '(((name . "TEST")
+ (candidates "foo")
+ (action ("identity" . identity)))))
+ (assoc-default 'name (anything-get-current-source)))
+ (desc "anything-attr")
+ (expect "FOO"
+ (anything-funcall-with-source
+ '((name . "FOO"))
+ (lambda ()
+ (anything-attr 'name))))
+ (expect 'fuga
+ (let (v)
+ (anything-test-candidates
+ '(((name . "FOO")
+ (hoge . fuga)
+ (init . (lambda () (setq v (anything-attr 'hoge))))
+ (candidates "a"))))
+ v))
+ (expect nil
+ (let (v)
+ (anything-test-candidates
+ '(((name . "FOO")
+ (init . (lambda () (setq v (anything-attr 'hoge))))
+ (candidates "a"))))
+ v))
+ (expect nil
+ (let (v)
+ (anything-test-candidates
+ '(((name . "FOO")
+ (hoge) ;INCOMPATIBLE!
+ (init . (lambda () (setq v (anything-attr 'hoge))))
+ (candidates "a"))))
+ v))
+ (desc "anything-attr-defined")
+ (expect (non-nil)
+ (let (v)
+ (anything-test-candidates
+ '(((name . "FOO")
+ (hoge)
+ (init . (lambda () (setq v (anything-attr-defined 'hoge))))
+ (candidates "a"))))
+ v))
+ (expect nil
+ (let (v)
+ (anything-test-candidates
+ '(((name . "FOO")
+ (init . (lambda () (setq v (anything-attr-defined 'hoge))))
+ (candidates "a"))))
+ v))
+ (desc "anything-attrset")
+ (expect '((name . "FOO") (hoge . 77))
+ (let ((src '((name . "FOO") (hoge))))
+ (anything-attrset 'hoge 77 src)
+ src))
+ (expect 77
+ (anything-attrset 'hoge 77 '((name . "FOO") (hoge))))
+
+ (expect '((name . "FOO") (hoge . 77))
+ (let ((src '((name . "FOO") (hoge . 1))))
+ (anything-attrset 'hoge 77 src)
+ src))
+
+ (expect '((name . "FOO") (hoge . 77) (x))
+ (let ((src '((name . "FOO") (x))))
+ (anything-attrset 'hoge 77 src)
+ src))
+ (expect 77
+ (anything-attrset 'hoge 77 '((name . "FOO"))))
+ (desc "anything-preselect")
+ ;; entire candidate
+ (expect "foo"
+ (with-current-buffer (anything-create-anything-buffer t)
+ (let ((anything-pattern "")
+ (anything-test-mode t))
+ (anything-process-source '((name . "test")
+ (candidates "hoge" "foo" "bar")))
+ (anything-preselect "foo")
+ (anything-get-selection))))
+ ;; regexp
+ (expect "foo"
+ (with-current-buffer (anything-create-anything-buffer t)
+ (let ((anything-pattern "")
+ (anything-test-mode t))
+ (anything-process-source '((name . "test")
+ (candidates "hoge" "foo" "bar")))
+ (anything-preselect "fo+")
+ (anything-get-selection))))
+ ;; no match -> first entry
+ (expect "hoge"
+ (with-current-buffer (anything-create-anything-buffer t)
+ (let ((anything-pattern "")
+ (anything-test-mode t))
+ (anything-process-source '((name . "test")
+ (candidates "hoge" "foo" "bar")))
+ (anything-preselect "not found")
+ (anything-get-selection))))
+ (desc "anything-check-new-input")
+ (expect "newpattern"
+ (stub anything-update)
+ (stub anything-action-window)
+ (let ((anything-pattern "pattern"))
+ (anything-check-new-input "newpattern")
+ anything-pattern))
+ ;; anything-input == nil when action window is available
+ (expect nil
+ (stub anything-update)
+ (stub anything-action-window => t)
+ (let ((anything-pattern "pattern")
+ anything-input)
+ (anything-check-new-input "newpattern")
+ anything-input))
+ ;; anything-input == anything-pattern unless action window is available
+ (expect "newpattern"
+ (stub anything-update)
+ (stub anything-action-window => nil)
+ (let ((anything-pattern "pattern")
+ anything-input)
+ (anything-check-new-input "newpattern")
+ anything-input))
+ (expect (mock (anything-update))
+ (stub anything-action-window)
+ (let (anything-pattern)
+ (anything-check-new-input "foo")))
+ (desc "anything-update")
+ (expect (mock (anything-process-source '((name . "1"))))
+ (anything-test-update '(((name . "1"))) ""))
+ ;; (find-function 'anything-update)
+ ;; TODO el-mock.el should express 2nd call of function.
+ ;; (expect (mock (anything-process-source '((name . "2"))))
+ ;; (stub anything-get-sources => '(((name . "1")) ((name . "2"))))
+ ;; (stub run-hooks)
+ ;; (stub anything-maybe-fit-frame)
+ ;; (stub run-with-idle-timer)
+ ;; (anything-update))
+ (expect (mock (run-with-idle-timer * nil 'anything-process-delayed-sources
+ '(((name . "2") (delayed)))))
+ (stub anything-get-sources => '(((name . "1"))
+ ((name . "2") (delayed))))
+ (stub run-hooks)
+ (stub anything-maybe-fit-frame)
+ (let ((anything-pattern "") anything-test-mode)
+ (anything-update)))
+
+ (expect (mock (run-with-idle-timer * nil 'anything-process-delayed-sources nil))
+ (stub anything-get-sources => '(((name . "1"))
+ ((name . "2"))))
+ (stub run-hooks)
+ (stub anything-maybe-fit-frame)
+ (let ((anything-pattern "") anything-test-mode)
+ (anything-update)))
+
+
+ (desc "requires-pattern attribute")
+ (expect (not-called anything-process-source)
+ (anything-test-update '(((name . "1") (requires-pattern))) ""))
+ (expect (not-called anything-process-source)
+ (anything-test-update '(((name . "1") (requires-pattern . 3))) "xx"))
+
+ (desc "delay")
+ (expect (mock (sit-for 0.25))
+ (stub with-current-buffer)
+ (let ((anything-idle-delay 1.0)
+ (anything-input-idle-delay 0.75))
+ (anything-process-delayed-sources t)))
+ (expect (mock (sit-for 0.0))
+ (stub with-current-buffer)
+ (let ((anything-idle-delay 0.2)
+ (anything-input-idle-delay 0.5))
+ (anything-process-delayed-sources t)))
+ (expect (mock (sit-for 0.5))
+ (stub with-current-buffer)
+ (let ((anything-idle-delay 0.5)
+ (anything-input-idle-delay nil))
+ (anything-process-delayed-sources t)))
+ (desc "anything-normalize-sources")
+ (expect '(anything-c-source-test)
+ (anything-normalize-sources 'anything-c-source-test))
+ (expect '(anything-c-source-test)
+ (anything-normalize-sources '(anything-c-source-test)))
+ (expect '(anything-c-source-test)
+ (let ((anything-sources '(anything-c-source-test)))
+ (anything-normalize-sources nil)))
+ (desc "anything-get-action")
+ (expect '(("identity" . identity))
+ (stub buffer-size => 1)
+ (stub anything-get-current-source => '((name . "test")
+ (action ("identity" . identity))))
+ (anything-get-action))
+ (expect '((("identity" . identity)) "action-transformer is called")
+ (stub buffer-size => 1)
+ (stub anything-get-current-source
+ => '((name . "test")
+ (action ("identity" . identity))
+ (action-transformer
+ . (lambda (actions selection)
+ (list actions selection)))))
+ (stub anything-get-selection => "action-transformer is called")
+ (anything-get-action))
+ (desc "anything-select-nth-action")
+ (expect "selection"
+ (stub anything-get-selection => "selection")
+ (stub anything-exit-minibuffer)
+ (let (anything-saved-selection)
+ (anything-select-nth-action 1)
+ anything-saved-selection))
+ (expect 'cadr
+ (stub anything-get-action => '(("0" . car) ("1" . cdr) ("2" . cadr)))
+ (stub anything-exit-minibuffer)
+ (stub anything-get-selection => "selection")
+ (let (anything-saved-action)
+ (anything-select-nth-action 2)
+ anything-saved-action))
+ (desc "anything-funcall-foreach")
+ (expect (mock (upcase "foo"))
+ (stub anything-get-sources => '(((init . (lambda () (upcase "foo"))))))
+ (anything-funcall-foreach 'init))
+ (expect (mock (downcase "bar"))
+ (stub anything-get-sources => '(((init . (lambda () (upcase "foo"))))
+ ((init . (lambda () (downcase "bar"))))))
+ (anything-funcall-foreach 'init))
+ (expect (not-called anything-funcall-with-source)
+ (stub anything-get-sources => '(((init . (lambda () (upcase "foo"))))))
+ (anything-funcall-foreach 'not-found))
+ ;; TODO anything-select-with-digit-shortcut test
+ (desc "anything-get-cached-candidates")
+ (expect '("cached" "version")
+ (let ((anything-candidate-cache '(("test" "cached" "version"))))
+ (anything-get-cached-candidates '((name . "test")
+ (candidates "new")))))
+ (expect '("new")
+ (let ((anything-candidate-cache '(("other" "cached" "version"))))
+ (anything-get-cached-candidates '((name . "test")
+ (candidates "new")))))
+ (expect '(("test" "new")
+ ("other" "cached" "version"))
+ (let ((anything-candidate-cache '(("other" "cached" "version"))))
+ (anything-get-cached-candidates '((name . "test")
+ (candidates "new")))
+ anything-candidate-cache))
+ (expect '(("other" "cached" "version"))
+ (let ((anything-candidate-cache '(("other" "cached" "version"))))
+ (anything-get-cached-candidates '((name . "test")
+ (candidates "new")
+ (volatile)))
+ anything-candidate-cache))
+ ;; TODO when candidates == process
+ ;; TODO anything-output-filter
+ (desc "candidate-number-limit attribute")
+ (expect '("a" "b")
+ (let ((anything-pattern "")
+ (anything-candidate-number-limit 20))
+ (anything-compute-matches '((name . "FOO") (candidates "a" "b" "c")
+ (candidate-number-limit . 2) (volatile)))))
+ (expect '("a" "b")
+ (let ((anything-pattern "[abc]")
+ (anything-candidate-number-limit 20))
+ (anything-compute-matches '((name . "FOO") (candidates "a" "b" "c")
+ (candidate-number-limit . 2) (volatile)))))
+ (expect '(("TEST" ("a" "b" "c")))
+ (let ((anything-candidate-number-limit 2))
+ (anything-test-candidates
+ '(((name . "TEST")
+ (init
+ . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
+ (insert "a\nb\nc\nd\n"))))
+ (candidates . anything-candidates-in-buffer)
+ (match identity)
+ (candidate-number-limit . 3)
+ (volatile))))))
+ (expect '(("TEST" ("a" "b" "c")))
+ (let ((anything-candidate-number-limit 2))
+ (anything-test-candidates
+ '(((name . "TEST")
+ (init
+ . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
+ (insert "a\nb\nc\nd\n"))))
+ (candidates . anything-candidates-in-buffer)
+ (match identity)
+ (candidate-number-limit . 3)
+ (volatile)))
+ ".")))
+ (desc "multiple init")
+ (expect '(1 . 2)
+ (let (a b)
+ (anything-test-candidates
+ '(((name . "test")
+ (init (lambda () (setq a 1))
+ (lambda () (setq b 2))))))
+ (cons a b)))
+ (expect 1
+ (let (a)
+ (anything-test-candidates
+ '(((name . "test")
+ (init (lambda () (setq a 1))))))
+ a))
+ (desc "multiple cleanup")
+ (expect '(1 . 2)
+ (let (a b)
+ (anything-test-candidates
+ '(((name . "test")
+ (cleanup (lambda () (setq a 1))
+ (lambda () (setq b 2))))))
+ (cons a b)))
+ (desc "anything-mklist")
+ (expect '(1)
+ (anything-mklist 1))
+ (expect '(2)
+ (anything-mklist '(2)))
+ (desc "anything-before-initialize-hook")
+ (expect 'called
+ (let ((anything-before-initialize-hook '((lambda () (setq v 'called))))
+ v)
+ (anything-initialize)
+ v))
+ (desc "anything-after-initialize-hook")
+ (expect '(b a)
+ (let ((anything-before-initialize-hook
+ '((lambda () (setq v '(a)))))
+ (anything-after-initialize-hook
+ '((lambda () (setq v (cons 'b v)))))
+ v)
+ (anything-initialize)
+ v))
+ (expect 0
+ (let ((anything-after-initialize-hook
+ '((lambda () (setq v (buffer-size (get-buffer anything-buffer))))))
+ v)
+ (anything-initialize)
+ v))
+ (desc "get-line attribute")
+ (expect '(("TEST" ("FOO+")))
+ (anything-test-candidates
+ '(((name . "TEST")
+ (init
+ . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
+ (insert "foo+\nbar+\nbaz+\n"))))
+ (candidates-in-buffer)
+ (get-line . (lambda (s e) (upcase (buffer-substring-no-properties s e))))))
+ "oo\\+"))
+ (desc "with-anything-restore-variables")
+ (expect '(7 8)
+ (let ((a 7) (b 8)
+ (anything-restored-variables '(a b)))
+ (with-anything-restore-variables
+ (setq a 0 b 0))
+ (list a b)))
+ (desc "anything-cleanup-hook")
+ (expect 'called
+ (let ((anything-cleanup-hook
+ '((lambda () (setq v 'called))))
+ v)
+ (anything-cleanup)
+ v))
+ (desc "with-anything-display-same-window")
+ (expect (non-nil)
+ (save-window-excursion
+ (delete-other-windows)
+ (split-window)
+
+ (let ((buf (get-buffer-create " tmp"))
+ (win (selected-window)))
+ (with-anything-display-same-window
+ (display-buffer buf)
+ (eq win (get-buffer-window buf))))))
+ (expect (non-nil)
+ (save-window-excursion
+ (delete-other-windows)
+ (split-window)
+
+ (let ((buf (get-buffer-create " tmp"))
+ (win (selected-window)))
+ (with-anything-display-same-window
+ (pop-to-buffer buf)
+ (eq win (get-buffer-window buf))))))
+ (expect (non-nil)
+ (save-window-excursion
+ (delete-other-windows)
+ (split-window)
+
+ (let ((buf (get-buffer-create " tmp"))
+ (win (selected-window)))
+ (with-anything-display-same-window
+ (switch-to-buffer buf)
+ (eq win (get-buffer-window buf))))))
+ (expect (non-nil)
+ (save-window-excursion
+ (delete-other-windows)
+ (let ((buf (get-buffer-create " tmp"))
+ (win (selected-window)))
+ (with-anything-display-same-window
+ (display-buffer buf)
+ (eq win (get-buffer-window buf))))))
+ (expect (non-nil)
+ (save-window-excursion
+ (delete-other-windows)
+ (let ((buf (get-buffer-create " tmp"))
+ (win (selected-window)))
+ (with-anything-display-same-window
+ (pop-to-buffer buf)
+ (eq win (get-buffer-window buf))))))
+ (desc "search-from-end attribute")
+ (expect '(("TEST" ("baz+" "bar+" "foo+")))
+ (anything-test-candidates
+ '(((name . "TEST")
+ (init
+ . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
+ (insert "foo+\nbar+\nbaz+\n"))))
+ (candidates-in-buffer)
+ (search-from-end)))))
+ (expect '(("TEST" ("baz+" "bar+" "foo+")))
+ (anything-test-candidates
+ '(((name . "TEST")
+ (init
+ . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
+ (insert "foo+\nbar+\nbaz+\n"))))
+ (candidates-in-buffer)
+ (search-from-end)))
+ "\\+"))
+ (expect '(("TEST" ("baz+" "bar+")))
+ (anything-test-candidates
+ '(((name . "TEST")
+ (init
+ . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
+ (insert "foo+\nbar+\nbaz+\n"))))
+ (candidates-in-buffer)
+ (search-from-end)
+ (candidate-number-limit . 2)))))
+ (expect '(("TEST" ("baz+" "bar+")))
+ (anything-test-candidates
+ '(((name . "TEST")
+ (init
+ . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
+ (insert "foo+\nbar+\nbaz+\n"))))
+ (candidates-in-buffer)
+ (search-from-end)
+ (candidate-number-limit . 2)))
+ "\\+"))
+
+ (desc "header-name attribute")
+ (expect "original is transformed"
+ (anything-test-update '(((name . "original")
+ (candidates "1")
+ (header-name
+ . (lambda (name)
+ (format "%s is transformed" name)))))
+ "")
+ (with-current-buffer (anything-buffer-get)
+ (buffer-string)
+ (overlay-get (car (overlays-at (1+(point-min)))) 'display)))
+ (desc "volatile and match attribute")
+ ;; candidates function is called once per `anything-process-delayed-sources'
+ (expect 1
+ (let ((v 0))
+ (anything-test-candidates '(((name . "test")
+ (candidates . (lambda () (incf v) '("ok")))
+ (volatile)
+ (match identity identity identity)))
+ "o")
+ v))
+ (desc "accept-empty attribute")
+ (expect nil
+ (anything-test-candidates
+ '(((name . "test") (candidates "") (action . identity))))
+ (anything-execute-selection-action))
+ (expect ""
+ (anything-test-candidates
+ '(((name . "test") (candidates "") (action . identity) (accept-empty))))
+ (anything-execute-selection-action))
+ (desc "anything-tick-hash")
+ (expect nil
+ (with-current-buffer (get-buffer-create " *00create+*")
+ (puthash " *00create+*/xxx" 1 anything-tick-hash)
+ (kill-buffer (current-buffer)))
+ (gethash " *00create+*/xxx" anything-tick-hash))
+ )))
+
+
+(provide 'anything)
+;; How to save (DO NOT REMOVE!!)
+;; (emacswiki-post "anything.el")
+;;; anything.el ends here
--- /dev/null
+;;;; c parameter hints
+(require 'eldoc)
+(require 'etags)
+
+;; make 'function-synopsis a new thing for thing-at-point
+(put 'function-synopsis 'beginning-op
+ (lambda ()
+ (if (bolp) (forward-line -1) (beginning-of-line))
+ (skip-chars-forward "^{")
+ (dotimes (i 3) (backward-sexp))))
+
+(put 'function-synopsis 'end-op
+ (lambda () (skip-chars-forward "^{")))
+
+;; override eldoc-mode's doc printer thingy
+(defadvice eldoc-print-current-symbol-info
+ (around eldoc-show-c-tag activate)
+ (if (eq major-mode 'c-mode)
+ (show-tag-in-minibuffer)
+ ad-do-it))
+
+(defun cleanup-function-synopsis (f)
+ ;; nuke newlines
+ (setq f (replace-regexp-in-string "\n" " " f))
+ ;; nuke comments (note non-greedy *? instead of *)
+ (setq f (replace-regexp-in-string "/\\*.*?\\*/" " " f))
+ ;; (just-one-space)
+ (setq f (replace-regexp-in-string "[ \t]+" " " f))
+ f)
+
+;; fetch a tag, jump to it, grab what looks like a function synopsis,
+;; and output it in the minibuffer.
+(defun show-tag-in-minibuffer ()
+ (when tags-table-list
+ (save-excursion
+ ;; shadow some etags globals so they won't be modified
+ (let ((tags-location-ring (make-ring find-tag-marker-ring-length))
+ (find-tag-marker-ring (make-ring find-tag-marker-ring-length))
+ (last-tag nil))
+ (let* ((tag (funcall
+ (or find-tag-default-function
+ (get major-mode 'find-tag-default-function)
+ 'find-tag-default)))
+ ;; we try to keep M-. from matching any old tag all the
+ ;; time
+ (tag-regex (format "\\(^\\|[ \t\n*]\\)%s\\($\\|(\\)"
+ (regexp-quote tag))))
+ (set-buffer (find-tag-noselect tag-regex nil t))
+ (let ((synopsis (or (thing-at-point 'function-synopsis)
+ (thing-at-point 'line))))
+ (when synopsis
+ (eldoc-message "%s"
+ (cleanup-function-synopsis synopsis)))))))))
+
+;; turn it on
+(add-hook 'c-mode 'turn-on-eldoc-mode)
+;;;; end c parameter hints
--- /dev/null
+;;; cparen.el --- coloured parentheses in Lisp-derived modes
+
+;; Copyright (C) 2001 Riku Saikkonen
+
+;; Author: Riku Saikkonen <Riku.Saikkonen@hut.fi>
+;; Version: 1.0
+;; Keywords: faces lisp
+
+;; This file is *NOT* part of GNU Emacs.
+;;
+;; This program is free software; you can redistribute it and/or
+;; modify it under the terms of the GNU General Public License as
+;; published by the Free Software Foundation; either version 2 of the
+;; License, or (at your option) any later version.
+;;
+;; This program is distributed in the hope that it will be useful, but
+;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+;; General Public License for more details.
+;;
+;; You should have received a copy of the GNU General Public License
+;; along with this program; if not, write to the Free Software
+;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+;; USA
+
+;;; Commentary:
+;;;
+;;; This package makes font-lock more colourful by colouring
+;;; parentheses in Lisp-derived modes. In Lisp mode, the package
+;;; simply makes all parentheses grey (`cparen-normal-paren-face'). In
+;;; Scheme mode, however, parentheses are coloured according to their
+;;; syntactic meaning. Try it and see if you like it.
+;;;
+;;; This package was motivated by the common complaint that Scheme has
+;;; too many different uses for parentheses. I think it will be most
+;;; useful for those who are new to Scheme, though I've also found it
+;;; somewhat useful myself. The package recognises all syntactic forms
+;;; defined in the Scheme standard R5RS.
+;;;
+;;; Activate the package by loading it and running M-x
+;;; cparen-activate. Please note that there is currently no simple way
+;;; to deactivate the package once it has been activated (except for
+;;; restarting Emacs). If you want the package enabled by default,
+;;; place cparen.el somewhere in your `load-path' and put the
+;;; following lines in your ~/.emacs:
+;;; (require 'cparen)
+;;; (cparen-activate)
+;;;
+;;; Here's some example Scheme code that you can try to highlight
+;;; (copy it to a buffer in Scheme mode and uncomment it). This is
+;;; quite contrived code that displays all the colours; you should
+;;; also try highlighting some normal Scheme code.
+;;;
+;;; (define (foo)
+;;; (let ((a 1) (b 2))
+;;; (define (foo a b)
+;;; (let* ((a 2) (b 3) (c 4))
+;;; ((foo 4)
+;;; (bar))
+;;; ((lambda (x y z) (+ x y z)) 1 2 3)
+;;; foo)
+;;; (and fds (let))
+;;; (if 1 (quote 2) '(3 3 #(a b c) 4) 4))
+;;; (cond ((= a 1) 2)
+;;; ((true? b) (+ a 2))
+;;; (else 4))
+;;; (begin (test) 3)
+;;; (set! x 2)
+;;; (case (* 5 2)
+;;; ((1 2 3) 'wrong)
+;;; ((10) 'right))
+;;; (do ((vec (make-vector 5))
+;;; (i 0 (+ i 1)))
+;;; ((= i 5) vec)
+;;; (vector-set! vec i i))
+;;; (let loop ((i 0) (j 1)) (loop 20))
+;;; 5))
+;;;
+;;; (define-syntax begin
+;;; (syntax-rules ()
+;;; ((begin exp ...)
+;;; ((lambda () exp ...)))))
+;;;
+;;; The default colours (specified in the deffaces below) may look
+;;; somewhat better with the following set of font-lock colours (which
+;;; are the ones I use):
+;;;
+;;; (custom-set-faces
+;;; '(font-lock-string-face ((((class color) (background light)) (:foreground "IndianRed4"))))
+;;; '(font-lock-keyword-face ((((class color) (background light)) (:bold t :foreground "ForestGreen"))))
+;;; '(font-lock-constant-face ((((class color) (background light)) (:foreground "RoyalBlue"))))
+;;; '(font-lock-variable-name-face ((((class color) (background light)) (:foreground "Blue"))))
+;;; '(font-lock-function-name-face ((((class color) (background light)) (:bold t :foreground "Blue"))))
+;;; '(font-lock-builtin-face ((((class color) (background light)) (:bold t :foreground "RoyalBlue")))))
+
+;;; Change Log:
+;;; $Id: cparen.el,v 1.7 2001/03/27 20:54:54 rjs Exp $
+;;;
+;;; Version 1.0 (March 27th, 2001)
+;;; * Initial release.
+
+;;; Todo:
+;;; * colouring support for Emacs Lisp and Common Lisp
+;;; * a function to deactivate the package (or a cparen minor mode;
+;;; the problem is that there is no simple complement to the
+;;; function `font-lock-add-keywords')
+;;; * `cparen-activate' doesn't affect the colouring of existing
+;;; buffers (workaround: use M-x normal-mode on them)
+;;; * user-customisable syntax; for example, make it easy for the
+;;; user to add a new let-like form
+
+;;; Code:
+
+(require 'font-lock)
+
+;;;; Customisable faces
+
+(defgroup cparen-highlighting-faces nil
+ "Faces for parentheses in cparen mode."
+ :group 'font-lock)
+
+(defface cparen-around-define-face
+ '((t (:bold t :foreground "Blue")))
+ "Face used around a define or define-syntax expression."
+ :group 'cparen-highlighting-faces)
+
+(defface cparen-around-lambda-face
+ '((t (:foreground "LightSeaGreen")))
+ "Face used around a lambda expression."
+ :group 'cparen-highlighting-faces)
+
+(defface cparen-around-quote-face
+ '((t (:foreground "SaddleBrown")))
+ "Face used around a quote or quasiquote expression."
+ :group 'cparen-highlighting-faces)
+
+(defface cparen-around-vector-face
+ '((t (:foreground "chocolate")))
+ "Face used around vector constants."
+ :group 'cparen-highlighting-faces)
+
+(defface cparen-around-letdo-face
+ '((t (:bold t :foreground "LightSeaGreen")))
+ "Face used around a let or do expression."
+ :group 'cparen-highlighting-faces)
+
+(defface cparen-binding-list-face
+ '((t (:bold t :foreground "ForestGreen")))
+ "Face surrounding lists of bindings."
+ :group 'cparen-highlighting-faces)
+
+(defface cparen-binding-face
+ '((t (:foreground "ForestGreen")))
+ "Face surrounding individual bindings."
+ :group 'cparen-highlighting-faces)
+
+(defface cparen-around-conditional-face
+ '((t (:bold t :foreground "RoyalBlue")))
+ "Face used around a conditional expression (if/cond/case)."
+ :group 'cparen-highlighting-faces)
+
+(defface cparen-conditional-clause-face
+ '((t (:foreground "RoyalBlue")))
+ "Face surrounding clauses in conditionals."
+ :group 'cparen-highlighting-faces)
+
+(defface cparen-around-begin-face
+ '((t (:foreground "maroon")))
+ "Face used around a begin expression."
+ :group 'cparen-highlighting-faces)
+
+(defface cparen-around-set!-face
+ '((t (:foreground "OrangeRed")))
+ "Face used around a set! expression."
+ :group 'cparen-highlighting-faces)
+
+(defface cparen-around-andor-face
+ '((t (:bold t :foreground "maroon")))
+ "Face used around an \"and\" or \"or\" expression."
+ :group 'cparen-highlighting-faces)
+
+(defface cparen-around-syntax-rules-face
+ '((t (:foreground "Magenta")))
+ "Face used around a syntax-rules expression."
+ :group 'cparen-highlighting-faces)
+
+(defface cparen-normal-paren-face
+ '((t (:foreground "grey50")))
+ "Face for normal parentheses in Lisp code."
+ :group 'cparen-highlighting-faces)
+
+;;;; Variables
+
+(defvar cparen-font-lock-keywords
+ '(("(" (0 (cparen-opening-paren-face)))
+ (")" (0 (cparen-closing-paren-face))))
+ "Font lock keywords to enable cparen mode.
+`cparen-activate' adds these using `font-lock-add-keywords'
+for Scheme mode.")
+
+(defvar cparen-mini-font-lock-keywords
+ '(("[()]" 0 'cparen-normal-paren-face))
+ "Font lock keywords to enable paren highlight.
+`cparen-activate' adds these using `font-lock-add-keywords'
+for Lisp mode.
+By default, they highlight all parentheses with the face
+`cparen-normal-paren-face'.")
+
+;;;; Functions
+
+(defsubst cparen-get-face-internal ()
+ "Internal cparen face finder.
+Finds the face of an opening parenthesis before point, moving point.
+Should be wrapped in `condition-case' and `save-excursion'. Please use
+`cparen-opening-paren-face' instead of this, if you can."
+ (or (if (looking-at "\\(let\\|do\\>\\)") 'cparen-around-letdo-face)
+ (if (looking-at "begin\\>") 'cparen-around-begin-face)
+ (if (looking-at "\\(cond\\>\\|if\\>\\|case\\>\\)")
+ 'cparen-around-conditional-face)
+ (if (looking-at "\\(and\\>\\|or\\>\\)") 'cparen-around-andor-face)
+ (if (looking-at "set!\\>") 'cparen-around-set!-face)
+ (if (looking-at "\\(quote\\>\\|quasiquote\\>\\)")
+ 'cparen-around-quote-face)
+ (if (looking-at "define") 'cparen-around-define-face)
+ (if (looking-at "lambda\\>") 'cparen-around-lambda-face)
+ (if (looking-at "syntax-rules\\>") 'cparen-around-syntax-rules-face)
+ (condition-case nil
+ (or (save-excursion
+ (backward-char 2)
+ (if (looking-at "[`']") 'cparen-around-quote-face
+ (if (looking-at "#") 'cparen-around-vector-face)))
+ (progn
+ (backward-up-list 1)
+ (backward-sexp 1)
+ (or (if (looking-at "\\(let\\|lambda\\>\\|define\\|do\\>\\)")
+ 'cparen-binding-list-face)
+ (if (looking-at "\\(case\\>\\|syntax-rules\\>\\)")
+ 'cparen-normal-paren-face)
+ (let ((atparen (looking-at "[([{]")))
+ (backward-sexp 1)
+ (if (or (looking-at "do\\>")
+ (and (not atparen) (looking-at "let")))
+ 'cparen-binding-list-face)))))
+ (error nil))
+ (progn
+ (backward-up-list 1)
+ (forward-char 1)
+ (if (looking-at "\\(cond\\>\\|case\\>\\)")
+ 'cparen-conditional-clause-face))
+ (if (looking-at "syntax-rules\\>") 'cparen-conditional-clause-face)
+ (progn
+ (backward-up-list 1)
+ (backward-sexp 1)
+ (if (looking-at "\\(let\\|do\\>\\)") 'cparen-binding-face))
+ (let ((atparen (looking-at "[([{]")))
+ (backward-sexp 1)
+ (if (and (not atparen) (looking-at "let"))
+ 'cparen-binding-face))
+ 'cparen-normal-paren-face))
+
+(defun cparen-opening-paren-face ()
+ "Find the face of an opening parenthesis before point.
+Uses `cparen-get-face-internal'."
+ (condition-case nil
+ (save-excursion
+ (cparen-get-face-internal))
+ (error 'cparen-normal-paren-face)))
+
+(defun cparen-closing-paren-face ()
+ "Find the face of a closing parenthesis before point.
+Uses `cparen-get-face-internal'."
+ (condition-case nil
+ (save-excursion
+ (backward-list 1) ; move to corresponding
+ (forward-char 1) ; opening paren
+ (cparen-get-face-internal))
+ (error 'cparen-normal-paren-face)))
+
+;;;; Installation
+
+(defun cparen-activate ()
+ "Activate coloured parentheses in Lisp modes.
+You should also enable `font-lock-mode'.
+Please note that there is currently no way to disable cparen, except
+by turning `font-lock-mode' off completely.
+Also, this function affects only buffers created after it was run;
+use \\[normal-mode] after this to enable the colours in an existing
+buffer."
+ (interactive)
+ (mapcar (lambda (mode)
+ (font-lock-add-keywords mode cparen-font-lock-keywords))
+ '(scheme-mode inferior-scheme-mode))
+ (mapcar (lambda (mode)
+ (font-lock-add-keywords mode cparen-mini-font-lock-keywords))
+ '(emacs-lisp-mode lisp-mode lisp-interaction-mode
+ inferior-lisp-mode)))
+
+(provide 'cparen)
+
+;;; cparen.el ends here
--- /dev/null
+;;; descbinds-anything.el --- Yet Another `describe-bindings' with `anything'.
+
+;; Copyright (C) 2008 Taiki SUGAWARA <buzz.taiki@gmail.com>
+
+;; Author: Taiki SUGAWARA <buzz.taiki@gmail.com>
+;; Keywords: anything, help
+;; Version: 1.02
+;; Time-stamp: <2008-11-16 14:06:02 UTC taiki>
+;; URL: http://www.emacswiki.org/cgi-bin/wiki/descbinds-anything.el
+
+;; This file is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation; either version 3, or (at your option)
+;; any later version.
+
+;; This file is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs; see the file COPYING. If not, write to
+;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
+
+;;; Commentary:
+;; This package is a replacement of `describe-bindings'.
+
+;;; Usage:
+;; Add followings on your .emacs.
+;;
+;; (require 'descbinds-anything)
+;; (descbinds-anything-install)
+;;
+;; Now, `describe-bindings' is replaced to `descbinds-anything'. Type `C-h b',
+;; `C-x C-h' these run `descbinds-anything'.
+;;
+;; In the Anything buffer, you can select key-binds with anything interface.
+;; When type RET, selected candidate command is executed.
+;; When type ESC, You can "Execute", "Describe Function" or "Find Function" by
+;; the menu.
+
+;;; History:
+;; 2008-11-16 UTC Taiki SUGAWARA <buzz.taiki@gmail.com>
+;;
+;; * descbinds-anything.el: Version 1.02
+;; bound `indent-tabs-mode` to t for nil environment.
+;;
+;; 2008-11-16 UTC Taiki SUGAWARA <buzz.taiki@gmail.com>
+;;
+;; * descbinds-anything.el: fix infinitive-loop when binding-line
+;; has not tab.
+
+;;; Code:
+
+(require 'anything)
+
+(defgroup descbinds-anything nil
+ "Yet Another `describe-bindings' with `anything'.")
+
+(defcustom descbinds-anything-actions
+ '(("Execute" . descbinds-anything-action:execute)
+ ("Describe Function" . descbinds-anything-action:describe)
+ ("Find Function" . descbinds-anything-action:find-func))
+ "Actions of selected candidate."
+ :type '(repeat
+ :tag "Actions"
+ (cons
+ :tag "Action"
+ (string :tag "Name")
+ (function :tag "Function"))))
+
+(defcustom descbinds-anything-candidate-formatter
+ 'descbinds-anything-default-candidate-formatter
+ "Candidate formatter function.
+This function called two argument KEY and BINDING."
+ :type '(function :tag "Formatter"))
+
+(defcustom descbinds-anything-window-style 'one-window
+ "Window splitting style."
+ :type '(choice
+ :tag "Styles"
+ (const :tag "One Window" one-window)
+ (const :tag "Same Window" same-window)
+ (const :tag "Split Window" split-window)))
+
+(defun descbinds-anything-all-sections (buffer &optional prefix menus)
+ (with-temp-buffer
+ (let ((indent-tabs-mode t))
+ (describe-buffer-bindings buffer prefix menus))
+ (goto-char (point-min))
+ (let ((header-p (not (= (char-after) ?\f)))
+ sections header section)
+ (while (not (eobp))
+ (cond
+ (header-p
+ (setq header (buffer-substring-no-properties (point) (line-end-position)))
+ (setq header-p nil)
+ (forward-line 3))
+ ((= (char-after) ?\f)
+ (push (cons header (nreverse section)) sections)
+ (setq section nil)
+ (setq header-p t))
+ ((looking-at "^[ \t]*$")
+ ;; ignore
+ )
+ (t
+ (let ((binding-start (save-excursion
+ (and (re-search-forward "\t+" nil t)
+ (match-end 0))))
+ key binidng)
+ (when binding-start
+ (setq key (buffer-substring-no-properties (point) binding-start)
+ key (replace-regexp-in-string"^[ \t\n]+" "" key)
+ key (replace-regexp-in-string"[ \t\n]+$" "" key))
+ (goto-char binding-start)
+ (setq binding (buffer-substring-no-properties binding-start (line-end-position)))
+ (unless (member binding '("self-insert-command"))
+ (push (cons key binding) section))))))
+ (forward-line))
+ (push (cons header (nreverse section)) sections)
+ (nreverse sections))))
+
+(defun descbinds-anything-action:execute (candidate)
+ "An action that execute selected CANDIDATE command."
+ (call-interactively (cdr candidate)))
+
+(defun descbinds-anything-action:describe (candidate)
+ "An action that describe selected CANDIDATE function."
+ (describe-function (cdr candidate)))
+
+(defun descbinds-anything-action:find-func (candidate)
+ "An action that find selected CANDIDATE function."
+ (find-function (cdr candidate)))
+
+(defun descbinds-anything-default-candidate-formatter (key binding)
+ "Default candidate formatter."
+ (format "%-10s\t%s" key binding))
+
+(defun descbinds-anything-sources (buffer &optional prefix menus)
+ (mapcar
+ (lambda (section)
+ (list
+ (cons 'name (car section))
+ (cons 'candidates (cdr section))
+ (cons 'candidate-transformer
+ (lambda (candidates)
+ (mapcar
+ (lambda (pair)
+ (cons (funcall descbinds-anything-candidate-formatter
+ (car pair) (cdr pair))
+ (cons (car pair)
+ (intern-soft (cdr pair)))))
+ candidates)))
+ (cons 'action descbinds-anything-actions)
+ (cons 'action-transformer
+ (lambda (actions candidate)
+ (and (commandp (cdr candidate))
+ actions)))))
+ (descbinds-anything-all-sections buffer prefix menus)))
+
+(defun descbinds-anything (&optional prefix buffer)
+ "Yet Another `describe-bindings' with `anything'."
+ (interactive)
+ (let ((anything-sources (descbinds-anything-sources
+ (or buffer (current-buffer))
+ prefix nil))
+ (anything-samewindow (and (not (minibufferp))
+ (memq descbinds-anything-window-style
+ '(same-window one-window))))
+ (anything-before-initialize-hook
+ (if (and (not (minibufferp))
+ (eq descbinds-anything-window-style 'one-window))
+ (cons 'delete-other-windows anything-before-initialize-hook)
+ anything-before-initialize-hook)))
+ (anything)))
+
+(defvar descbinds-anything-Orig-describe-bindings
+ (symbol-function 'describe-bindings))
+
+(defun descbinds-anything-install ()
+ "Use `descbinds-anything' as a replacement of `describe-bindings'."
+ (interactive)
+ (fset 'describe-bindings 'descbinds-anything))
+
+(defun descbinds-anything-uninstall ()
+ "Restore original `describe-bindings'."
+ (interactive)
+ (fset 'describe-bindings descbinds-anything-Orig-describe-bindings))
+
+(provide 'descbinds-anything)
+;;; descbinds-anything.el ends here
--- /dev/null
+;;; linum.el --- Display line numbers to the left of buffers
+
+;; Copyright (C) 2007, 2008 Markus Triska
+
+;; Author: Markus Triska <markus.triska@gmx.at>
+;; Keywords: convenience
+
+;; This file is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation; either version 3, or (at your option)
+;; any later version.
+
+;; This file is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs; see the file COPYING. If not, write to
+;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
+
+;;; Commentary:
+
+;; Display line numbers for the current buffer. Copy linum.el to your
+;; load-path and add to your .emacs:
+
+;; (require 'linum)
+
+;; Then toggle display of line numbers with M-x linum-mode. To enable
+;; line numbering in all buffers, use M-x global-linum-mode.
+
+;;; Code:
+
+(defconst linum-version "0.9wza")
+
+(defvar linum-overlays nil "Overlays used in this buffer.")
+(defvar linum-available nil "Overlays available for reuse.")
+(defvar linum-before-numbering-hook nil
+ "Functions run in each buffer before line numbering starts.")
+
+(mapc #'make-variable-buffer-local '(linum-overlays linum-available))
+
+(defgroup linum nil
+ "Show line numbers to the left of buffers"
+ :group 'convenience)
+
+;;;###autoload
+(defcustom linum-format 'dynamic
+ "Format used to display line numbers. Either a format string
+like \"%7d\", 'dynamic to adapt the width as needed, or a
+function that is called with a line number as its argument and
+should evaluate to a string to be shown on that line. See also
+`linum-before-numbering-hook'."
+ :group 'linum
+ :type 'sexp)
+
+(defface linum
+ '((t :inherit (shadow default)))
+ "Face for displaying line numbers in the display margin."
+ :group 'linum)
+
+(defcustom linum-eager t
+ "Whether line numbers should be updated after each command.
+The conservative setting `nil' might miss some buffer changes,
+and you have to scroll or press C-l to update the numbers."
+ :group 'linum
+ :type 'boolean)
+
+(defcustom linum-delay nil
+ "Delay updates to give Emacs a chance for other changes."
+ :group 'linum
+ :type 'boolean)
+
+;;;###autoload
+(define-minor-mode linum-mode
+ "Toggle display of line numbers in the left marginal area."
+ :lighter "" ; for desktop.el
+ (if linum-mode
+ (progn
+ (if linum-eager
+ (add-hook 'post-command-hook (if linum-delay
+ 'linum-schedule
+ 'linum-update-current) nil t)
+ (add-hook 'after-change-functions 'linum-after-change nil t))
+ (add-hook 'window-scroll-functions 'linum-after-scroll nil t)
+ ;; mistake in Emacs: window-size-change-functions cannot be local
+ (add-hook 'window-size-change-functions 'linum-after-size)
+ (add-hook 'change-major-mode-hook 'linum-delete-overlays nil t)
+ (add-hook 'window-configuration-change-hook
+ 'linum-after-config nil t)
+ (linum-update-current))
+ (remove-hook 'post-command-hook 'linum-update-current t)
+ (remove-hook 'post-command-hook 'linum-schedule t)
+ (remove-hook 'window-size-change-functions 'linum-after-size)
+ (remove-hook 'window-scroll-functions 'linum-after-scroll t)
+ (remove-hook 'after-change-functions 'linum-after-change t)
+ (remove-hook 'window-configuration-change-hook 'linum-after-config t)
+ (remove-hook 'change-major-mode-hook 'linum-delete-overlays t)
+ (linum-delete-overlays)))
+
+;;;###autoload
+(define-globalized-minor-mode global-linum-mode linum-mode linum-on)
+
+(defun linum-on ()
+ (unless (minibufferp)
+ (linum-mode 1)))
+
+(defun linum-delete-overlays ()
+ "Delete all overlays displaying line numbers for this buffer."
+ (mapc #'delete-overlay linum-overlays)
+ (setq linum-overlays nil)
+ (dolist (w (get-buffer-window-list (current-buffer) nil t))
+ (set-window-margins w 0)))
+
+(defun linum-update-current ()
+ "Update line numbers for the current buffer."
+ (linum-update (current-buffer)))
+
+(defun linum-update (buffer)
+ "Update line numbers for all windows displaying BUFFER."
+ (with-current-buffer buffer
+ (when linum-mode
+ (setq linum-available linum-overlays)
+ (setq linum-overlays nil)
+ (save-excursion
+ (mapc #'linum-update-window
+ (get-buffer-window-list buffer nil 'visible)))
+ (mapc #'delete-overlay linum-available)
+ (setq linum-available nil))))
+
+(defun linum-update-window (win)
+ "Update line numbers for the portion visible in window WIN."
+ (goto-char (window-start win))
+ (let ((line (line-number-at-pos))
+ (limit (window-end win t))
+ (fmt (cond ((stringp linum-format) linum-format)
+ ((eq linum-format 'dynamic)
+ (let ((w (length (number-to-string
+ (count-lines (point-min) (point-max))))))
+ (concat "%" (number-to-string w) "d")))))
+ (width 0))
+ (run-hooks 'linum-before-numbering-hook)
+ ;; Create an overlay (or reuse an existing one) for each
+ ;; line visible in this window, if necessary.
+ (while (and (not (eobp)) (<= (point) limit))
+ (let* ((str (if fmt
+ (propertize (format fmt line) 'face 'linum)
+ (funcall linum-format line)))
+ (visited (catch 'visited
+ (dolist (o (overlays-in (point) (point)))
+ (when (string= (overlay-get o 'linum-str) str)
+ (unless (memq o linum-overlays)
+ (push o linum-overlays))
+ (setq linum-available (delete o linum-available))
+ (throw 'visited t))))))
+ (setq width (max width (length str)))
+ (unless visited
+ (let ((ov (if (null linum-available)
+ (make-overlay (point) (point))
+ (move-overlay (pop linum-available) (point) (point)))))
+ (push ov linum-overlays)
+ (overlay-put ov 'before-string
+ (propertize " " 'display `((margin left-margin) ,str)))
+ (overlay-put ov 'linum-str str))))
+ (forward-line)
+ (setq line (1+ line)))
+ (set-window-margins win width)))
+
+(defun linum-after-change (beg end len)
+ ;; update overlays on deletions, and after newlines are inserted
+ (when (or (= beg end)
+ (= end (point-max))
+ ;; TODO: use string-match-p with CVS or new release
+ (string-match "\n" (buffer-substring-no-properties beg end)))
+ (linum-update-current)))
+
+(defun linum-after-scroll (win start)
+ (linum-update (window-buffer win)))
+
+(defun linum-after-size (frame)
+ (linum-after-config))
+
+(defun linum-schedule ()
+ ;; schedule an update; the delay gives Emacs a chance for display changes
+ (run-with-idle-timer 0 nil #'linum-update-current))
+
+(defun linum-after-config ()
+ (walk-windows (lambda (w) (linum-update (window-buffer w))) nil 'visible))
+
+(provide 'linum)
+;;; linum.el ends here
--- /dev/null
+;; modalshortcuts.el - a simple minor mode to use modal shortcuts.
+
+(setq modal-mode-keymap (make-sparse-keymap))
+
+(global-set-key (kbd "<S-f9>") modal-mode-keymap)
+
+(define-key modal-mode-keymap "i" 'indent-region)
+(define-key modal-mode-keymap "v" 'info)
+(define-key modal-mode-keymap "w" 'save-buffer)
+(define-key modal-mode-keymap "t" 'find-tag)
+(define-key modal-mode-keymap "q" 'save-buffers-kill-emacs)
+(define-key modal-mode-keymap "d" 'delete-other-windows)
+(define-key modal-mode-keymap "u" 'advertised-undo)
+(define-key modal-mode-keymap "a" 'ffap)
+(define-key modal-mode-keymap "g" 'keyboard-quit)
+(define-key modal-mode-keymap "f" 'find-file)
+(define-key modal-mode-keymap "b" 'ido-switch-buffer)
+(define-key modal-mode-keymap "k" 'kill-buffer)
+(define-key modal-mode-keymap "o" 'other-window)
+(define-key modal-mode-keymap "e" 'kmacro-end-and-call-macro)
+(define-key modal-mode-keymap "(" 'kmacro-start-macro)
+(define-key modal-mode-keymap ")" 'kmacro-end-macro)
--- /dev/null
+;;; psvn.el --- Subversion interface for emacs
+;; Copyright (C) 2002-2008 by Stefan Reichoer
+
+;; Author: Stefan Reichoer <stefan@xsteve.at>
+;; $Id: psvn.el 33557 2008-10-08 20:01:12Z xsteve $
+
+;; psvn.el is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation; either version 2, or (at your option)
+;; any later version.
+
+;; psvn.el 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; see the file COPYING. If not, write to
+;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+;; Boston, MA 02111-1307, USA.
+
+;;; Commentary
+
+;; psvn.el is tested with GNU Emacs 21.3 on windows, debian linux,
+;; freebsd5, red hat el4, ubuntu edgy with svn 1.4.0
+
+;; psvn.el needs at least svn 1.1.0
+;; if you upgrade to a higher version, you need to do a fresh checkout
+
+;; psvn.el is an interface for the revision control tool subversion
+;; (see http://subversion.tigris.org)
+;; psvn.el provides a similar interface for subversion as pcl-cvs for cvs.
+;; At the moment the following commands are implemented:
+;;
+;; M-x svn-status: run 'svn -status -v'
+;; M-x svn-examine (like pcl-cvs cvs-examine) is alias for svn-status
+;;
+;; and show the result in the svn-status-buffer-name buffer (normally: *svn-status*).
+;; If svn-status-verbose is set to nil, only "svn status" without "-v"
+;; is run. Currently you have to toggle this variable manually.
+;; This buffer uses svn-status mode in which the following keys are defined:
+;; g - svn-status-update: run 'svn status -v'
+;; M-s - svn-status-update: run 'svn status -v'
+;; C-u g - svn-status-update: run 'svn status -vu'
+;; = - svn-status-show-svn-diff run 'svn diff'
+;; l - svn-status-show-svn-log run 'svn log'
+;; i - svn-status-info run 'svn info'
+;; r - svn-status-revert run 'svn revert'
+;; X v - svn-status-resolved run 'svn resolved'
+;; U - svn-status-update-cmd run 'svn update'
+;; M-u - svn-status-update-cmd run 'svn update'
+;; c - svn-status-commit run 'svn commit'
+;; a - svn-status-add-file run 'svn add --non-recursive'
+;; A - svn-status-add-file-recursively run 'svn add'
+;; + - svn-status-make-directory run 'svn mkdir'
+;; R - svn-status-mv run 'svn mv'
+;; C - svn-status-cp run 'svn cp'
+;; D - svn-status-rm run 'svn rm'
+;; M-c - svn-status-cleanup run 'svn cleanup'
+;; k - svn-status-lock run 'svn lock'
+;; K - svn-status-unlock run 'svn unlock'
+;; b - svn-status-blame run 'svn blame'
+;; X e - svn-status-export run 'svn export'
+;; RET - svn-status-find-file-or-examine-directory
+;; ^ - svn-status-examine-parent
+;; ~ - svn-status-get-specific-revision
+;; E - svn-status-ediff-with-revision
+;; X X - svn-status-resolve-conflicts
+;; S g - svn-status-grep-files
+;; S s - svn-status-search-files
+;; s - svn-status-show-process-buffer
+;; h - svn-status-pop-to-partner-buffer
+;; e - svn-status-toggle-edit-cmd-flag
+;; ? - svn-status-toggle-hide-unknown
+;; _ - svn-status-toggle-hide-unmodified
+;; m - svn-status-set-user-mark
+;; u - svn-status-unset-user-mark
+;; $ - svn-status-toggle-elide
+;; w - svn-status-copy-current-line-info
+;; DEL - svn-status-unset-user-mark-backwards
+;; * ! - svn-status-unset-all-usermarks
+;; * ? - svn-status-mark-unknown
+;; * A - svn-status-mark-added
+;; * M - svn-status-mark-modified
+;; * P - svn-status-mark-modified-properties
+;; * D - svn-status-mark-deleted
+;; * * - svn-status-mark-changed
+;; * . - svn-status-mark-by-file-ext
+;; * % - svn-status-mark-filename-regexp
+;; * s - svn-status-store-usermarks
+;; * l - svn-status-load-usermarks
+;; . - svn-status-goto-root-or-return
+;; f - svn-status-find-file
+;; o - svn-status-find-file-other-window
+;; C-o - svn-status-find-file-other-window-noselect
+;; v - svn-status-view-file-other-window
+;; I - svn-status-parse-info
+;; V - svn-status-svnversion
+;; P l - svn-status-property-list
+;; P s - svn-status-property-set
+;; P d - svn-status-property-delete
+;; P e - svn-status-property-edit-one-entry
+;; P i - svn-status-property-ignore-file
+;; P I - svn-status-property-ignore-file-extension
+;; P C-i - svn-status-property-edit-svn-ignore
+;; P k - svn-status-property-set-keyword-list
+;; P K i - svn-status-property-set-keyword-id
+;; P K d - svn-status-property-set-keyword-date
+;; P y - svn-status-property-set-eol-style
+;; P x - svn-status-property-set-executable
+;; P m - svn-status-property-set-mime-type
+;; H - svn-status-use-history
+;; x - svn-status-update-buffer
+;; q - svn-status-bury-buffer
+
+;; C-x C-j - svn-status-dired-jump
+
+;; The output in the buffer contains this header to ease reading
+;; of svn output:
+;; FPH BASE CMTD Author em File
+;; F = Filemark
+;; P = Property mark
+;; H = History mark
+;; BASE = local base revision
+;; CMTD = last committed revision
+;; Author = author of change
+;; em = "**" or "(Update Available)" [see `svn-status-short-mod-flag-p']
+;; if file can be updated
+;; File = path/filename
+;;
+
+;; To use psvn.el put the following line in your .emacs:
+;; (require 'psvn)
+;; Start the svn interface with M-x svn-status
+
+;; The latest version of psvn.el can be found at:
+;; http://www.xsteve.at/prg/emacs/psvn.el
+;; Or you can check it out from the subversion repository:
+;; svn co http://svn.collab.net/repos/svn/trunk/contrib/client-side/emacs emacs-svn
+
+;; TODO:
+;; * shortcut for svn propset svn:keywords "Date" psvn.el
+;; * docstrings for the functions
+;; * perhaps shortcuts for ranges, dates
+;; * when editing the command line - offer help from the svn client
+;; * finish svn-status-property-set
+;; * Add repository browser
+;; * Get rid of all byte-compiler warnings
+;; * SVK working copy support
+;; * multiple independent buffers in svn-status-mode
+;; There are "TODO" comments in other parts of this file as well.
+
+;; Overview over the implemented/not (yet) implemented svn sub-commands:
+;; * add implemented
+;; * blame implemented
+;; * cat implemented
+;; * checkout (co) implemented
+;; * cleanup implemented
+;; * commit (ci) implemented
+;; * copy (cp) implemented
+;; * delete (del, remove, rm) implemented
+;; * diff (di) implemented
+;; * export implemented
+;; * help (?, h)
+;; * import used (in svn-admin-create-trunk-directory)
+;; * info implemented
+;; * list (ls) implemented
+;; * lock implemented
+;; * log implemented
+;; * merge
+;; * mkdir implemented
+;; * move (mv, rename, ren) implemented
+;; * propdel (pdel) implemented
+;; * propedit (pedit, pe) not needed
+;; * propget (pget, pg) used (in svn-status-property-edit)
+;; * proplist (plist, pl) implemented
+;; * propset (pset, ps) used (in svn-prop-edit-do-it)
+;; * resolved implemented
+;; * revert implemented
+;; * status (stat, st) implemented
+;; * switch (sw)
+;; * unlock implemented
+;; * update (up) implemented
+
+;; For the not yet implemented commands you should use the command line
+;; svn client. If there are user requests for any missing commands I will
+;; probably implement them.
+
+;; There is also limited support for the web-based software project management and bug/issue tracking system trac
+;; Trac ticket links can be enabled in the *svn-log* buffers when using the following:
+;; (setq svn-log-link-handlers '(trac-ticket-short))
+
+;; ---------------------------
+;; Frequently asked questions:
+;; ---------------------------
+
+;; Q1: I need support for user names with blanks/spaces
+;; A1: Add the user names to svn-user-names-including-blanks and set the
+;; svn-pre-parse-status-hook.
+;; The problem is, that the user names and the file names from the svn status
+;; output can both contain blanks. Blanks in file names are supported.
+;; the svn-user-names-including-blanks list is used to replace the spaces
+;; in the user names with - to overcome this problem
+
+;; Q2: My svn-update command it taking a really long time. How can I
+;; see what's going on?
+;; A2: In the *svn-status* buffer press "s".
+
+;; Q3: How do I enter a username and password?
+;; A3: In the *svn-status* buffer press "s", switch to the
+;; *svn-process* buffer and press enter. You will be prompted for
+;; username and password.
+
+;; Q4: What does "?", "M", and "C" in the first column of the
+;; *svn-status* buffer mean?
+;; A4: "?" means the file(s) is not under Subversion control
+;; "M" means you have a locally modified file
+;; "C" means there is a conflict
+;; "@$&#!" means someone is saying nasty things to you
+
+
+;; Comments / suggestions and bug reports are welcome!
+
+;; Development notes
+;; -----------------
+
+;; "svn-" is the package prefix used in psvn.el. There are also longer
+;; prefixes which clarify the code and help symbol completion, but they
+;; are not intended to prevent name clashes with other packages. All
+;; interactive commands meant to be used only in a specific mode should
+;; have names beginning with the name of that mode: for example,
+;; "svn-status-add-file" in "svn-status-mode". "psvn" should be used
+;; only in names of files, customization groups, and features. If SVK
+;; support is ever added, it should use "svn-svk-" when no existing
+;; prefix is applicable.
+
+;; Many of the variables marked as `risky-local-variable' are probably
+;; impossible to abuse, as the commands that read them are used only in
+;; buffers that are not visiting any files. Better safe than sorry.
+
+;;; Code:
+
+(require 'easymenu)
+
+(eval-when-compile (require 'dired))
+(eval-when-compile (require 'ediff-util))
+(eval-when-compile (require 'ediff-wind))
+(eval-when-compile (require 'elp))
+(eval-when-compile (require 'pp))
+
+(condition-case nil
+ (progn
+ (require 'diff-mode))
+ (error nil))
+
+(defconst svn-psvn-revision "$Id: psvn.el 33557 2008-10-08 20:01:12Z xsteve $"
+ "The revision number of psvn.")
+
+;;; user setable variables
+(defcustom svn-status-verbose t
+ "*Add '-v' to svn status call.
+This can be toggled with \\[svn-status-toggle-svn-verbose-flag]."
+ :type 'boolean
+ :group 'psvn)
+(defcustom svn-log-edit-file-name "++svn-log++"
+ "*Name of a saved log file.
+This can be either absolute, or relative to the default directory
+of the `svn-log-edit-buffer-name' buffer."
+ :type 'file
+ :group 'psvn)
+(put 'svn-log-edit-file-name 'risky-local-variable t)
+(defcustom svn-log-edit-insert-files-to-commit t
+ "*Insert the filelist to commit in the *svn-log* buffer"
+ :type 'boolean
+ :group 'psvn)
+(defcustom svn-log-edit-show-diff-for-commit nil
+ "*Show the diff being committed when you run `svn-status-commit.'."
+ :type 'boolean
+ :group 'psvn)
+(defcustom svn-log-edit-use-log-edit-mode
+ (and (condition-case nil (require 'log-edit) (error nil)) t)
+ "*Use log-edit-mode as base for svn-log-edit-mode
+This variable takes effect only when psvn.el is being loaded."
+ :type 'boolean
+ :group 'psvn)
+(defcustom svn-log-edit-paragraph-start
+ "$\\|[ \t]*$\\|##.*$\\|\\*.*:.*$\\|[ \t]+(.+):.*$"
+ "*Value used for `paragraph-start' in `svn-log-edit-buffer-name' buffer."
+ :type 'regexp
+ :group 'psvn)
+(defcustom svn-log-edit-paragraph-separate "$\\|##.*$"
+ "*Value used for `paragraph-separate' in `svn-log-edit-buffer-name' buffer."
+ :type 'regexp
+ :group 'psvn)
+(defcustom svn-status-hide-unknown nil
+ "*Hide unknown files in `svn-status-buffer-name' buffer.
+This can be toggled with \\[svn-status-toggle-hide-unknown]."
+ :type 'boolean
+ :group 'psvn)
+(defcustom svn-status-hide-unmodified nil
+ "*Hide unmodified files in `svn-status-buffer-name' buffer.
+This can be toggled with \\[svn-status-toggle-hide-unmodified]."
+ :type 'boolean
+ :group 'psvn)
+(defcustom svn-status-sort-status-buffer t
+ "*Whether to sort the `svn-status-buffer-name' buffer.
+
+Setting this variable to nil speeds up \\[M-x svn-status], however the
+listing may then become incorrect.
+
+This can be toggled with \\[svn-status-toggle-sort-status-buffer]."
+ :type 'boolean
+ :group 'psvn)
+
+(defcustom svn-status-ediff-delete-temporary-files nil
+ "*Whether to delete temporary ediff files. If set to ask, ask the user"
+ :type '(choice (const t)
+ (const nil)
+ (const ask))
+ :group 'psvn)
+
+(defcustom svn-status-changelog-style 'changelog
+ "*The changelog style that is used for `svn-file-add-to-changelog'.
+Possible values are:
+ 'changelog: use `add-change-log-entry-other-window'
+ 'svn-dev: use commit messages that are used by the svn developers
+ a function: This function is called to add a new entry to the changelog file.
+"
+ :type '(set (const changelog)
+ (const svn-dev))
+ :group 'psvn)
+
+(defcustom svn-status-unmark-files-after-list '(commit revert)
+ "*List of operations after which all user marks will be removed.
+Possible values are: commit, revert."
+ :type '(set (const commit)
+ (const revert))
+ :group 'psvn)
+
+(defcustom svn-status-preserve-window-configuration t
+ "*Try to preserve the window configuration."
+ :type 'boolean
+ :group 'psvn)
+
+(defcustom svn-status-auto-revert-buffers t
+ "*Auto revert buffers that have changed on disk."
+ :type 'boolean
+ :group 'psvn)
+
+(defcustom svn-status-fancy-file-state-in-modeline t
+ "*Show a color dot in the modeline that describes the state of the current file."
+ :type 'boolean
+ :group 'psvn)
+
+(defcustom svn-status-negate-meaning-of-arg-commands '()
+ "*List of operations that should use a negated meaning of the prefix argument.
+The supported functions are `svn-status' and `svn-status-set-user-mark'."
+ :type '(set (function-item svn-status)
+ (function-item svn-status-set-user-mark))
+ :group 'psvn)
+
+(defcustom svn-status-svn-executable "svn"
+ "*The name of the svn executable.
+This can be either absolute or looked up on `exec-path'."
+ ;; Don't use (file :must-match t). It doesn't know about `exec-path'.
+ :type 'file
+ :group 'psvn)
+(put 'svn-status-svn-executable 'risky-local-variable t)
+
+(defcustom svn-status-default-export-directory "~/" "*The default directory that is suggested svn export."
+ :type 'file
+ :group 'psvn)
+
+(defcustom svn-status-svn-environment-var-list '("LC_MESSAGES=C" "LC_ALL=")
+ "*A list of environment variables that should be set for that svn process.
+Each element is either a string \"VARIABLE=VALUE\" which will be added to
+the environment when svn is run, or just \"VARIABLE\" which causes that
+variable to be entirely removed from the environment.
+
+The default setting is '(\"LC_MESSAGES=C\" \"LC_ALL=\"). This ensures that the svn command
+line client does not output localized strings. psvn.el relies on the english
+messages."
+ :type '(repeat string)
+ :group 'psvn)
+(put 'svn-status-svn-environment-var-list 'risky-local-variable t)
+
+(defcustom svn-browse-url-function nil
+ ;; If the user hasn't changed `svn-browse-url-function', then changing
+ ;; `browse-url-browser-function' should affect psvn even after it has
+ ;; been loaded.
+ "Function to display a Subversion related WWW page in a browser.
+So far, this is used only for \"trac\" issue tracker integration.
+By default, this is nil, which means use `browse-url-browser-function'.
+Any non-nil value overrides that variable, with the same syntax."
+ ;; It would be nice to show the full list of browsers supported by
+ ;; browse-url, but (custom-variable-type 'browse-url-browser-function)
+ ;; returns just `function' if browse-url has not yet been loaded,
+ ;; and there seems to be no easy way to autoload browse-url when
+ ;; the custom-type of svn-browse-url-function is actually needed.
+ ;; So I'll only offer enough choices to cover all supported types.
+ :type `(choice (const :tag "Specified by `browse-url-browser-function'" nil)
+ (function :value browse-url-default-browser
+ ;; In XEmacs 21.4.17, the `function' widget matches
+ ;; all objects. Constrain it here so that alists
+ ;; fall through to the next choice. Accept either
+ ;; a symbol (fbound or not) or a lambda expression.
+ :match ,(lambda (widget value)
+ (or (symbolp value) (functionp value))))
+ (svn-alist :tag "Regexp/function association list"
+ :key-type regexp :value-type function
+ :value (("." . browse-url-default-browser))))
+ :link '(emacs-commentary-link "browse-url")
+ :group 'psvn)
+;; (put 'svn-browse-url-function 'risky-local-variable t)
+;; already implied by "-function" suffix
+
+(defcustom svn-status-window-alist
+ '((diff "*svn-diff*") (log "*svn-log*") (info t) (blame t) (proplist t) (update t))
+ "An alist to specify which windows should be used for svn command outputs.
+The following keys are supported: diff, log, info, blame, proplist, update.
+The following values can be given:
+nil ... show in `svn-process-buffer-name' buffer
+t ... show in dedicated *svn-info* buffer
+invisible ... don't show the buffer (eventually useful for update)
+a string ... show in a buffer named string"
+ :type '(svn-alist
+ :key-type symbol
+ :value-type (group
+ (choice
+ (const :tag "Show in *svn-process* buffer" nil)
+ (const :tag "Show in dedicated *svn-info* buffer" t)
+ (const :tag "Don't show the output" invisible)
+ (string :tag "Show in a buffer named"))))
+ :options '(diff log info blame proplist update)
+ :group 'psvn)
+
+(defcustom svn-status-short-mod-flag-p t
+ "*Whether the mark for out of date files is short or long.
+
+If this variable is is t, and a file is out of date (i.e., there is a newer
+version in the repository than the working copy), then the file will
+be marked by \"**\"
+
+If this variable is nil, and the file is out of date then the longer phrase
+\"(Update Available)\" is used.
+
+In either case the mark gets the face
+`svn-status-update-available-face', and will only be visible if
+`\\[svn-status-update]' is run with a prefix argument"
+ :type '(choice (const :tag "Short \"**\"" t)
+ (const :tag "Long \"(Update Available)\"" nil))
+ :group 'psvn)
+
+(defvar svn-status-debug-level 0 "The psvn.el debugging verbosity level.
+The higher the number, the more debug messages are shown.
+
+See `svn-status-message' for the meaning of values for that variable.")
+
+(defvar svn-bookmark-list nil "A list of locations for a quick access via `svn-status-via-bookmark'")
+;;(setq svn-bookmark-list '(("proj1" . "~/work/proj1")
+;; ("doc1" . "~/docs/doc1")))
+
+(defvar svn-status-buffer-name "*svn-status*" "Name for the svn status buffer")
+(defvar svn-process-buffer-name " *svn-process*" "Name for the svn process buffer")
+(defvar svn-log-edit-buffer-name "*svn-log-edit*" "Name for the svn log-edit buffer")
+
+(defcustom svn-status-use-header-line
+ (if (boundp 'header-line-format) t 'inline)
+ "*Whether a header line should be used.
+When t: Use the emacs header line
+When 'inline: Insert the header line in the `svn-status-buffer-name' buffer
+Otherwise: Don't display a header line"
+ :type '(choice (const :tag "Show column titles as a header line" t)
+ (const :tag "Insert column titles as text in the buffer" inline)
+ (other :tag "No column titles" nil))
+ :group 'psvn)
+
+;;; default arguments to pass to svn commands
+;; TODO: When customizing, an option menu or completion might be nice....
+(defcustom svn-status-default-log-arguments '("-v")
+ "*List of arguments to pass to svn log.
+\(used in `svn-status-show-svn-log'; override these by giving prefixes\)."
+ :type '(repeat string)
+ :group 'psvn)
+(put 'svn-status-default-log-arguments 'risky-local-variable t)
+
+(defcustom svn-status-default-commit-arguments '()
+ "*List of arguments to pass to svn commit.
+If you don't like recursive commits, set this value to (\"-N\")
+or mark the directory before committing it.
+Do not put an empty string here, except as an argument of an option:
+Subversion and the operating system may treat that as a file name
+equivalent to \".\", so you would commit more than you intended."
+ :type '(repeat string)
+ :group 'psvn)
+(put 'svn-status-default-commit-arguments 'risky-local-variable t)
+
+(defcustom svn-status-default-diff-arguments '("-x" "--ignore-eol-style")
+ "*A list of arguments that is passed to the svn diff command.
+When the built in diff command is used,
+the following options are available: --ignore-eol-style, --ignore-space-change,
+--ignore-all-space, --ignore-eol-style.
+The following setting ignores eol style changes and all white space changes:
+'(\"-x\" \"--ignore-eol-style --ignore-all-space\")
+
+If you'd like to suppress whitespace changes using the external diff command
+use the following value:
+'(\"--diff-cmd\" \"diff\" \"-x\" \"-wbBu\")
+
+"
+ :type '(repeat string)
+ :group 'psvn)
+(put 'svn-status-default-diff-arguments 'risky-local-variable t)
+
+(defcustom svn-status-default-status-arguments '()
+ "*A list of arguments that is passed to the svn status command.
+The following options are available: --ignore-externals
+
+"
+ :type '(repeat string)
+ :group 'psvn)
+(put 'svn-status-default-status-arguments 'risky-local-variable t)
+
+(defcustom svn-status-default-blame-arguments '("-x" "--ignore-eol-style")
+ "*A list of arguments that is passed to the svn blame command.
+See `svn-status-default-diff-arguments' for some examples."
+ :type '(repeat string)
+ :group 'psvn)
+
+(put 'svn-status-default-blame-arguments 'risky-local-variable t)
+
+(defvar svn-trac-project-root nil
+ "Path for an eventual existing trac issue tracker.
+This can be set with \\[svn-status-set-trac-project-root].")
+
+(defvar svn-status-module-name nil
+ "*A short name for the actual project.
+This can be set with \\[svn-status-set-module-name].")
+
+(defvar svn-status-branch-list nil
+ "*A list of known branches for the actual project
+This can be set with \\[svn-status-set-branch-list].
+
+The list contains full repository paths or shortcuts starting with \#
+\# at the beginning is replaced by the repository url.
+\#1\# has the special meaning that all paths below the given directory
+will be considered for interactive selections.
+
+A useful setting might be: '\(\"\#trunk\" \"\#1\#tags\" \"\#1\#branches\")")
+
+(defvar svn-status-load-state-before-svn-status t
+ "*Whether to automatically restore state from ++psvn.state file before running svn-status.")
+
+(defvar svn-log-link-handlers nil "A list of link handlers in *svn-log* buffers.
+These link handlers must be registered via `svn-log-register-link-handler'")
+
+;;; hooks
+(defvar svn-status-mode-hook nil "Hook run when entering `svn-status-mode'.")
+(defvar svn-log-edit-mode-hook nil "Hook run when entering `svn-log-edit-mode'.")
+(defvar svn-log-edit-done-hook nil "Hook run after commiting files via svn.")
+;; (put 'svn-log-edit-mode-hook 'risky-local-variable t)
+;; (put 'svn-log-edit-done-hook 'risky-local-variable t)
+;; already implied by "-hook" suffix
+
+(defvar svn-post-process-svn-output-hook nil "Hook that can be used to preprocess the output from svn.
+The function `svn-status-remove-control-M' can be useful for that hook")
+
+(when (eq system-type 'windows-nt)
+ (add-hook 'svn-post-process-svn-output-hook 'svn-status-remove-control-M))
+
+(defvar svn-status-svn-process-coding-system (when (boundp 'locale-coding-system) locale-coding-system)
+ "The coding system that is used for the svn command line client.
+It is used in svn-run, if it is not nil.")
+
+(defvar svn-status-svn-file-coding-system 'undecided-unix
+ "The coding system that is used to save files that are loaded as
+parameter or data files via the svn command line client.
+It is used in the following functions: `svn-prop-edit-do-it', `svn-log-edit-done'.
+You could set it to 'utf-8")
+
+(defcustom svn-status-use-ido-completion
+ (fboundp 'ido-completing-read)
+ "*Use ido completion functionality."
+ :type 'boolean
+ :group 'psvn)
+
+(defvar svn-status-completing-read-function
+ (if svn-status-use-ido-completion 'ido-completing-read 'completing-read))
+
+;;; experimental features
+(defvar svn-status-track-user-input nil "Track user/password queries.
+This feature is implemented via a process filter.
+It is an experimental feature.")
+
+(defvar svn-status-refresh-info nil "Whether `svn-status-update-buffer' should call `svn-status-parse-info'.")
+
+;;; Customize group
+(defgroup psvn nil
+ "Subversion interface for Emacs."
+ :group 'tools)
+
+(defgroup psvn-faces nil
+ "psvn faces."
+ :group 'psvn)
+
+
+(eval-and-compile
+ (require 'cl)
+ (defconst svn-xemacsp (featurep 'xemacs))
+ (if svn-xemacsp
+ (require 'overlay)
+ (require 'overlay nil t)))
+
+(defcustom svn-status-display-full-path nil
+ "Specifies how the filenames look like in the listing.
+If t, their full path name will be displayed, else only the filename."
+ :type 'boolean
+ :group 'psvn)
+
+(defcustom svn-status-prefix-key [(control x) (meta s)]
+ "Prefix key for the psvn commands in the global keymap."
+ :type '(choice (const [(control x) ?v ?S])
+ (const [(super s)])
+ (const [(hyper s)])
+ (const [(control x) ?v])
+ (const [(control x) ?V])
+ (sexp))
+ :group 'psvn
+ :set (lambda (var value)
+ (if (boundp var)
+ (global-unset-key (symbol-value var)))
+ (set var value)
+ (global-set-key (symbol-value var) 'svn-global-keymap)))
+
+(defcustom svn-admin-default-create-directory "~/"
+ "*The default directory that is suggested for `svn-admin-create'."
+ :type 'string
+ :group 'psvn)
+
+(defvar svn-status-custom-hide-function nil
+ "A function that receives a line-info and decides whether to hide that line.
+See psvn.el for an example function.")
+;; (put 'svn-status-custom-hide-function 'risky-local-variable t)
+;; already implied by "-function" suffix
+
+
+;; Use the normally used mode for files ending in .~HEAD~, .~BASE~, ...
+(add-to-list 'auto-mode-alist '("\\.~?\\(HEAD\\|BASE\\|PREV\\)~?\\'" ignore t))
+
+;;; internal variables
+(defvar svn-status-directory-history nil "List of visited svn working directories.")
+(defvar svn-process-cmd nil)
+(defvar svn-status-info nil)
+(defvar svn-status-filename-to-buffer-position-cache (make-hash-table :test 'equal :weakness t))
+(defvar svn-status-base-info nil "The parsed result from the svn info command.")
+(defvar svn-status-initial-window-configuration nil)
+(defvar svn-status-default-column 23)
+(defvar svn-status-default-revision-width 4)
+(defvar svn-status-default-author-width 9)
+(defvar svn-status-line-format " %c%c%c %4s %4s %-9s")
+(defvar svn-start-of-file-list-line-number 0)
+(defvar svn-status-files-to-commit nil
+ "List of files to commit at `svn-log-edit-done'.
+This is always set together with `svn-status-recursive-commit'.")
+(defvar svn-status-recursive-commit nil
+ "Non-nil if the next commit should be recursive.
+This is always set together with `svn-status-files-to-commit'.")
+(defvar svn-log-edit-update-log-entry nil
+ "Revision number whose log entry is being edited.
+This is nil if the log entry is for a new commit.")
+(defvar svn-status-pre-commit-window-configuration nil)
+(defvar svn-status-pre-propedit-window-configuration nil)
+(defvar svn-status-head-revision nil)
+(defvar svn-status-root-return-info nil)
+(defvar svn-status-property-edit-must-match-flag nil)
+(defvar svn-status-propedit-property-name nil "The property name for the actual svn propset command")
+(defvar svn-status-propedit-file-list nil)
+(defvar svn-status-mode-line-process "")
+(defvar svn-status-mode-line-process-status "")
+(defvar svn-status-mode-line-process-edit-flag "")
+(defvar svn-status-edit-svn-command nil)
+(defvar svn-status-update-previous-process-output nil)
+(defvar svn-pre-run-asynch-recent-keys nil)
+(defvar svn-pre-run-mode-line-process nil)
+(defvar svn-status-temp-dir
+ (expand-file-name
+ (or
+ (when (boundp 'temporary-file-directory) temporary-file-directory) ;emacs
+ ;; XEmacs 21.4.17 can return "/tmp/kalle" from (temp-directory).
+ ;; `file-name-as-directory' adds a slash so we can append a file name.
+ (when (fboundp 'temp-directory) (file-name-as-directory (temp-directory)))
+ "/tmp/")) "The directory that is used to store temporary files for psvn.")
+;; Because `temporary-file-directory' is not a risky local variable in
+;; GNU Emacs 22.0.51, we don't mark `svn-status-temp-dir' as such either.
+(defvar svn-temp-suffix (make-temp-name "."))
+(put 'svn-temp-suffix 'risky-local-variable t)
+(defvar svn-status-temp-file-to-remove nil)
+(put 'svn-status-temp-file-to-remove 'risky-local-variable t)
+(defvar svn-status-temp-arg-file (concat svn-status-temp-dir "svn.arg" svn-temp-suffix))
+(put 'svn-status-temp-arg-file 'risky-local-variable t)
+(defvar svn-status-options nil)
+(defvar svn-status-remote)
+(defvar svn-status-commit-rev-number nil)
+(defvar svn-status-update-rev-number nil)
+(defvar svn-status-operated-on-dot nil)
+(defvar svn-status-last-commit-author nil)
+(defvar svn-status-elided-list nil)
+(defvar svn-status-last-output-buffer-name nil "The buffer name for the buffer that holds the output from the last executed svn command")
+(defvar svn-status-pre-run-svn-buffer nil)
+(defvar svn-status-update-list nil)
+(defvar svn-transient-buffers)
+(defvar svn-ediff-windows)
+(defvar svn-ediff-result)
+(defvar svn-status-last-diff-options nil)
+(defvar svn-status-blame-file-name nil)
+(defvar svn-status-blame-revision nil)
+(defvar svn-admin-last-repository-dir nil "The last repository url for various operations.")
+(defvar svn-last-cmd-ring (make-ring 30) "Ring that holds the last executed svn commands (for debugging purposes)")
+(defvar svn-status-cached-version-string nil)
+(defvar svn-client-version nil "The version number of the used svn client")
+(defvar svn-status-get-line-information-for-file nil)
+(defvar svn-status-base-dir-cache (make-hash-table :test 'equal :weakness nil))
+(defvar svn-status-usermark-storage (make-hash-table :test 'equal :weakness nil))
+(defvar svn-log-registered-link-handlers (make-hash-table :test 'eql :weakness nil))
+
+(defvar svn-status-partner-buffer nil "The partner buffer for this svn related buffer")
+(make-variable-buffer-local 'svn-status-partner-buffer)
+
+;; Emacs 21 defines these in ediff-init.el but it seems more robust
+;; to just declare the variables here than try to load that file.
+;; It is Ediff's job to declare these as risky-local-variable if needed.
+(defvar ediff-buffer-A)
+(defvar ediff-buffer-B)
+(defvar ediff-buffer-C)
+(defvar ediff-quit-hook)
+
+;; Ditto for log-edit.el.
+(defvar log-edit-initial-files)
+(defvar log-edit-callback)
+(defvar log-edit-listfun)
+
+;; Ediff does not use this variable in GNU Emacs 20.7, GNU Emacs 21.4,
+;; nor XEmacs 21.4.17. However, pcl-cvs (a.k.a. pcvs) does.
+;; TODO: Check if this should be moved into the "svn-" namespace.
+(defvar ediff-after-quit-destination-buffer)
+
+;; That is an example for the svn-status-custom-hide-function:
+;; Note: For many cases it is a better solution to ignore files or
+;; file extensions via the svn-ignore properties (on P i, P I)
+;; (setq svn-status-custom-hide-function 'svn-status-hide-pyc-files)
+;; (defun svn-status-hide-pyc-files (info)
+;; "Hide all pyc files in the `svn-status-buffer-name' buffer."
+;; (let* ((fname (svn-status-line-info->filename-nondirectory info))
+;; (fname-len (length fname)))
+;; (and (> fname-len 4) (string= (substring fname (- fname-len 4)) ".pyc"))))
+
+;;; faces
+(defface svn-status-marked-face
+ '((((type tty) (class color)) (:foreground "green" :weight light))
+ (((class color) (background light)) (:foreground "green3"))
+ (((class color) (background dark)) (:foreground "palegreen2"))
+ (t (:weight bold)))
+ "Face to highlight the mark for user marked files in svn status buffers."
+ :group 'psvn-faces)
+
+(defface svn-status-marked-popup-face
+ '((((type tty) (class color)) (:foreground "green" :weight light))
+ (((class color) (background light)) (:foreground "green3"))
+ (((class color) (background dark)) (:foreground "palegreen2"))
+ (t (:weight bold)))
+ "Face to highlight the actual file, if a popup menu is activated."
+ :group 'psvn-faces)
+
+(defface svn-status-update-available-face
+ '((((type tty) (class color)) (:foreground "magenta" :weight light))
+ (((class color) (background light)) (:foreground "magenta"))
+ (((class color) (background dark)) (:foreground "yellow"))
+ (t (:weight bold)))
+ "Face used to highlight the 'out of date' mark.
+\(i.e., the mark used when there is a newer version in the repository
+than the working copy.\)
+
+See also `svn-status-short-mod-flag-p'."
+ :group 'psvn-faces)
+
+;based on cvs-filename-face
+(defface svn-status-directory-face
+ '((((type tty) (class color)) (:foreground "lightblue" :weight light))
+ (((class color) (background light)) (:foreground "blue4"))
+ (((class color) (background dark)) (:foreground "lightskyblue1"))
+ (t (:weight bold)))
+ "Face for directories in *svn-status* buffers.
+See `svn-status--line-info->directory-p' for what counts as a directory."
+ :group 'psvn-faces)
+
+;based on font-lock-comment-face
+(defface svn-status-filename-face
+ '((((class color) (background light)) (:foreground "chocolate"))
+ (((class color) (background dark)) (:foreground "beige")))
+ "Face for non-directories in *svn-status* buffers.
+See `svn-status--line-info->directory-p' for what counts as a directory."
+ :group 'psvn-faces)
+
+;not based on anything, may be horribly ugly!
+(defface svn-status-symlink-face
+ '((((class color) (background light)) (:foreground "cornflower blue"))
+ (((class color) (background dark)) (:foreground "cyan")))
+ "Face for symlinks in *svn-status* buffers.
+
+This is the face given to the actual link (i.e., the versioned item),
+the target of the link gets either `svn-status-filename-face' or
+`svn-status-directory-face'."
+ :group 'psvn-faces)
+
+;based on font-lock-warning-face
+(defface svn-status-locked-face
+ '((t
+ (:weight bold :foreground "Red")))
+ "Face for the phrase \"[ LOCKED ]\" `svn-status-buffer-name' buffers."
+ :group 'psvn-faces)
+
+;based on vhdl-font-lock-directive-face
+(defface svn-status-switched-face
+ '((((class color)
+ (background light))
+ (:foreground "CadetBlue"))
+ (((class color)
+ (background dark))
+ (:foreground "Aquamarine"))
+ (t
+ (:bold t :italic t)))
+ "Face for the phrase \"(switched)\" non-directories in svn status buffers."
+ :group 'psvn-faces)
+
+(if svn-xemacsp
+ (defface svn-status-blame-highlight-face
+ '((((type tty) (class color)) (:foreground "green" :weight light))
+ (((class color) (background light)) (:foreground "green3"))
+ (((class color) (background dark)) (:foreground "palegreen2"))
+ (t (:weight bold)))
+ "Default face for highlighting a line in svn status blame mode."
+ :group 'psvn-faces)
+ (defface svn-status-blame-highlight-face
+ '((t :inherit highlight))
+ "Default face for highlighting a line in svn status blame mode."
+ :group 'psvn-faces))
+
+(if svn-xemacsp
+ (defface svn-log-partner-highlight-face
+ '((((type tty) (class color)) (:foreground "yellow" :weight light))
+ (((class color) (background light)) (:foreground "gold"))
+ (((class color) (background dark)) (:foreground "gold"))
+ (t (:weight bold)))
+ "Default face for highlighting the partner in svn log mode."
+ :group 'psvn-faces)
+ (defface svn-log-partner-highlight-face
+ '((((class color) (background light))
+ (:background "light goldenrod" :weight bold))
+ (t (:weight bold)))
+ "Default face for highlighting the partner in svn log mode."
+ :group 'psvn-faces))
+
+(defface svn-status-blame-rev-number-face
+ '((((class color) (background light)) (:foreground "DarkGoldenrod"))
+ (((class color) (background dark)) (:foreground "LightGoldenrod"))
+ (t (:weight bold :slant italic)))
+ "Face to highlight revision numbers in the svn-blame mode."
+ :group 'psvn-faces)
+
+(defvar svn-highlight t)
+;; stolen from PCL-CVS
+(defun svn-add-face (str face &optional keymap)
+ "Return string STR decorated with the specified FACE.
+If `svn-highlight' is nil then just return STR."
+ (when svn-highlight
+ ;; Do not use `list*'; cl.el might not have been loaded. We could
+ ;; put (require 'cl) at the top but let's try to manage without.
+ (add-text-properties 0 (length str)
+ `(face ,face
+ mouse-face highlight)
+;; 18.10.2004: the keymap parameter is not used (yet) in psvn.el
+;; ,@(when keymap
+;; `(mouse-face highlight
+;; local-map ,keymap)))
+ str))
+ str)
+
+(defun svn-status-maybe-add-face (condition text face)
+ "If CONDITION then add FACE to TEXT.
+Else return TEXT unchanged."
+ (if condition
+ (svn-add-face text face)
+ text))
+
+(defun svn-status-choose-face-to-add (condition text face1 face2)
+ "If CONDITION then add FACE1 to TEXT, else add FACE2 to TEXT."
+ (if condition
+ (svn-add-face text face1)
+ (svn-add-face text face2)))
+
+(defun svn-status-maybe-add-string (condition string face)
+ "If CONDITION then return STRING decorated with FACE.
+Otherwise, return \"\"."
+ (if condition
+ (svn-add-face string face)
+ ""))
+
+;; compatibility
+;; emacs 20
+(defalias 'svn-point-at-eol
+ (if (fboundp 'point-at-eol) 'point-at-eol 'line-end-position))
+(defalias 'svn-point-at-bol
+ (if (fboundp 'point-at-bol) 'point-at-bol 'line-beginning-position))
+(defalias 'svn-read-directory-name
+ (if (fboundp 'read-directory-name) 'read-directory-name 'read-file-name))
+
+(eval-when-compile
+ (if (not (fboundp 'gethash))
+ (require 'cl-macs)))
+(defalias 'svn-puthash (if (fboundp 'puthash) 'puthash 'cl-puthash))
+
+;; emacs 21
+(if (fboundp 'line-number-at-pos)
+ (defalias 'svn-line-number-at-pos 'line-number-at-pos)
+ (defun svn-line-number-at-pos (&optional pos)
+ "Return (narrowed) buffer line number at position POS.
+If POS is nil, use current buffer location."
+ (let ((opoint (or pos (point))) start)
+ (save-excursion
+ (goto-char (point-min))
+ (setq start (point))
+ (goto-char opoint)
+ (forward-line 0)
+ (1+ (count-lines start (point)))))))
+
+(defun svn-substring-no-properties (string &optional from to)
+ (if (fboundp 'substring-no-properties)
+ (substring-no-properties string from to)
+ (substring string from to)))
+
+; xemacs
+;; Evaluate the defsubst at compile time, so that the byte compiler
+;; knows the definition and can inline calls. It cannot detect the
+;; defsubst automatically from within the if form.
+(eval-and-compile
+ (if (fboundp 'match-string-no-properties)
+ (defalias 'svn-match-string-no-properties 'match-string-no-properties)
+ (defsubst svn-match-string-no-properties (match)
+ (buffer-substring-no-properties (match-beginning match) (match-end match)))))
+
+;; XEmacs 21.4.17 does not have an `alist' widget. Define a replacement.
+;; To find out whether the `alist' widget exists, we cannot check just
+;; (get 'alist 'widget-type), because GNU Emacs 21.4 defines it in
+;; "wid-edit.el", which is not preloaded; it will be autoloaded when
+;; `widget-create' is called. Instead, we call `widgetp', which is
+;; also autoloaded from "wid-edit.el". XEmacs 21.4.17 does not have
+;; `widgetp' either, so we check that first.
+(if (and (fboundp 'widgetp) (widgetp 'alist))
+ (define-widget 'svn-alist 'alist
+ "An association list.
+Use this instead of `alist', for XEmacs 21.4 compatibility.")
+ (define-widget 'svn-alist 'list
+ "An association list.
+Use this instead of `alist', for XEmacs 21.4 compatibility."
+ :convert-widget 'svn-alist-convert-widget
+ :tag "Association List"
+ :key-type 'sexp
+ :value-type 'sexp)
+ (defun svn-alist-convert-widget (widget)
+ (let* ((value-type (widget-get widget :value-type))
+ (option-widgets (loop for option in (widget-get widget :options)
+ collect `(cons :format "%v"
+ (const :format "%t: %v\n"
+ :tag "Key"
+ ,option)
+ ,value-type))))
+ (widget-put widget :args
+ `(,@(when option-widgets
+ `((set :inline t :format "%v"
+ ,@option-widgets)))
+ (editable-list :inline t
+ (cons :format "%v"
+ ,(widget-get widget :key-type)
+ ,value-type)))))
+ widget))
+
+;; process launch functions
+(defvar svn-call-process-function (if (fboundp 'process-file) 'process-file 'call-process))
+(defvar svn-start-process-function (if (fboundp 'start-file-process) 'start-file-process 'start-process))
+
+
+;;; keymaps
+
+(defvar svn-global-keymap nil "Global keymap for psvn.el.
+To bind this to a different key, customize `svn-status-prefix-key'.")
+(put 'svn-global-keymap 'risky-local-variable t)
+(when (not svn-global-keymap)
+ (setq svn-global-keymap (make-sparse-keymap))
+ (define-key svn-global-keymap (kbd "v") 'svn-status-version)
+ (define-key svn-global-keymap (kbd "s") 'svn-status-this-directory)
+ (define-key svn-global-keymap (kbd "b") 'svn-status-via-bookmark)
+ (define-key svn-global-keymap (kbd "h") 'svn-status-use-history)
+ (define-key svn-global-keymap (kbd "u") 'svn-status-update-cmd)
+ (define-key svn-global-keymap (kbd "=") 'svn-status-show-svn-diff)
+ (define-key svn-global-keymap (kbd "f =") 'svn-file-show-svn-diff)
+ (define-key svn-global-keymap (kbd "f e") 'svn-file-show-svn-ediff)
+ (define-key svn-global-keymap (kbd "f l") 'svn-status-show-svn-log)
+ (define-key svn-global-keymap (kbd "f b") 'svn-status-blame)
+ (define-key svn-global-keymap (kbd "f a") 'svn-file-add-to-changelog)
+ (define-key svn-global-keymap (kbd "f r") 'svn-file-revert)
+ (define-key svn-global-keymap (kbd "c") 'svn-status-commit)
+ (define-key svn-global-keymap (kbd "S") 'svn-status-switch-to-status-buffer)
+ (define-key svn-global-keymap (kbd "o") 'svn-status-pop-to-status-buffer))
+
+(defvar svn-status-diff-mode-map ()
+ "Keymap used in `svn-status-diff-mode' for additional commands that are not defined in diff-mode.")
+(put 'svn-status-diff-mode-map 'risky-local-variable t) ;for Emacs 20.7
+
+(when (not svn-status-diff-mode-map)
+ (setq svn-status-diff-mode-map (copy-keymap diff-mode-shared-map))
+ (define-key svn-status-diff-mode-map [?g] 'revert-buffer)
+ (define-key svn-status-diff-mode-map [?s] 'svn-status-pop-to-status-buffer)
+ (define-key svn-status-diff-mode-map [?c] 'svn-status-diff-pop-to-commit-buffer)
+ (define-key svn-status-diff-mode-map [?w] 'svn-status-diff-save-current-defun-as-kill))
+
+(defvar svn-global-trac-map ()
+ "Subkeymap used in `svn-global-keymap' for trac issue tracker commands.")
+(put 'svn-global-trac-map 'risky-local-variable t) ;for Emacs 20.7
+(when (not svn-global-trac-map)
+ (setq svn-global-trac-map (make-sparse-keymap))
+ (define-key svn-global-trac-map (kbd "w") 'svn-trac-browse-wiki)
+ (define-key svn-global-trac-map (kbd "t") 'svn-trac-browse-timeline)
+ (define-key svn-global-trac-map (kbd "m") 'svn-trac-browse-roadmap)
+ (define-key svn-global-trac-map (kbd "s") 'svn-trac-browse-source)
+ (define-key svn-global-trac-map (kbd "r") 'svn-trac-browse-report)
+ (define-key svn-global-trac-map (kbd "i") 'svn-trac-browse-ticket)
+ (define-key svn-global-trac-map (kbd "c") 'svn-trac-browse-changeset)
+ (define-key svn-global-keymap (kbd "t") svn-global-trac-map))
+
+;; The setter of `svn-status-prefix-key' makes a binding in the global
+;; map refer to the `svn-global-keymap' symbol, rather than directly
+;; to the keymap. Emacs then implicitly uses the symbol-function.
+;; This has the advantage that `describe-bindings' (C-h b) can show
+;; the name of the keymap and link to its documentation.
+(defalias 'svn-global-keymap svn-global-keymap)
+;; `defalias' of GNU Emacs 21.4 doesn't allow a docstring argument.
+(put 'svn-global-keymap 'function-documentation
+ '(documentation-property 'svn-global-keymap 'variable-documentation t))
+
+
+;; named after SVN_WC_ADM_DIR_NAME in svn_wc.h
+(defun svn-wc-adm-dir-name ()
+ "Return the name of the \".svn\" subdirectory or equivalent."
+ (if (and (eq system-type 'windows-nt)
+ (getenv "SVN_ASP_DOT_NET_HACK"))
+ "_svn"
+ ".svn"))
+
+(defun svn-log-edit-file-name (&optional curdir)
+ "Get the name of the saved log edit file
+If curdir, return `svn-log-edit-file-name'
+Otherwise position svn-log-edit-file-name in the root directory of this working copy"
+ (if curdir
+ svn-log-edit-file-name
+ (concat (svn-status-base-dir) svn-log-edit-file-name)))
+
+(defun svn-status-message (level &rest args)
+ "If LEVEL is lower than `svn-status-debug-level' print ARGS using `message'.
+
+Guideline for numbers:
+1 - error messages, 3 - non-serious error messages, 5 - messages for things
+that take a long time, 7 - not very important messages on stuff, 9 - messages
+inside loops."
+ (if (<= level svn-status-debug-level)
+ (apply 'message args)))
+
+(defun svn-status-flatten-list (list)
+ "Flatten any lists within ARGS, so that there are no sublists."
+ (loop for item in list
+ if (listp item) nconc (svn-status-flatten-list item)
+ else collect item))
+
+(defun svn-status-window-line-position (w)
+ "Return the window line at point for window W, or nil if W is nil."
+ (svn-status-message 3 "About to count lines; selected window is %s" (selected-window))
+ (and w (count-lines (window-start w) (point))))
+
+;;;###autoload
+(defun svn-checkout (repos-url path)
+ "Run svn checkout REPOS-URL PATH."
+ (interactive (list (read-string "Checkout from repository Url: ")
+ (svn-read-directory-name "Checkout to directory: ")))
+ (svn-run t t 'checkout "checkout" repos-url (expand-file-name path)))
+
+;;;###autoload (defalias 'svn-examine 'svn-status)
+(defalias 'svn-examine 'svn-status)
+
+;;;###autoload
+(defun svn-status (dir &optional arg)
+ "Examine the status of Subversion working copy in directory DIR.
+If ARG is -, allow editing of the parameters. One could add -N to
+run svn status non recursively to make it faster.
+For every other non nil ARG pass the -u argument to `svn status', which
+asks svn to connect to the repository and check to see if there are updates
+there.
+
+If there is no .svn directory, examine if there is CVS and run
+`cvs-examine'. Otherwise ask if to run `dired'."
+ (interactive (list (svn-read-directory-name "SVN status directory: "
+ nil default-directory nil)
+ current-prefix-arg))
+ (let ((svn-dir (format "%s%s"
+ (file-name-as-directory dir)
+ (svn-wc-adm-dir-name)))
+ (cvs-dir (format "%sCVS" (file-name-as-directory dir))))
+ (cond
+ ((file-directory-p svn-dir)
+ (setq arg (svn-status-possibly-negate-meaning-of-arg arg 'svn-status))
+ (svn-status-1 dir arg))
+ ((and (file-directory-p cvs-dir)
+ (fboundp 'cvs-examine))
+ (cvs-examine dir nil))
+ (t
+ (when (y-or-n-p
+ (format
+ (concat
+ "%s "
+ "is not Subversion controlled (missing %s "
+ "directory). "
+ "Run dired instead? ")
+ dir
+ (svn-wc-adm-dir-name)))
+ (dired dir))))))
+
+(defvar svn-status-display-new-status-buffer nil)
+(defun svn-status-1 (dir &optional arg)
+ "Examine DIR. See `svn-status' for more information."
+ (unless (file-directory-p dir)
+ (error "%s is not a directory" dir))
+ (setq dir (file-name-as-directory dir))
+ (when svn-status-load-state-before-svn-status
+ (unless (string= dir (car svn-status-directory-history))
+ (let ((default-directory dir)) ;otherwise svn-status-base-dir looks in the wrong place
+ (svn-status-load-state t))))
+ (setq svn-status-directory-history (delete dir svn-status-directory-history))
+ (add-to-list 'svn-status-directory-history dir)
+ (if (string= (buffer-name) svn-status-buffer-name)
+ (setq svn-status-display-new-status-buffer nil)
+ (setq svn-status-display-new-status-buffer t)
+ ;;(message "psvn: Saving initial window configuration")
+ (setq svn-status-initial-window-configuration
+ (current-window-configuration)))
+ (let* ((cur-buf (current-buffer))
+ (status-buf (get-buffer-create svn-status-buffer-name))
+ (proc-buf (get-buffer-create svn-process-buffer-name))
+ (want-edit (eq arg '-))
+ (status-option (if want-edit
+ (if svn-status-verbose "-v" "")
+ (if svn-status-verbose
+ (if arg "-uv" "-v")
+ (if arg "-u" "")))))
+ (save-excursion
+ (set-buffer status-buf)
+ (setq default-directory dir)
+ (set-buffer proc-buf)
+ (setq default-directory dir
+ svn-status-remote (when arg t))
+ (set-buffer cur-buf)
+ (if want-edit
+ (let (svn-status-edit-svn-command t)
+ (svn-run t t 'status "status" svn-status-default-status-arguments status-option))
+ (svn-run t t 'status "status" svn-status-default-status-arguments status-option)))))
+
+(defun svn-status-this-directory (arg)
+ "Run `svn-status' for the `default-directory'"
+ (interactive "P")
+ (svn-status default-directory arg))
+
+(defun svn-status-use-history ()
+ "Interactively select a different directory from `svn-status-directory-history'."
+ (interactive)
+ (let* ((in-status-buffer (eq major-mode 'svn-status-mode))
+ (hist (if in-status-buffer (cdr svn-status-directory-history) svn-status-directory-history))
+ (dir (funcall svn-status-completing-read-function "svn-status on directory: " hist))
+ (svn-status-buffer (get-buffer svn-status-buffer-name))
+ (svn-buffer-available (and svn-status-buffer
+ (with-current-buffer svn-status-buffer-name (string= default-directory dir)))))
+ (if (file-directory-p dir)
+ (if svn-buffer-available
+ (svn-status-switch-to-status-buffer)
+ (unless svn-status-refresh-info
+ (setq svn-status-refresh-info 'once))
+ (svn-status dir))
+ (error "%s is not a directory" dir))))
+
+(defun svn-had-user-input-since-asynch-run ()
+ (not (equal (recent-keys) svn-pre-run-asynch-recent-keys)))
+
+(defun svn-process-environment ()
+ "Construct the environment for the svn process.
+It is a combination of `svn-status-svn-environment-var-list' and
+the usual `process-environment'."
+ ;; If there are duplicate elements in `process-environment', then GNU
+ ;; Emacs 21.4 guarantees that the first one wins; but GNU Emacs 20.7
+ ;; and XEmacs 21.4.17 don't document what happens. We'll just remove
+ ;; any duplicates ourselves, then. This also gives us an opportunity
+ ;; to handle the "VARIABLE" syntax that none of them supports.
+ (loop with found = '()
+ for elt in (append svn-status-svn-environment-var-list
+ process-environment)
+ for has-value = (string-match "=" elt)
+ for name = (substring elt 0 has-value)
+ unless (member name found)
+ do (push name found)
+ and when has-value
+ collect elt))
+
+(defun svn-run (run-asynchron clear-process-buffer cmdtype &rest arglist)
+ "Run svn with arguments ARGLIST.
+
+If RUN-ASYNCHRON is t then run svn asynchronously.
+
+If CLEAR-PROCESS-BUFFER is t then erase the contents of the
+`svn-process-buffer-name' buffer before commencing.
+
+CMDTYPE is a symbol such as 'mv, 'revert, or 'add, representing the
+command to run.
+
+ARGLIST is a list of arguments \(which must include the command name,
+for example: '(\"revert\" \"file1\"\)
+ARGLIST is flattened and any every nil value is discarded.
+
+If the variable `svn-status-edit-svn-command' is non-nil then the user
+can edit ARGLIST before running svn.
+
+The hook svn-pre-run-hook allows to monitor/modify the ARGLIST."
+ (setq arglist (svn-status-flatten-list arglist))
+ (if (eq (process-status "svn") nil)
+ (progn
+ (when svn-status-edit-svn-command
+ (setq arglist (append
+ (list (car arglist))
+ (split-string
+ (read-from-minibuffer
+ (format "svn %s flags: " (car arglist))
+ (mapconcat 'identity (cdr arglist) " ")))))
+ (when (eq svn-status-edit-svn-command t)
+ (svn-status-toggle-edit-cmd-flag t))
+ (message "svn-run %s: %S" cmdtype arglist))
+ (run-hooks 'svn-pre-run-hook)
+ (unless (eq mode-line-process 'svn-status-mode-line-process)
+ (setq svn-pre-run-mode-line-process mode-line-process)
+ (setq mode-line-process 'svn-status-mode-line-process))
+ (setq svn-status-pre-run-svn-buffer (current-buffer))
+ (let* ((proc-buf (get-buffer-create svn-process-buffer-name))
+ (svn-exe svn-status-svn-executable)
+ (svn-proc))
+ (when (listp (car arglist))
+ (setq arglist (car arglist)))
+ (save-excursion
+ (set-buffer proc-buf)
+ (unless (file-executable-p default-directory)
+ (message "psvn: workaround in %s needed: %s no longer exists" (current-buffer) default-directory)
+ (cd (expand-file-name "~")))
+ (setq buffer-read-only nil)
+ (buffer-disable-undo)
+ (fundamental-mode)
+ (if clear-process-buffer
+ (delete-region (point-min) (point-max))
+ (goto-char (point-max)))
+ (setq svn-process-cmd cmdtype)
+ (setq svn-status-last-commit-author nil)
+ (setq svn-status-mode-line-process-status (format " running %s" cmdtype))
+ (svn-status-update-mode-line)
+ (sit-for 0.1)
+ (ring-insert svn-last-cmd-ring (list (current-time-string) arglist default-directory))
+ (if run-asynchron
+ (progn
+ ;;(message "running asynchron: %s %S" svn-exe arglist)
+ (setq svn-pre-run-asynch-recent-keys (recent-keys))
+ (let ((process-environment (svn-process-environment))
+ (process-connection-type nil))
+ ;; Communicate with the subprocess via pipes rather
+ ;; than via a pseudoterminal, so that if the svn+ssh
+ ;; scheme is being used, SSH will not ask for a
+ ;; passphrase via stdio; psvn.el is currently unable
+ ;; to answer such prompts. Instead, SSH will run
+ ;; x11-ssh-askpass if possible. If Emacs is being
+ ;; run on a TTY without $DISPLAY, this will fail; in
+ ;; such cases, the user should start ssh-agent and
+ ;; then run ssh-add explicitly.
+ (setq svn-proc (apply svn-start-process-function "svn" proc-buf svn-exe arglist)))
+ (when svn-status-svn-process-coding-system
+ (set-process-coding-system svn-proc svn-status-svn-process-coding-system
+ svn-status-svn-process-coding-system))
+ (set-process-sentinel svn-proc 'svn-process-sentinel)
+ (when svn-status-track-user-input
+ (set-process-filter svn-proc 'svn-process-filter)))
+ ;;(message "running synchron: %s %S" svn-exe arglist)
+ (let ((process-environment (svn-process-environment)))
+ ;; `call-process' ignores `process-connection-type' and
+ ;; never opens a pseudoterminal.
+ (apply svn-call-process-function svn-exe nil proc-buf nil arglist))
+ (setq svn-status-last-output-buffer-name svn-process-buffer-name)
+ (run-hooks 'svn-post-process-svn-output-hook)
+ (setq svn-status-mode-line-process-status "")
+ (svn-status-update-mode-line)
+ (when svn-pre-run-mode-line-process
+ (setq mode-line-process svn-pre-run-mode-line-process)
+ (setq svn-pre-run-mode-line-process nil))))))
+ (error "You can only run one svn process at once!")))
+
+(defun svn-process-sentinel-fixup-path-seperators ()
+ "Convert all path separators to UNIX style.
+\(This is a no-op unless `system-type' is windows-nt\)"
+ (when (eq system-type 'windows-nt)
+ (save-excursion
+ (goto-char (point-min))
+ (while (search-forward "\\" nil t)
+ (replace-match "/")))))
+
+(defun svn-process-sentinel (process event)
+ ;;(princ (format "Process: %s had the event `%s'" process event)))
+ ;;(save-excursion
+ (let ((act-buf (current-buffer)))
+ (when svn-pre-run-mode-line-process
+ (with-current-buffer svn-status-pre-run-svn-buffer
+ (setq mode-line-process svn-pre-run-mode-line-process))
+ (setq svn-pre-run-mode-line-process nil))
+ (set-buffer (process-buffer process))
+ (setq svn-status-mode-line-process-status "")
+ (svn-status-update-mode-line)
+ (cond ((string= event "finished\n")
+ (run-hooks 'svn-post-process-svn-output-hook)
+ (cond ((eq svn-process-cmd 'status)
+ ;;(message "svn status finished")
+ (svn-process-sentinel-fixup-path-seperators)
+ (svn-parse-status-result)
+ (svn-status-apply-elide-list)
+ (when svn-status-update-previous-process-output
+ (set-buffer (process-buffer process))
+ (delete-region (point-min) (point-max))
+ (insert "Output from svn command:\n")
+ (insert svn-status-update-previous-process-output)
+ (goto-char (point-min))
+ (setq svn-status-update-previous-process-output nil))
+ (when svn-status-update-list
+ ;; (message "Using svn-status-update-list: %S" svn-status-update-list)
+ (save-excursion
+ (svn-status-update-with-command-list svn-status-update-list))
+ (setq svn-status-update-list nil))
+ (when svn-status-display-new-status-buffer
+ (set-window-configuration svn-status-initial-window-configuration)
+ (if (svn-had-user-input-since-asynch-run)
+ (message "svn status finished")
+ (switch-to-buffer svn-status-buffer-name))))
+ ((eq svn-process-cmd 'log)
+ (svn-status-show-process-output 'log t)
+ (pop-to-buffer svn-status-last-output-buffer-name)
+ (svn-log-view-mode)
+ (forward-line 2)
+ (unless (looking-at "Changed paths:")
+ (forward-line 1))
+ (font-lock-fontify-buffer)
+ (message "svn log finished"))
+ ((eq svn-process-cmd 'info)
+ (svn-status-show-process-output 'info t)
+ (message "svn info finished"))
+ ((eq svn-process-cmd 'ls)
+ (svn-status-show-process-output 'info t)
+ (message "svn ls finished"))
+ ((eq svn-process-cmd 'diff)
+ (svn-status-activate-diff-mode)
+ (message "svn diff finished"))
+ ((eq svn-process-cmd 'parse-info)
+ (svn-status-parse-info-result))
+ ((eq svn-process-cmd 'blame)
+ (svn-status-show-process-output 'blame t)
+ (when svn-status-pre-run-svn-buffer
+ (with-current-buffer svn-status-pre-run-svn-buffer
+ (unless (eq major-mode 'svn-status-mode)
+ (let ((src-line-number (svn-line-number-at-pos)))
+ (pop-to-buffer (get-buffer svn-status-last-output-buffer-name))
+ (goto-line src-line-number)))))
+ (with-current-buffer (get-buffer svn-status-last-output-buffer-name)
+ (svn-status-activate-blame-mode))
+ (message "svn blame finished"))
+ ((eq svn-process-cmd 'commit)
+ (svn-process-sentinel-fixup-path-seperators)
+ (svn-status-remove-temp-file-maybe)
+ (when (member 'commit svn-status-unmark-files-after-list)
+ (svn-status-unset-all-usermarks))
+ (svn-status-update-with-command-list (svn-status-parse-commit-output))
+ (svn-revert-some-buffers)
+ (run-hooks 'svn-log-edit-done-hook)
+ (setq svn-status-files-to-commit nil
+ svn-status-recursive-commit nil)
+ (if (null svn-status-commit-rev-number)
+ (message "No revision to commit.")
+ (message "svn: Committed revision %s." svn-status-commit-rev-number)))
+ ((eq svn-process-cmd 'update)
+ (svn-status-show-process-output 'update t)
+ (setq svn-status-update-list (svn-status-parse-update-output))
+ (svn-revert-some-buffers)
+ (svn-status-update)
+ (if (car svn-status-update-rev-number)
+ (message "svn: Updated to revision %s." (cadr svn-status-update-rev-number))
+ (message "svn: At revision %s." (cadr svn-status-update-rev-number))))
+ ((eq svn-process-cmd 'add)
+ (svn-status-update-with-command-list (svn-status-parse-ar-output))
+ (message "svn add finished"))
+ ((eq svn-process-cmd 'lock)
+ (svn-status-update)
+ (message "svn lock finished"))
+ ((eq svn-process-cmd 'unlock)
+ (svn-status-update)
+ (message "svn unlock finished"))
+ ((eq svn-process-cmd 'mkdir)
+ (svn-status-update)
+ (message "svn mkdir finished"))
+ ((eq svn-process-cmd 'revert)
+ (when (member 'revert svn-status-unmark-files-after-list)
+ (svn-status-unset-all-usermarks))
+ (svn-revert-some-buffers)
+ (svn-status-update)
+ (message "svn revert finished"))
+ ((eq svn-process-cmd 'resolved)
+ (svn-status-update)
+ (message "svn resolved finished"))
+ ((eq svn-process-cmd 'rm)
+ (svn-status-update-with-command-list (svn-status-parse-ar-output))
+ (message "svn rm finished"))
+ ((eq svn-process-cmd 'cleanup)
+ (message "svn cleanup finished"))
+ ((eq svn-process-cmd 'proplist)
+ (svn-status-show-process-output 'proplist t)
+ (message "svn proplist finished"))
+ ((eq svn-process-cmd 'checkout)
+ (svn-status default-directory))
+ ((eq svn-process-cmd 'proplist-parse)
+ (svn-status-property-parse-property-names))
+ ((eq svn-process-cmd 'propset)
+ (svn-status-remove-temp-file-maybe)
+ (if (member svn-status-propedit-property-name '("svn:keywords"))
+ (svn-status-update-with-command-list (svn-status-parse-property-output))
+ (svn-status-update)))
+ ((eq svn-process-cmd 'propdel)
+ (svn-status-update))))
+ ((string= event "killed\n")
+ (message "svn process killed"))
+ ((string-match "exited abnormally" event)
+ (while (accept-process-output process 0 100))
+ ;; find last error message and show it.
+ (goto-char (point-max))
+ (if (re-search-backward "^svn: \\(.*\\)" nil t)
+ (svn-process-handle-error (match-string 1))
+ (message "svn failed: %s" event)))
+ (t
+ (message "svn process had unknown event: %s" event))
+ (svn-status-show-process-output nil t))))
+
+(defvar svn-process-handle-error-msg nil)
+(defun svn-process-handle-error (error-msg)
+ (let ((svn-process-handle-error-msg error-msg))
+ (electric-helpify 'svn-process-help-with-error-msg)))
+
+(defun svn-process-help-with-error-msg ()
+ (interactive)
+ (let ((help-msg (cadr (assoc svn-process-handle-error-msg
+ '(("Cannot non-recursively commit a directory deletion"
+ "Please unmark all files and position point at the directory you would like to remove.\nThen run commit again."))))))
+ (if help-msg
+ (save-excursion
+ (with-output-to-temp-buffer (help-buffer)
+ (princ (format "svn failed: %s\n\n%s" svn-process-handle-error-msg help-msg))))
+ (message "svn failed: %s" svn-process-handle-error-msg))))
+
+
+(defun svn-process-filter (process str)
+ "Track the svn process output and ask user questions in the minibuffer when appropriate."
+ (save-window-excursion
+ (set-buffer svn-process-buffer-name)
+ ;;(message "svn-process-filter: %s" str)
+ (goto-char (point-max))
+ (insert str)
+ (save-excursion
+ (goto-char (svn-point-at-bol))
+ (when (looking-at "Password for '\\(.+\\)': ")
+ ;(svn-status-show-process-buffer)
+ (let ((passwd (read-passwd
+ (format "Enter svn password for %s: " (match-string 1)))))
+ (svn-process-send-string-and-newline passwd t)))
+ (when (looking-at "Username: ")
+ (let ((user-name (read-string "Username for svn operation: ")))
+ (svn-process-send-string-and-newline user-name)))
+ (when (looking-at "(R)eject, accept (t)emporarily or accept (p)ermanently")
+ (svn-status-show-process-buffer)
+ (let ((answer (read-string "(R)eject, accept (t)emporarily or accept (p)ermanently? ")))
+ (svn-process-send-string (substring answer 0 1)))))))
+
+(defun svn-revert-some-buffers (&optional tree)
+ "Reverts all buffers visiting a file in TREE that aren't modified.
+To be run after a commit, an update or a merge."
+ (interactive)
+ (let ((tree (or (svn-status-base-dir) tree)))
+ (dolist (buffer (buffer-list))
+ (with-current-buffer buffer
+ (when (not (buffer-modified-p))
+ (let ((file (buffer-file-name)))
+ (when file
+ (let ((root (svn-status-base-dir (file-name-directory file)))
+ (point-pos (point)))
+ (when (and root
+ (string= root tree)
+ ;; buffer is modified and in the tree TREE.
+ svn-status-auto-revert-buffers)
+ (when svn-status-fancy-file-state-in-modeline
+ (svn-status-update-modeline))
+ ;; (message "svn-revert-some-buffers: %s %s" (buffer-file-name) (verify-visited-file-modtime (current-buffer)))
+ ;; Keep the buffer if the file doesn't exist
+ (when (and (file-exists-p file) (not (verify-visited-file-modtime (current-buffer))))
+ (revert-buffer t t)
+ (goto-char point-pos)))))))))))
+
+(defun svn-parse-rev-num (str)
+ (if (and str (stringp str)
+ (save-match-data (string-match "^[0-9]+" str)))
+ (string-to-number str)
+ -1))
+
+(defsubst svn-status-make-ui-status ()
+ "Make a ui-status structure for a file in a svn working copy.
+The initial values in the structure returned by this function
+are good for a file or directory that the user hasn't seen before.
+
+The ui-status structure keeps track of how the file or directory
+should be displayed in svn-status mode. Updating the svn-status
+buffer from the working copy preserves the ui-status if possible.
+User commands modify this structure; each file or directory must
+thus have its own copy.
+
+Currently, the ui-status is a list (USER-MARK USER-ELIDE).
+USER-MARK is non-nil iff the user has marked the file or directory,
+ typically with `svn-status-set-user-mark'. To read USER-MARK,
+ call `svn-status-line-info->has-usermark'.
+USER-ELIDE is non-nil iff the user has elided the file or directory
+ from the svn-status buffer, typically with `svn-status-toggle-elide'.
+ To read USER-ELIDE, call `svn-status-line-info->user-elide'.
+
+Call `svn-status-line-info->ui-status' to access the whole ui-status
+structure."
+ (list nil nil))
+
+(defun svn-status-make-dummy-dirs (dir-list old-ui-information)
+ "Calculate additionally necessary directories that were not shown in the output
+of 'svn status'"
+ ;; (message "svn-status-make-dummy-dirs %S" dir-list)
+ (let ((candidate)
+ (base-dir))
+ (dolist (dir dir-list)
+ (setq base-dir (file-name-directory dir))
+ (while base-dir
+ ;;(message "dir: %S dir-list: %S, base-dir: %S" dir dir-list base-dir)
+ (setq candidate (replace-regexp-in-string "/+$" "" base-dir))
+ (setq base-dir (file-name-directory candidate))
+ ;; (message "dir: %S, candidate: %S" dir candidate)
+ (add-to-list 'dir-list candidate))))
+ ;; (message "svn-status-make-dummy-dirs %S" dir-list)
+ (append (mapcar (lambda (dir)
+ (svn-status-make-line-info
+ dir
+ (gethash dir old-ui-information)))
+ dir-list)
+ svn-status-info))
+
+(defun svn-status-make-line-info (&optional
+ path
+ ui
+ file-mark prop-mark
+ local-rev last-change-rev
+ author
+ update-mark
+ locked-mark
+ with-history-mark
+ switched-mark
+ locked-repo-mark
+ psvn-extra-info)
+ "Create a new line-info from the given arguments
+Anything left nil gets a sensible default.
+nb: LOCKED-MARK refers to the kind of locks you get after an error,
+ LOCKED-REPO-MARK is the kind managed with `svn lock'"
+ (list (or ui (svn-status-make-ui-status))
+ (or file-mark ? )
+ (or prop-mark ? )
+ (or path "")
+ (or local-rev ? )
+ (or last-change-rev ? )
+ (or author "")
+ update-mark
+ locked-mark
+ with-history-mark
+ switched-mark
+ locked-repo-mark
+ psvn-extra-info))
+
+(defvar svn-user-names-including-blanks nil "A list of svn user names that include blanks.
+To add support for the names \"feng shui\" and \"mister blank\", place the following in your .emacs:
+ (setq svn-user-names-including-blanks '(\"feng shui\" \"mister blank\"))
+ (add-hook 'svn-pre-parse-status-hook 'svn-status-parse-fixup-user-names-including-blanks)
+")
+;;(setq svn-user-names-including-blanks '("feng shui" "mister blank"))
+;;(add-hook 'svn-pre-parse-status-hook 'svn-status-parse-fixup-user-names-including-blanks)
+
+(defun svn-status-parse-fixup-user-names-including-blanks ()
+ "Helper function to allow user names that include blanks.
+Add this function to the `svn-pre-parse-status-hook'. The variable
+`svn-user-names-including-blanks' must be configured to hold all user names that contain
+blanks. This function replaces the blanks with '-' to allow further processing with
+the usual parsing functionality in `svn-parse-status-result'."
+ (when svn-user-names-including-blanks
+ (goto-char (point-min))
+ (let ((search-string (concat " \\(" (mapconcat 'concat svn-user-names-including-blanks "\\|") "\\) ")))
+ (save-match-data
+ (save-excursion
+ (while (re-search-forward search-string (point-max) t)
+ (replace-match (replace-regexp-in-string " " "-" (match-string 1)) nil nil nil 1)))))))
+
+(defun svn-parse-status-result ()
+ "Parse the `svn-process-buffer-name' buffer.
+The results are used to build the `svn-status-info' variable."
+ (setq svn-status-head-revision nil)
+ (save-excursion
+ (let ((old-ui-information (svn-status-ui-information-hash-table))
+ (svn-marks)
+ (svn-file-mark)
+ (svn-property-mark)
+ (svn-wc-locked-mark)
+ (svn-repo-locked-mark)
+ (svn-with-history-mark)
+ (svn-switched-mark)
+ (svn-update-mark)
+ (local-rev)
+ (last-change-rev)
+ (author)
+ (path)
+ (dir)
+ (revision-width svn-status-default-revision-width)
+ (author-width svn-status-default-author-width)
+ (svn-marks-length (if svn-status-verbose
+ (if svn-status-remote
+ 8 6)
+ (if svn-status-remote
+ ;; not verbose
+ 8 7)))
+ (dir-set '("."))
+ (externals-map (make-hash-table :test 'equal))
+ (skip-double-external-dir-entry-name nil))
+ (set-buffer svn-process-buffer-name)
+ (setq svn-status-info nil)
+ (run-hooks 'svn-pre-parse-status-hook)
+ (goto-char (point-min))
+ (while (< (point) (point-max))
+ (cond
+ ((= (svn-point-at-eol) (svn-point-at-bol)) ;skip blank lines
+ nil)
+ ((looking-at "Status against revision:[ ]+\\([0-9]+\\)")
+ ;; the above message appears for the main listing plus once for each svn:externals entry
+ (unless svn-status-head-revision
+ (setq svn-status-head-revision (match-string 1))))
+ ((looking-at "Performing status on external item at '\\(.*\\)'")
+ ;; The *next* line has info about the directory named in svn:externals
+ ;; [ie the directory in (match-string 1)]
+ ;; we should parse it, and merge the info with what we have already know
+ ;; but for now just ignore the line completely
+ ; (forward-line)
+ ;; Actually, this seems to not always be the case
+ ;; I have an example where we are in an svn:external which
+ ;; is itself inside a svn:external, this need not be true:
+ ;; the next line is not 'X dir' but just 'dir', so we
+ ;; actually need to parse that line, or the results will
+ ;; not contain dir!
+ ;; so we should merge lines 'X dir' with ' dir', but for now
+ ;; we just leave both in the results
+
+ ;; My attempt to merge the lines uses skip-double-external-dir-entry-name
+ ;; and externals-map
+ (setq skip-double-external-dir-entry-name (svn-match-string-no-properties 1))
+ ;; (message "Going to skip %s" skip-double-external-dir-entry-name)
+ nil)
+ ((looking-at "--- Changelist") ; skip svn changelist header lines
+ ;; See: http://svn.collab.net/repos/svn/trunk/notes/changelist-design.txt
+ nil)
+ (t
+ (setq svn-marks (buffer-substring (point) (+ (point) svn-marks-length))
+ svn-file-mark (elt svn-marks 0) ; 1st column - M,A,C,D,G,? etc
+ svn-property-mark (elt svn-marks 1) ; 2nd column - M,C (properties)
+ svn-wc-locked-mark (elt svn-marks 2) ; 3rd column - L or blank
+ svn-with-history-mark (elt svn-marks 3) ; 4th column - + or blank
+ svn-switched-mark (elt svn-marks 4) ; 5th column - S or blank
+ svn-repo-locked-mark (elt svn-marks 5)) ; 6th column - K,O,T,B or blank
+ (when svn-status-remote
+ (setq svn-update-mark (elt svn-marks 7))) ; 8th column - * or blank
+ (when (eq svn-property-mark ?\ ) (setq svn-property-mark nil))
+ (when (eq svn-wc-locked-mark ?\ ) (setq svn-wc-locked-mark nil))
+ (when (eq svn-with-history-mark ?\ ) (setq svn-with-history-mark nil))
+ (when (eq svn-switched-mark ?\ ) (setq svn-switched-mark nil))
+ (when (eq svn-update-mark ?\ ) (setq svn-update-mark nil))
+ (when (eq svn-repo-locked-mark ?\ ) (setq svn-repo-locked-mark nil))
+ (forward-char svn-marks-length)
+ (skip-chars-forward " ")
+ ;; (message "after marks: '%s'" (buffer-substring (point) (line-end-position)))
+ (cond
+ ((looking-at "\\([-?]\\|[0-9]+\\) +\\([-?]\\|[0-9]+\\) +\\([^ ]+\\) *\\(.+\\)$")
+ (setq local-rev (svn-parse-rev-num (match-string 1))
+ last-change-rev (svn-parse-rev-num (match-string 2))
+ author (match-string 3)
+ path (match-string 4)))
+ ((looking-at "\\([-?]\\|[0-9]+\\) +\\([^ ]+\\)$")
+ (setq local-rev (svn-parse-rev-num (match-string 1))
+ last-change-rev -1
+ author "?"
+ path (match-string 2)))
+ ((looking-at "\\(.*\\)")
+ (setq path (match-string 1)
+ local-rev -1
+ last-change-rev -1
+ author (if (eq svn-file-mark ?X) "" "?"))) ;clear author of svn:externals dirs
+ (t
+ (error "Unknown status line format")))
+ (unless path (setq path "."))
+ (setq dir (file-name-directory path))
+ (if (and (not svn-status-verbose) dir)
+ (let ((dirname (directory-file-name dir)))
+ (if (not (member dirname dir-set))
+ (setq dir-set (cons dirname dir-set)))))
+ (if (and skip-double-external-dir-entry-name (string= skip-double-external-dir-entry-name path))
+ ;; merge this entry to a previous saved one
+ (let ((info (gethash path externals-map)))
+ ;; (message "skip-double-external-dir-entry-name: %s - path: %s" skip-double-external-dir-entry-name path)
+ (if info
+ (progn
+ (svn-status-line-info->set-localrev info local-rev)
+ (svn-status-line-info->set-lastchangerev info last-change-rev)
+ (svn-status-line-info->set-author info author)
+ (svn-status-message 3 "merging entry for %s to %s" path info)
+ (setq skip-double-external-dir-entry-name nil))
+ (message "psvn: %s not handled correct, please report this case." path)))
+ (setq svn-status-info
+ (cons (svn-status-make-line-info path
+ (gethash path old-ui-information)
+ svn-file-mark
+ svn-property-mark
+ local-rev
+ last-change-rev
+ author
+ svn-update-mark
+ svn-wc-locked-mark
+ svn-with-history-mark
+ svn-switched-mark
+ svn-repo-locked-mark
+ nil) ;;psvn-extra-info
+ svn-status-info)))
+ (when (eq svn-file-mark ?X)
+ (svn-puthash (match-string 1) (car svn-status-info) externals-map)
+ (svn-status-message 3 "found external: %s %S" (match-string 1) (car svn-status-info)))
+ (setq revision-width (max revision-width
+ (length (number-to-string local-rev))
+ (length (number-to-string last-change-rev))))
+ (setq author-width (max author-width (length author)))))
+ (forward-line 1))
+ (unless svn-status-verbose
+ (setq svn-status-info (svn-status-make-dummy-dirs dir-set
+ old-ui-information)))
+ (setq svn-status-default-column
+ (+ 6 revision-width revision-width author-width
+ (if svn-status-short-mod-flag-p 3 0)))
+ (setq svn-status-line-format (format " %%c%%c%%c %%%ds %%%ds %%-%ds"
+ revision-width
+ revision-width
+ author-width))
+ (setq svn-status-info (nreverse svn-status-info))
+ (when svn-status-sort-status-buffer
+ (setq svn-status-info (sort svn-status-info 'svn-status-sort-predicate))))))
+
+;;(string-lessp "." "%") => nil
+;(svn-status-sort-predicate '(t t t ".") '(t t t "%")) => t
+(defun svn-status-sort-predicate (a b)
+ "Return t if A should appear before B in the `svn-status-buffer-name' buffer.
+A and B must be line-info's."
+ (string-lessp (concat (svn-status-line-info->full-path a) "/")
+ (concat (svn-status-line-info->full-path b) "/")))
+
+(defun svn-status-remove-temp-file-maybe ()
+ "Remove any (no longer required) temporary files created by psvn.el."
+ (when svn-status-temp-file-to-remove
+ (when (file-exists-p svn-status-temp-file-to-remove)
+ (delete-file svn-status-temp-file-to-remove))
+ (when (file-exists-p svn-status-temp-arg-file)
+ (delete-file svn-status-temp-arg-file))
+ (setq svn-status-temp-file-to-remove nil)))
+
+(defun svn-status-remove-control-M ()
+ "Remove ^M at end of line in the whole buffer."
+ (interactive)
+ (let ((buffer-read-only nil))
+ (save-match-data
+ (save-excursion
+ (goto-char (point-min))
+ (while (re-search-forward "\r$" (point-max) t)
+ (replace-match "" nil nil))))))
+
+(condition-case nil
+ ;;(easy-menu-add-item nil '("tools") ["SVN Status" svn-status t] "PCL-CVS")
+ (easy-menu-add-item nil '("tools") ["SVN Status" svn-status t])
+ (error (message "psvn: could not install menu")))
+
+(defvar svn-status-mode-map () "Keymap used in `svn-status-mode' buffers.")
+(put 'svn-status-mode-map 'risky-local-variable t) ;for Emacs 20.7
+(defvar svn-status-mode-mark-map ()
+ "Subkeymap used in `svn-status-mode' for mark commands.")
+(put 'svn-status-mode-mark-map 'risky-local-variable t) ;for Emacs 20.7
+(defvar svn-status-mode-property-map ()
+ "Subkeymap used in `svn-status-mode' for property commands.")
+(put 'svn-status-mode-property-map 'risky-local-variable t) ;for Emacs 20.7
+(defvar svn-status-mode-options-map ()
+ "Subkeymap used in `svn-status-mode' for option commands.")
+(put 'svn-status-mode-options-map 'risky-local-variable t) ;for Emacs 20.7
+(defvar svn-status-mode-trac-map ()
+ "Subkeymap used in `svn-status-mode' for trac issue tracker commands.")
+(put 'svn-status-mode-trac-map 'risky-local-variable t) ;for Emacs 20.7
+(defvar svn-status-mode-extension-map ()
+ "Subkeymap used in `svn-status-mode' for some seldom used commands.")
+(put 'svn-status-mode-extension-map 'risky-local-variable t) ;for Emacs 20.7
+(defvar svn-status-mode-branch-map ()
+ "Subkeymap used in `svn-status-mode' for branching commands.")
+(put 'svn-status-mode-extension-map 'risky-local-variable t) ;for Emacs 20.7
+(defvar svn-status-mode-search-map ()
+ "Subkeymap used in `svn-status-mode' for search commands.")
+(put 'svn-status-mode-search-map 'risky-local-variable t) ;for Emacs 20.7
+
+(when (not svn-status-mode-map)
+ (setq svn-status-mode-map (make-sparse-keymap))
+ (suppress-keymap svn-status-mode-map)
+ ;; Don't use (kbd "<return>"); it's unreachable with GNU Emacs 21.3 on a TTY.
+ (define-key svn-status-mode-map (kbd "RET") 'svn-status-find-file-or-examine-directory)
+ (define-key svn-status-mode-map (kbd "<mouse-2>") 'svn-status-mouse-find-file-or-examine-directory)
+ (define-key svn-status-mode-map (kbd "^") 'svn-status-examine-parent)
+ (define-key svn-status-mode-map (kbd "s") 'svn-status-show-process-buffer)
+ (define-key svn-status-mode-map (kbd "h") 'svn-status-pop-to-partner-buffer)
+ (define-key svn-status-mode-map (kbd "f") 'svn-status-find-files)
+ (define-key svn-status-mode-map (kbd "o") 'svn-status-find-file-other-window)
+ (define-key svn-status-mode-map (kbd "C-o") 'svn-status-find-file-other-window-noselect)
+ (define-key svn-status-mode-map (kbd "v") 'svn-status-view-file-other-window)
+ (define-key svn-status-mode-map (kbd "e") 'svn-status-toggle-edit-cmd-flag)
+ (define-key svn-status-mode-map (kbd "g") 'svn-status-update)
+ (define-key svn-status-mode-map (kbd "M-s") 'svn-status-update) ;; PCL-CVS compatibility
+ (define-key svn-status-mode-map (kbd "q") 'svn-status-bury-buffer)
+ (define-key svn-status-mode-map (kbd "x") 'svn-status-redraw-status-buffer)
+ (define-key svn-status-mode-map (kbd "H") 'svn-status-use-history)
+ (define-key svn-status-mode-map (kbd "m") 'svn-status-set-user-mark)
+ (define-key svn-status-mode-map (kbd "u") 'svn-status-unset-user-mark)
+ ;; This matches a binding of `dired-unmark-all-files' in `dired-mode-map'
+ ;; of both GNU Emacs and XEmacs. It seems unreachable with XEmacs on
+ ;; TTY, but if that's a problem then its Dired needs fixing too.
+ ;; Or you could just use "*!".
+ (define-key svn-status-mode-map "\M-\C-?" 'svn-status-unset-all-usermarks)
+ ;; The key that normally deletes characters backwards should here
+ ;; instead unmark files backwards. In GNU Emacs, that would be (kbd
+ ;; "DEL") aka [?\177], but XEmacs treats those as [(delete)] and
+ ;; would bind a key that normally deletes forwards. [(backspace)]
+ ;; is unreachable with GNU Emacs on a tty. Try to recognize the
+ ;; dialect and act accordingly.
+ ;;
+ ;; XEmacs has a `delete-forward-p' function that checks the
+ ;; `delete-key-deletes-forward' option. We don't use those, for two
+ ;; reasons: psvn.el may be loaded before user customizations, and
+ ;; XEmacs allows simultaneous connections to multiple devices with
+ ;; different keyboards.
+ (define-key svn-status-mode-map
+ (if (member (kbd "DEL") '([(delete)] [delete]))
+ [(backspace)] ; XEmacs
+ (kbd "DEL")) ; GNU Emacs
+ 'svn-status-unset-user-mark-backwards)
+ (define-key svn-status-mode-map (kbd "$") 'svn-status-toggle-elide)
+ (define-key svn-status-mode-map (kbd "w") 'svn-status-copy-current-line-info)
+ (define-key svn-status-mode-map (kbd ".") 'svn-status-goto-root-or-return)
+ (define-key svn-status-mode-map (kbd "I") 'svn-status-parse-info)
+ (define-key svn-status-mode-map (kbd "V") 'svn-status-svnversion)
+ (define-key svn-status-mode-map (kbd "?") 'svn-status-toggle-hide-unknown)
+ (define-key svn-status-mode-map (kbd "_") 'svn-status-toggle-hide-unmodified)
+ (define-key svn-status-mode-map (kbd "a") 'svn-status-add-file)
+ (define-key svn-status-mode-map (kbd "A") 'svn-status-add-file-recursively)
+ (define-key svn-status-mode-map (kbd "+") 'svn-status-make-directory)
+ (define-key svn-status-mode-map (kbd "R") 'svn-status-mv)
+ (define-key svn-status-mode-map (kbd "C") 'svn-status-cp)
+ (define-key svn-status-mode-map (kbd "D") 'svn-status-rm)
+ (define-key svn-status-mode-map (kbd "c") 'svn-status-commit)
+ (define-key svn-status-mode-map (kbd "M-c") 'svn-status-cleanup)
+ (define-key svn-status-mode-map (kbd "k") 'svn-status-lock)
+ (define-key svn-status-mode-map (kbd "K") 'svn-status-unlock)
+ (define-key svn-status-mode-map (kbd "U") 'svn-status-update-cmd)
+ (define-key svn-status-mode-map (kbd "M-u") 'svn-status-update-cmd)
+ (define-key svn-status-mode-map (kbd "r") 'svn-status-revert)
+ (define-key svn-status-mode-map (kbd "l") 'svn-status-show-svn-log)
+ (define-key svn-status-mode-map (kbd "i") 'svn-status-info)
+ (define-key svn-status-mode-map (kbd "b") 'svn-status-blame)
+ (define-key svn-status-mode-map (kbd "=") 'svn-status-show-svn-diff)
+ ;; [(control ?=)] is unreachable on TTY, but you can use "*u" instead.
+ ;; (Is the "u" mnemonic for something?)
+ (define-key svn-status-mode-map (kbd "C-=") 'svn-status-show-svn-diff-for-marked-files)
+ (define-key svn-status-mode-map (kbd "~") 'svn-status-get-specific-revision)
+ (define-key svn-status-mode-map (kbd "E") 'svn-status-ediff-with-revision)
+
+ (define-key svn-status-mode-map (kbd "n") 'svn-status-next-line)
+ (define-key svn-status-mode-map (kbd "p") 'svn-status-previous-line)
+ (define-key svn-status-mode-map (kbd "<down>") 'svn-status-next-line)
+ (define-key svn-status-mode-map (kbd "<up>") 'svn-status-previous-line)
+ (define-key svn-status-mode-map (kbd "C-x C-j") 'svn-status-dired-jump)
+ (define-key svn-status-mode-map [down-mouse-3] 'svn-status-popup-menu))
+
+(when (not svn-status-mode-mark-map)
+ (setq svn-status-mode-mark-map (make-sparse-keymap))
+ (define-key svn-status-mode-map (kbd "*") svn-status-mode-mark-map)
+ (define-key svn-status-mode-mark-map (kbd "!") 'svn-status-unset-all-usermarks)
+ (define-key svn-status-mode-mark-map (kbd "?") 'svn-status-mark-unknown)
+ (define-key svn-status-mode-mark-map (kbd "A") 'svn-status-mark-added)
+ (define-key svn-status-mode-mark-map (kbd "M") 'svn-status-mark-modified)
+ (define-key svn-status-mode-mark-map (kbd "P") 'svn-status-mark-modified-properties)
+ (define-key svn-status-mode-mark-map (kbd "D") 'svn-status-mark-deleted)
+ (define-key svn-status-mode-mark-map (kbd "*") 'svn-status-mark-changed)
+ (define-key svn-status-mode-mark-map (kbd ".") 'svn-status-mark-by-file-ext)
+ (define-key svn-status-mode-mark-map (kbd "%") 'svn-status-mark-filename-regexp)
+ (define-key svn-status-mode-mark-map (kbd "s") 'svn-status-store-usermarks)
+ (define-key svn-status-mode-mark-map (kbd "l") 'svn-status-load-usermarks)
+ (define-key svn-status-mode-mark-map (kbd "u") 'svn-status-show-svn-diff-for-marked-files))
+
+(when (not svn-status-mode-search-map)
+ (setq svn-status-mode-search-map (make-sparse-keymap))
+ (define-key svn-status-mode-search-map (kbd "g") 'svn-status-grep-files)
+ (define-key svn-status-mode-search-map (kbd "s") 'svn-status-search-files)
+ (define-key svn-status-mode-map (kbd "S") svn-status-mode-search-map))
+
+(when (not svn-status-mode-property-map)
+ (setq svn-status-mode-property-map (make-sparse-keymap))
+ (define-key svn-status-mode-property-map (kbd "l") 'svn-status-property-list)
+ (define-key svn-status-mode-property-map (kbd "s") 'svn-status-property-set)
+ (define-key svn-status-mode-property-map (kbd "d") 'svn-status-property-delete)
+ (define-key svn-status-mode-property-map (kbd "e") 'svn-status-property-edit-one-entry)
+ (define-key svn-status-mode-property-map (kbd "i") 'svn-status-property-ignore-file)
+ (define-key svn-status-mode-property-map (kbd "I") 'svn-status-property-ignore-file-extension)
+ ;; XEmacs 21.4.15 on TTY (vt420) converts `C-i' to `TAB',
+ ;; which [(control ?i)] won't match. Handle it separately.
+ ;; On GNU Emacs, the following two forms bind the same key,
+ ;; reducing clutter in `where-is'.
+ (define-key svn-status-mode-property-map [(control ?i)] 'svn-status-property-edit-svn-ignore)
+ (define-key svn-status-mode-property-map (kbd "TAB") 'svn-status-property-edit-svn-ignore)
+ (define-key svn-status-mode-property-map (kbd "k") 'svn-status-property-set-keyword-list)
+ (define-key svn-status-mode-property-map (kbd "Ki") 'svn-status-property-set-keyword-id)
+ (define-key svn-status-mode-property-map (kbd "Kd") 'svn-status-property-set-keyword-date)
+ (define-key svn-status-mode-property-map (kbd "y") 'svn-status-property-set-eol-style)
+ (define-key svn-status-mode-property-map (kbd "x") 'svn-status-property-set-executable)
+ (define-key svn-status-mode-property-map (kbd "m") 'svn-status-property-set-mime-type)
+ ;; TODO: Why is `svn-status-select-line' in `svn-status-mode-property-map'?
+ (define-key svn-status-mode-property-map (kbd "RET") 'svn-status-select-line)
+ (define-key svn-status-mode-map (kbd "P") svn-status-mode-property-map))
+(when (not svn-status-mode-extension-map)
+ (setq svn-status-mode-extension-map (make-sparse-keymap))
+ (define-key svn-status-mode-extension-map (kbd "v") 'svn-status-resolved)
+ (define-key svn-status-mode-extension-map (kbd "X") 'svn-status-resolve-conflicts)
+ (define-key svn-status-mode-extension-map (kbd "e") 'svn-status-export)
+ (define-key svn-status-mode-map (kbd "X") svn-status-mode-extension-map))
+(when (not svn-status-mode-options-map)
+ (setq svn-status-mode-options-map (make-sparse-keymap))
+ (define-key svn-status-mode-options-map (kbd "s") 'svn-status-save-state)
+ (define-key svn-status-mode-options-map (kbd "l") 'svn-status-load-state)
+ (define-key svn-status-mode-options-map (kbd "x") 'svn-status-toggle-sort-status-buffer)
+ (define-key svn-status-mode-options-map (kbd "v") 'svn-status-toggle-svn-verbose-flag)
+ (define-key svn-status-mode-options-map (kbd "f") 'svn-status-toggle-display-full-path)
+ (define-key svn-status-mode-options-map (kbd "t") 'svn-status-set-trac-project-root)
+ (define-key svn-status-mode-options-map (kbd "n") 'svn-status-set-module-name)
+ (define-key svn-status-mode-options-map (kbd "c") 'svn-status-set-changelog-style)
+ (define-key svn-status-mode-options-map (kbd "b") 'svn-status-set-branch-list)
+ (define-key svn-status-mode-map (kbd "O") svn-status-mode-options-map))
+(when (not svn-status-mode-trac-map)
+ (setq svn-status-mode-trac-map (make-sparse-keymap))
+ (define-key svn-status-mode-trac-map (kbd "w") 'svn-trac-browse-wiki)
+ (define-key svn-status-mode-trac-map (kbd "t") 'svn-trac-browse-timeline)
+ (define-key svn-status-mode-trac-map (kbd "m") 'svn-trac-browse-roadmap)
+ (define-key svn-status-mode-trac-map (kbd "r") 'svn-trac-browse-report)
+ (define-key svn-status-mode-trac-map (kbd "s") 'svn-trac-browse-source)
+ (define-key svn-status-mode-trac-map (kbd "i") 'svn-trac-browse-ticket)
+ (define-key svn-status-mode-trac-map (kbd "c") 'svn-trac-browse-changeset)
+ (define-key svn-status-mode-map (kbd "T") svn-status-mode-trac-map))
+(when (not svn-status-mode-branch-map)
+ (setq svn-status-mode-branch-map (make-sparse-keymap))
+ (define-key svn-status-mode-branch-map (kbd "d") 'svn-branch-diff)
+ (define-key svn-status-mode-map (kbd "B") svn-status-mode-branch-map))
+
+(easy-menu-define svn-status-mode-menu svn-status-mode-map
+ "'svn-status-mode' menu"
+ '("SVN"
+ ["svn status" svn-status-update t]
+ ["svn update" svn-status-update-cmd t]
+ ["svn commit" svn-status-commit t]
+ ["svn log" svn-status-show-svn-log t]
+ ["svn info" svn-status-info t]
+ ["svn blame" svn-status-blame t]
+ ("Diff"
+ ["svn diff current file" svn-status-show-svn-diff t]
+ ["svn diff marked files" svn-status-show-svn-diff-for-marked-files t]
+ ["svn ediff current file" svn-status-ediff-with-revision t]
+ ["svn resolve conflicts" svn-status-resolve-conflicts]
+ )
+ ("Search"
+ ["Grep marked files" svn-status-grep-files t]
+ ["Search marked files" svn-status-search-files t]
+ )
+ ["svn cat ..." svn-status-get-specific-revision t]
+ ["svn add" svn-status-add-file t]
+ ["svn add recursively" svn-status-add-file-recursively t]
+ ["svn mkdir..." svn-status-make-directory t]
+ ["svn mv..." svn-status-mv t]
+ ["svn cp..." svn-status-cp t]
+ ["svn rm..." svn-status-rm t]
+ ["svn export..." svn-status-export t]
+ ["Up Directory" svn-status-examine-parent t]
+ ["Elide Directory" svn-status-toggle-elide t]
+ ["svn revert" svn-status-revert t]
+ ["svn resolved" svn-status-resolved t]
+ ["svn cleanup" svn-status-cleanup t]
+ ["svn lock" svn-status-lock t]
+ ["svn unlock" svn-status-unlock t]
+ ["Show Process Buffer" svn-status-show-process-buffer t]
+ ("Branch"
+ ["diff" svn-branch-diff t]
+ ["Set Branch list" svn-status-set-branch-list t]
+ )
+ ("Property"
+ ["svn proplist" svn-status-property-list t]
+ ["Set Multiple Properties..." svn-status-property-set t]
+ ["Edit One Property..." svn-status-property-edit-one-entry t]
+ ["svn propdel..." svn-status-property-delete t]
+ "---"
+ ["svn:ignore File..." svn-status-property-ignore-file t]
+ ["svn:ignore File Extension..." svn-status-property-ignore-file-extension t]
+ ["Edit svn:ignore Property" svn-status-property-edit-svn-ignore t]
+ "---"
+ ["Edit svn:keywords List" svn-status-property-set-keyword-list t]
+ ["Add/Remove Id to/from svn:keywords" svn-status-property-set-keyword-id t]
+ ["Add/Remove Date to/from svn:keywords" svn-status-property-set-keyword-date t]
+ "---"
+ ["Select svn:eol-style" svn-status-property-set-eol-style t]
+ ["Set svn:executable" svn-status-property-set-executable t]
+ ["Set svn:mime-type" svn-status-property-set-mime-type t]
+ )
+ ("Options"
+ ["Save Options" svn-status-save-state t]
+ ["Load Options" svn-status-load-state t]
+ ["Set Trac project root" svn-status-set-trac-project-root t]
+ ["Set Short module name" svn-status-set-module-name t]
+ ["Set Changelog style" svn-status-set-changelog-style t]
+ ["Set Branch list" svn-status-set-branch-list t]
+ ["Sort the *svn-status* buffer" svn-status-toggle-sort-status-buffer
+ :style toggle :selected svn-status-sort-status-buffer]
+ ["Use -v for svn status calls" svn-status-toggle-svn-verbose-flag
+ :style toggle :selected svn-status-verbose]
+ ["Display full path names" svn-status-toggle-display-full-path
+ :style toggle :selected svn-status-display-full-path]
+ )
+ ("Trac"
+ ["Browse wiki" svn-trac-browse-wiki t]
+ ["Browse timeline" svn-trac-browse-timeline t]
+ ["Browse roadmap" svn-trac-browse-roadmap t]
+ ["Browse source" svn-trac-browse-source t]
+ ["Browse report" svn-trac-browse-report t]
+ ["Browse ticket" svn-trac-browse-ticket t]
+ ["Browse changeset" svn-trac-browse-changeset t]
+ ["Set Trac project root" svn-status-set-trac-project-root t]
+ )
+ "---"
+ ["Edit Next SVN Cmd Line" svn-status-toggle-edit-cmd-flag t]
+ ["Work Directory History..." svn-status-use-history t]
+ ("Mark / Unmark"
+ ["Mark" svn-status-set-user-mark t]
+ ["Unmark" svn-status-unset-user-mark t]
+ ["Unmark all" svn-status-unset-all-usermarks t]
+ "---"
+ ["Mark/Unmark unknown" svn-status-mark-unknown t]
+ ["Mark/Unmark modified" svn-status-mark-modified t]
+ ["Mark/Unmark modified properties" svn-status-mark-modified-properties t]
+ ["Mark/Unmark added" svn-status-mark-added t]
+ ["Mark/Unmark deleted" svn-status-mark-deleted t]
+ ["Mark/Unmark modified/added/deleted" svn-status-mark-changed t]
+ ["Mark/Unmark filename by extension" svn-status-mark-by-file-ext t]
+ ["Mark/Unmark filename by regexp" svn-status-mark-filename-regexp t]
+ ["Store Usermarks" svn-status-store-usermarks t]
+ ["Load Usermarks" svn-status-load-usermarks t]
+ )
+ ["Hide Unknown" svn-status-toggle-hide-unknown
+ :style toggle :selected svn-status-hide-unknown]
+ ["Hide Unmodified" svn-status-toggle-hide-unmodified
+ :style toggle :selected svn-status-hide-unmodified]
+ ["Show Client versions" svn-status-version t]
+ ["Prepare bug report" svn-prepare-bug-report t]
+ ))
+
+(defvar svn-status-file-popup-menu-list
+ '(["open" svn-status-find-file-other-window t]
+ ["svn diff" svn-status-show-svn-diff t]
+ ["svn commit" svn-status-commit t]
+ ["svn log" svn-status-show-svn-log t]
+ ["svn blame" svn-status-blame t]
+ ["mark" svn-status-set-user-mark t]
+ ["unmark" svn-status-unset-user-mark t]
+ ["svn add" svn-status-add-file t]
+ ["svn add recursively" svn-status-add-file-recursively t]
+ ["svn mv..." svn-status-mv t]
+ ["svn rm..." svn-status-rm t]
+ ["svn lock" svn-status-lock t]
+ ["svn unlock" svn-status-unlock t]
+ ["svn info" svn-status-info t]
+ ) "A list of menu entries for `svn-status-popup-menu'")
+
+;; extend svn-status-file-popup-menu-list via:
+;; (add-to-list 'svn-status-file-popup-menu-list ["commit" svn-status-commit t])
+
+(defun svn-status-popup-menu (event)
+ "Display a file specific popup menu"
+ (interactive "e")
+ (mouse-set-point event)
+ (let* ((line-info (svn-status-get-line-information))
+ (name (svn-status-line-info->filename line-info)))
+ (when line-info
+ (easy-menu-define svn-status-actual-popup-menu nil nil
+ (append (list name) svn-status-file-popup-menu-list))
+ (svn-status-face-set-temporary-during-popup
+ 'svn-status-marked-popup-face (svn-point-at-bol) (svn-point-at-eol)
+ svn-status-actual-popup-menu))))
+
+(defun svn-status-face-set-temporary-during-popup (face begin end menu &optional prefix)
+ "Put FACE on BEGIN and END in the buffer during Popup MENU.
+PREFIX is passed to `popup-menu'."
+ (let (o)
+ (unwind-protect
+ (progn
+ (setq o (make-overlay begin end))
+ (overlay-put o 'face face)
+ (sit-for 0)
+ (popup-menu menu prefix))
+ (delete-overlay o))))
+
+(defun svn-status-mode ()
+ "Major mode used by psvn.el to display the output of \"svn status\".
+
+The Output has the following format:
+ FPH BASE CMTD Author em File
+F = Filemark
+P = Property mark
+H = History mark
+BASE = local base revision
+CMTD = last committed revision
+Author = author of change
+em = \"**\" or \"(Update Available)\" [see `svn-status-short-mod-flag-p']
+ if file can be updated
+File = path/filename
+
+The following keys are defined:
+\\{svn-status-mode-map}"
+ (interactive)
+ (kill-all-local-variables)
+
+ (use-local-map svn-status-mode-map)
+ (easy-menu-add svn-status-mode-menu)
+
+ (setq major-mode 'svn-status-mode)
+ (setq mode-name "svn-status")
+ (setq mode-line-process 'svn-status-mode-line-process)
+ (run-hooks 'svn-status-mode-hook)
+ (let ((view-read-only nil))
+ (toggle-read-only 1)))
+
+(defun svn-status-update-mode-line ()
+ (setq svn-status-mode-line-process
+ (concat svn-status-mode-line-process-edit-flag svn-status-mode-line-process-status))
+ (force-mode-line-update))
+
+(defun svn-status-bury-buffer (arg)
+ "Bury the buffers used by psvn.el
+Currently this is:
+ `svn-status-buffer-name'
+ `svn-process-buffer-name'
+ `svn-log-edit-buffer-name'
+ *svn-property-edit*
+ *svn-log*
+ *svn-info*
+When called with a prefix argument, ARG, switch back to the window configuration that was
+in use before `svn-status' was called."
+ (interactive "P")
+ (cond (arg
+ (when svn-status-initial-window-configuration
+ (set-window-configuration svn-status-initial-window-configuration)))
+ (t
+ (let ((bl `(,svn-log-edit-buffer-name "*svn-property-edit*" "*svn-log*" "*svn-info*" ,svn-process-buffer-name)))
+ (while bl
+ (when (get-buffer (car bl))
+ (bury-buffer (car bl)))
+ (setq bl (cdr bl)))
+ (when (string= (buffer-name) svn-status-buffer-name)
+ (bury-buffer))))))
+
+(defun svn-status-save-some-buffers (&optional tree)
+ "Save all buffers visiting a file in TREE.
+If TREE is not given, try `svn-status-base-dir' as TREE."
+ (interactive)
+ ;; (message "svn-status-save-some-buffers: tree1: %s" tree)
+ (let ((ok t)
+ (tree (or (svn-status-base-dir)
+ tree)))
+ ;; (message "svn-status-save-some-buffers: tree2: %s" tree)
+ (unless tree
+ (error "Not in a svn project tree"))
+ (dolist (buffer (buffer-list))
+ (with-current-buffer buffer
+ (when (buffer-modified-p)
+ (let ((file (buffer-file-name)))
+ (when file
+ (let ((root (svn-status-base-dir (file-name-directory file))))
+ ;; (message "svn-status-save-some-buffers: file: %s, root: %s" file root)
+ (when (and root
+ (string= root tree)
+ ;; buffer is modified and in the tree TREE.
+ (or (y-or-n-p (concat "Save buffer " (buffer-name) "? "))
+ (setq ok nil)))
+ (save-buffer))))))))
+ ok))
+
+(defun svn-status-find-files ()
+ "Open selected file(s) for editing.
+See `svn-status-marked-files' for what counts as selected."
+ (interactive)
+ (let ((fnames (mapcar 'svn-status-line-info->full-path (svn-status-marked-files))))
+ (mapc 'find-file fnames)))
+
+
+(defun svn-status-find-file-other-window ()
+ "Open the file in the other window for editing."
+ (interactive)
+ (svn-status-ensure-cursor-on-file)
+ (find-file-other-window (svn-status-line-info->filename
+ (svn-status-get-line-information))))
+
+(defun svn-status-find-file-other-window-noselect ()
+ "Open the file in the other window for editing, but don't select it."
+ (interactive)
+ (svn-status-ensure-cursor-on-file)
+ (display-buffer
+ (find-file-noselect (svn-status-line-info->filename
+ (svn-status-get-line-information)))))
+
+(defun svn-status-view-file-other-window ()
+ "Open the file in the other window for viewing."
+ (interactive)
+ (svn-status-ensure-cursor-on-file)
+ (view-file-other-window (svn-status-line-info->filename
+ (svn-status-get-line-information))))
+
+(defun svn-status-find-file-or-examine-directory ()
+ "If point is on a directory, run `svn-status' on that directory.
+Otherwise run `find-file'."
+ (interactive)
+ (svn-status-ensure-cursor-on-file)
+ (let ((line-info (svn-status-get-line-information)))
+ (if (svn-status-line-info->directory-p line-info)
+ (svn-status (svn-status-line-info->full-path line-info))
+ (find-file (svn-status-line-info->filename line-info)))))
+
+(defun svn-status-examine-parent ()
+ "Run `svn-status' on the parent of the current directory."
+ (interactive)
+ (svn-status (expand-file-name "../")))
+
+(defun svn-status-mouse-find-file-or-examine-directory (event)
+ "Move point to where EVENT occurred, and do `svn-status-find-file-or-examine-directory'
+EVENT could be \"mouse clicked\" or similar."
+ (interactive "e")
+ (mouse-set-point event)
+ (svn-status-find-file-or-examine-directory))
+
+(defun svn-status-line-info->ui-status (line-info)
+ "Return the ui-status structure of LINE-INFO.
+See `svn-status-make-ui-status' for information about the ui-status."
+ (nth 0 line-info))
+
+(defun svn-status-line-info->has-usermark (line-info) (nth 0 (nth 0 line-info)))
+(defun svn-status-line-info->user-elide (line-info) (nth 1 (nth 0 line-info)))
+
+(defun svn-status-line-info->filemark (line-info) (nth 1 line-info))
+(defun svn-status-line-info->propmark (line-info) (nth 2 line-info))
+(defun svn-status-line-info->filename (line-info) (nth 3 line-info))
+(defun svn-status-line-info->filename-nondirectory (line-info)
+ (file-name-nondirectory (svn-status-line-info->filename line-info)))
+(defun svn-status-line-info->localrev (line-info)
+ (if (>= (nth 4 line-info) 0)
+ (nth 4 line-info)
+ nil))
+(defun svn-status-line-info->lastchangerev (line-info)
+ "Return the last revision in which LINE-INFO was modified."
+ (let ((l (nth 5 line-info)))
+ (if (and l (>= l 0))
+ l
+ nil)))
+(defun svn-status-line-info->author (line-info)
+ "Return the last author that changed the item that is represented in LINE-INFO."
+ (nth 6 line-info))
+(defun svn-status-line-info->update-available (line-info)
+ "Return whether LINE-INFO is out of date.
+In other words, whether there is a newer version available in the
+repository than the working copy."
+ (nth 7 line-info))
+(defun svn-status-line-info->locked (line-info)
+ "Return whether LINE-INFO represents a locked file.
+This is column three of the `svn status' output.
+The result will be nil or \"L\".
+\(A file becomes locked when an operation is interrupted; run \\[svn-status-cleanup]'
+to unlock it.\)"
+ (nth 8 line-info))
+(defun svn-status-line-info->historymark (line-info)
+ "Mark from column four of output from `svn status'.
+This will be nil unless the file is scheduled for addition with
+history, when it will be \"+\"."
+ (nth 9 line-info))
+(defun svn-status-line-info->switched (line-info)
+ "Return whether LINE-INFO is switched relative to its parent.
+This is column five of the output from `svn status'.
+The result will be nil or \"S\"."
+ (nth 10 line-info))
+(defun svn-status-line-info->repo-locked (line-info)
+ "Return whether LINE-INFO contains some locking information.
+This is column six of the output from `svn status'.
+The result will be \"K\", \"O\", \"T\", \"B\" or nil."
+ (nth 11 line-info))
+(defun svn-status-line-info->psvn-extra-info (line-info)
+ "Return a list of extra information for psvn associated with LINE-INFO.
+This list holds currently only one element:
+* The action after a commit or update."
+ (nth 12 line-info))
+
+(defun svn-status-line-info->is-visiblep (line-info)
+ "Return whether the line is visible or not"
+ (or (not (or (svn-status-line-info->hide-because-unknown line-info)
+ (svn-status-line-info->hide-because-unmodified line-info)
+ (svn-status-line-info->hide-because-custom-hide-function line-info)
+ (svn-status-line-info->hide-because-user-elide line-info)))
+ (svn-status-line-info->update-available line-info) ;; show the line, if an update is available
+ (svn-status-line-info->psvn-extra-info line-info) ;; show the line, if there is some extra info displayed on this line
+ ))
+
+(defun svn-status-line-info->hide-because-unknown (line-info)
+ (and svn-status-hide-unknown
+ (eq (svn-status-line-info->filemark line-info) ??)))
+
+(defun svn-status-line-info->hide-because-custom-hide-function (line-info)
+ (and svn-status-custom-hide-function
+ (apply svn-status-custom-hide-function (list line-info))))
+
+(defun svn-status-line-info->hide-because-unmodified (line-info)
+ ;;(message " %S %S %S %S - %s" svn-status-hide-unmodified (svn-status-line-info->propmark line-info) ?_
+ ;; (svn-status-line-info->filemark line-info) (svn-status-line-info->filename line-info))
+ (and svn-status-hide-unmodified
+ (and (or (eq (svn-status-line-info->filemark line-info) ?_)
+ (eq (svn-status-line-info->filemark line-info) ? ))
+ (or (eq (svn-status-line-info->propmark line-info) ?_)
+ (eq (svn-status-line-info->propmark line-info) ? )
+ (eq (svn-status-line-info->propmark line-info) nil)))))
+
+(defun svn-status-line-info->hide-because-user-elide (line-info)
+ (eq (svn-status-line-info->user-elide line-info) t))
+
+(defun svn-status-line-info->show-user-elide-continuation (line-info)
+ (eq (svn-status-line-info->user-elide line-info) 'directory))
+
+;; modify the line-info
+(defun svn-status-line-info->set-filemark (line-info value)
+ (setcar (nthcdr 1 line-info) value))
+
+(defun svn-status-line-info->set-propmark (line-info value)
+ (setcar (nthcdr 2 line-info) value))
+
+(defun svn-status-line-info->set-localrev (line-info value)
+ (setcar (nthcdr 4 line-info) value))
+
+(defun svn-status-line-info->set-author (line-info value)
+ (setcar (nthcdr 6 line-info) value))
+
+(defun svn-status-line-info->set-lastchangerev (line-info value)
+ (setcar (nthcdr 5 line-info) value))
+
+(defun svn-status-line-info->set-repo-locked (line-info value)
+ (setcar (nthcdr 11 line-info) value))
+
+(defun svn-status-line-info->set-psvn-extra-info (line-info value)
+ (setcar (nthcdr 12 line-info) value))
+
+(defun svn-status-copy-current-line-info (arg)
+ "Copy the current file name at point, using `svn-status-copy-filename-as-kill'.
+If no file is at point, copy everything starting from ':' to the end of line."
+ (interactive "P")
+ (if (svn-status-get-line-information)
+ (svn-status-copy-filename-as-kill arg)
+ (save-excursion
+ (goto-char (svn-point-at-bol))
+ (when (looking-at ".+?: *\\(.+\\)$")
+ (kill-new (svn-match-string-no-properties 1))
+ (message "Copied: %s" (svn-match-string-no-properties 1))))))
+
+(defun svn-status-copy-filename-as-kill (arg)
+ "Copy the actual file name to the kill-ring.
+When called with the prefix argument 0, use the full path name."
+ (interactive "P")
+ (let ((str (if (eq arg 0)
+ (svn-status-line-info->full-path (svn-status-get-line-information))
+ (svn-status-line-info->filename (svn-status-get-line-information)))))
+ (kill-new str)
+ (message "Copied %s" str)))
+
+(defun svn-status-get-child-directories (&optional dir)
+ "Return a list of subdirectories for DIR"
+ (interactive)
+ (let ((this-dir (concat (expand-file-name (or dir (svn-status-line-info->filename (svn-status-get-line-information)))) "/"))
+ (test-dir)
+ (sub-dir-list))
+ ;;(message "this-dir %S" this-dir)
+ (dolist (line-info svn-status-info)
+ (when (svn-status-line-info->directory-p line-info)
+ (setq test-dir (svn-status-line-info->full-path line-info))
+ (when (string= (file-name-directory test-dir) this-dir)
+ (add-to-list 'sub-dir-list (file-relative-name (svn-status-line-info->full-path line-info)) t))))
+ sub-dir-list))
+
+(defun svn-status-toggle-elide (arg)
+ "Toggle eliding of the current file or directory.
+When called with a prefix argument, toggle the hiding of all subdirectories for the current directory."
+ (interactive "P")
+ (if arg
+ (let ((cur-line (svn-status-line-info->filename (svn-status-get-line-information))))
+ (when (svn-status-line-info->user-elide (svn-status-get-line-information))
+ (svn-status-toggle-elide nil))
+ (dolist (dir-name (svn-status-get-child-directories))
+ (svn-status-goto-file-name dir-name)
+ (svn-status-toggle-elide nil))
+ (svn-status-goto-file-name cur-line))
+ (let ((st-info svn-status-info)
+ (fname)
+ (test (svn-status-line-info->filename (svn-status-get-line-information)))
+ (len-test)
+ (len-fname)
+ (new-elide-mark t)
+ (elide-mark))
+ (if (member test svn-status-elided-list)
+ (setq svn-status-elided-list (delete test svn-status-elided-list))
+ (add-to-list 'svn-status-elided-list test))
+ (when (string= test ".")
+ (setq test ""))
+ (setq len-test (length test))
+ (while st-info
+ (setq fname (svn-status-line-info->filename (car st-info)))
+ (setq len-fname (length fname))
+ (when (and (>= len-fname len-test)
+ (string= (substring fname 0 len-test) test))
+ (setq elide-mark new-elide-mark)
+ (when (or (string= fname ".")
+ (and (= len-fname len-test) (svn-status-line-info->directory-p (car st-info))))
+ (message "Elided directory %s and all its files." fname)
+ (setq new-elide-mark (not (svn-status-line-info->user-elide (car st-info))))
+ (setq elide-mark (if new-elide-mark 'directory nil)))
+ ;;(message "elide-mark: %S member: %S" elide-mark (member fname svn-status-elided-list))
+ (when (and (member fname svn-status-elided-list) (not elide-mark))
+ (setq svn-status-elided-list (delete fname svn-status-elided-list)))
+ (setcar (nthcdr 1 (svn-status-line-info->ui-status (car st-info))) elide-mark))
+ (setq st-info (cdr st-info))))
+ ;;(message "svn-status-elided-list: %S" svn-status-elided-list)
+ (svn-status-update-buffer)))
+
+(defun svn-status-apply-elide-list ()
+ "Elide files/directories according to `svn-status-elided-list'."
+ (interactive)
+ (let ((st-info svn-status-info)
+ (fname)
+ (len-fname)
+ (test)
+ (len-test)
+ (elided-list)
+ (elide-mark))
+ (while st-info
+ (setq fname (svn-status-line-info->filename (car st-info)))
+ (setq len-fname (length fname))
+ (setq elided-list svn-status-elided-list)
+ (setq elide-mark nil)
+ (while elided-list
+ (setq test (car elided-list))
+ (when (string= test ".")
+ (setq test ""))
+ (setq len-test (length test))
+ (when (and (>= len-fname len-test)
+ (string= (substring fname 0 len-test) test))
+ (setq elide-mark t)
+ (when (or (string= fname ".")
+ (and (= len-fname len-test) (svn-status-line-info->directory-p (car st-info))))
+ (setq elide-mark 'directory)))
+ (setq elided-list (cdr elided-list)))
+ ;;(message "fname: %s elide-mark: %S" fname elide-mark)
+ (setcar (nthcdr 1 (svn-status-line-info->ui-status (car st-info))) elide-mark)
+ (setq st-info (cdr st-info))))
+ (svn-status-update-buffer))
+
+(defun svn-status-update-with-command-list (cmd-list)
+ (save-excursion
+ (set-buffer svn-status-buffer-name)
+ (let ((st-info)
+ (found)
+ (action)
+ (fname (svn-status-line-info->filename (svn-status-get-line-information)))
+ (fname-pos (point))
+ (column (current-column)))
+ (setq cmd-list (sort cmd-list '(lambda (item1 item2) (string-lessp (car item1) (car item2)))))
+ (while cmd-list
+ (unless st-info (setq st-info svn-status-info))
+ ;;(message "%S" (caar cmd-list))
+ (setq found nil)
+ (while (and (not found) st-info)
+ (setq found (string= (caar cmd-list) (svn-status-line-info->filename (car st-info))))
+ ;;(message "found: %S" found)
+ (unless found (setq st-info (cdr st-info))))
+ (unless found
+ (svn-status-message 3 "psvn: continue to search for %s" (caar cmd-list))
+ (setq st-info svn-status-info)
+ (while (and (not found) st-info)
+ (setq found (string= (caar cmd-list) (svn-status-line-info->filename (car st-info))))
+ (unless found (setq st-info (cdr st-info)))))
+ (if found
+ ;;update the info line
+ (progn
+ (setq action (cadar cmd-list))
+ ;;(message "found %s, action: %S" (caar cmd-list) action)
+ (svn-status-annotate-status-buffer-entry action (car st-info)))
+ (svn-status-message 3 "psvn: did not find %s" (caar cmd-list)))
+ (setq cmd-list (cdr cmd-list)))
+ (if fname
+ (progn
+ (goto-char fname-pos)
+ (svn-status-goto-file-name fname)
+ (goto-char (+ column (svn-point-at-bol))))
+ (goto-char (+ (next-overlay-change (point-min)) svn-status-default-column))))))
+
+(defun svn-status-annotate-status-buffer-entry (action line-info)
+ (let ((tag-string))
+ (svn-status-goto-file-name (svn-status-line-info->filename line-info))
+ (when (and (member action '(committed added))
+ svn-status-commit-rev-number)
+ (svn-status-line-info->set-localrev line-info svn-status-commit-rev-number)
+ (svn-status-line-info->set-lastchangerev line-info svn-status-commit-rev-number))
+ (when svn-status-last-commit-author
+ (svn-status-line-info->set-author line-info svn-status-last-commit-author))
+ (svn-status-line-info->set-psvn-extra-info line-info (list action))
+ (cond ((equal action 'committed)
+ (setq tag-string " <committed>")
+ (when (member (svn-status-line-info->repo-locked line-info) '(?K))
+ (svn-status-line-info->set-repo-locked line-info nil)))
+ ((equal action 'added)
+ (setq tag-string " <added>"))
+ ((equal action 'deleted)
+ (setq tag-string " <deleted>"))
+ ((equal action 'replaced)
+ (setq tag-string " <replaced>"))
+ ((equal action 'updated)
+ (setq tag-string " <updated>"))
+ ((equal action 'updated-props)
+ (setq tag-string " <updated-props>"))
+ ((equal action 'conflicted)
+ (setq tag-string " <conflicted>")
+ (svn-status-line-info->set-filemark line-info ?C))
+ ((equal action 'merged)
+ (setq tag-string " <merged>"))
+ ((equal action 'propset)
+ ;;(setq tag-string " <propset>")
+ (svn-status-line-info->set-propmark line-info svn-status-file-modified-after-save-flag))
+ ((equal action 'added-wc)
+ (svn-status-line-info->set-filemark line-info ?A)
+ (svn-status-line-info->set-localrev line-info 0))
+ ((equal action 'deleted-wc)
+ (svn-status-line-info->set-filemark line-info ?D))
+ (t
+ (error "Unknown action '%s for %s" action (svn-status-line-info->filename line-info))))
+ (when (and tag-string (not (member action '(conflicted merged))))
+ (svn-status-line-info->set-filemark line-info ? )
+ (svn-status-line-info->set-propmark line-info ? ))
+ (let ((buffer-read-only nil))
+ (delete-region (svn-point-at-bol) (svn-point-at-eol))
+ (svn-insert-line-in-status-buffer line-info)
+ (backward-char 1)
+ (when tag-string
+ (insert tag-string))
+ (delete-char 1))))
+
+
+
+;; (svn-status-update-with-command-list '(("++ideas" committed) ("a.txt" committed) ("alf")))
+;; (svn-status-update-with-command-list (svn-status-parse-commit-output))
+
+(defun svn-status-parse-commit-output ()
+ "Parse the output of svn commit.
+Return a list that is suitable for `svn-status-update-with-command-list'"
+ (save-excursion
+ (set-buffer svn-process-buffer-name)
+ (let ((action)
+ (file-name)
+ (skip)
+ (result))
+ (goto-char (point-min))
+ (setq svn-status-commit-rev-number nil)
+ (setq skip nil) ; set to t whenever we find a line not about a committed file
+ (while (< (point) (point-max))
+ (cond ((= (svn-point-at-eol) (svn-point-at-bol)) ;skip blank lines
+ (setq skip t))
+ ((looking-at "Sending")
+ (setq action 'committed))
+ ((looking-at "Adding")
+ (setq action 'added))
+ ((looking-at "Deleting")
+ (setq action 'deleted))
+ ((looking-at "Replacing")
+ (setq action 'replaced))
+ ((looking-at "Transmitting file data")
+ (setq skip t))
+ ((looking-at "Committed revision \\([0-9]+\\)")
+ (setq svn-status-commit-rev-number
+ (string-to-number (svn-match-string-no-properties 1)))
+ (setq skip t))
+ (t ;; this should never be needed(?)
+ (setq action 'unknown)))
+ (unless skip ;found an interesting line
+ (forward-char 15)
+ (when svn-status-operated-on-dot
+ ;; when the commit used . as argument, delete the trailing directory
+ ;; from the svn output
+ (search-forward "/" nil t))
+ (setq file-name (buffer-substring-no-properties (point) (svn-point-at-eol)))
+ (unless svn-status-last-commit-author
+ (setq svn-status-last-commit-author (car (svn-status-info-for-path (expand-file-name (concat default-directory file-name))))))
+ (setq result (cons (list file-name action)
+ result))
+ (setq skip nil))
+ (forward-line 1))
+ result)))
+;;(svn-status-parse-commit-output)
+;;(svn-status-annotate-status-buffer-entry)
+
+(defun svn-status-parse-ar-output ()
+ "Parse the output of svn add|remove.
+Return a list that is suitable for `svn-status-update-with-command-list'"
+ (save-excursion
+ (set-buffer svn-process-buffer-name)
+ (let ((action)
+ (name)
+ (skip)
+ (result))
+ (goto-char (point-min))
+ (while (< (point) (point-max))
+ (cond ((= (svn-point-at-eol) (svn-point-at-bol)) ;skip blank lines
+ (setq skip t))
+ ((looking-at "A")
+ (setq action 'added-wc))
+ ((looking-at "D")
+ (setq action 'deleted-wc))
+ (t ;; this should never be needed(?)
+ (setq action 'unknown)))
+ (unless skip ;found an interesting line
+ (forward-char 10)
+ (setq name (buffer-substring-no-properties (point) (svn-point-at-eol)))
+ (setq result (cons (list name action)
+ result))
+ (setq skip nil))
+ (forward-line 1))
+ result)))
+;; (svn-status-parse-ar-output)
+;; (svn-status-update-with-command-list (svn-status-parse-ar-output))
+
+(defun svn-status-parse-update-output ()
+ "Parse the output of svn update.
+Return a list that is suitable for `svn-status-update-with-command-list'"
+ (save-excursion
+ (set-buffer svn-process-buffer-name)
+ (setq svn-status-update-rev-number nil)
+ (let ((action)
+ (name)
+ (skip)
+ (result))
+ (goto-char (point-min))
+ (while (< (point) (point-max))
+ (cond ((= (svn-point-at-eol) (svn-point-at-bol)) ;skip blank lines
+ (setq skip t))
+ ((looking-at "Updated to revision \\([0-9]+\\)")
+ (setq svn-status-update-rev-number
+ (list t (string-to-number (svn-match-string-no-properties 1))))
+ (setq skip t))
+ ((looking-at "At revision \\([0-9]+\\)")
+ (setq svn-status-update-rev-number
+ (list nil (string-to-number (svn-match-string-no-properties 1))))
+ (setq skip t))
+ ((looking-at "U")
+ (setq action 'updated))
+ ((looking-at "A")
+ (setq action 'added))
+ ((looking-at "D")
+ (setq skip t))
+ ;;(setq action 'deleted)) ;;deleted files are not displayed in the svn status output.
+ ((looking-at "C")
+ (setq action 'conflicted))
+ ((looking-at "G")
+ (setq action 'merged))
+
+ ((looking-at " U")
+ (setq action 'updated-props))
+
+ (t ;; this should never be needed(?)
+ (setq action (concat "parse-update: '"
+ (buffer-substring-no-properties (point) (+ 2 (point))) "'"))))
+ (unless skip ;found an interesting line
+ (forward-char 3)
+ (setq name (buffer-substring-no-properties (point) (svn-point-at-eol)))
+ (setq result (cons (list name action)
+ result))
+ (setq skip nil))
+ (forward-line 1))
+ result)))
+;; (svn-status-parse-update-output)
+;; (svn-status-update-with-command-list (svn-status-parse-update-output))
+
+(defun svn-status-parse-property-output ()
+ "Parse the output of svn propset.
+Return a list that is suitable for `svn-status-update-with-command-list'"
+ (save-excursion
+ (set-buffer svn-process-buffer-name)
+ (let ((result))
+ (dolist (line (split-string (buffer-substring-no-properties (point-min) (point-max)) "\n"))
+ (message "%s" line)
+ (when (string-match "property '\\(.+\\)' set on '\\(.+\\)'" line)
+ ;;(message "property %s - file %s" (match-string 1 line) (match-string 2 line))
+ (setq result (cons (list (match-string 2 line) 'propset) result))))
+ result)))
+
+;; (svn-status-parse-property-output)
+;; (svn-status-update-with-command-list (svn-status-parse-property-output))
+
+
+(defun svn-status-line-info->symlink-p (line-info)
+ "Return non-nil if LINE-INFO refers to a symlink, nil otherwise.
+The value is the name of the file to which it is linked. \(See
+`file-symlink-p'.\)
+
+On win32 systems this won't work, even though symlinks are supported
+by subversion on such systems."
+ ;; on win32 would need to see how svn does symlinks
+ (file-symlink-p (svn-status-line-info->filename line-info)))
+
+(defun svn-status-line-info->directory-p (line-info)
+ "Return t if LINE-INFO refers to a directory, nil otherwise.
+Symbolic links to directories count as directories (see `file-directory-p')."
+ (file-directory-p (svn-status-line-info->filename line-info)))
+
+(defun svn-status-line-info->full-path (line-info)
+ "Return the full path of the file represented by LINE-INFO."
+ (expand-file-name
+ (svn-status-line-info->filename line-info)))
+
+;;Not convinced that this is the fastest way, but...
+(defun svn-status-count-/ (string)
+ "Return number of \"/\"'s in STRING."
+ (let ((n 0)
+ (last 0))
+ (while (setq last (string-match "/" string (1+ last)))
+ (setq n (1+ n)))
+ n))
+
+(defun svn-insert-line-in-status-buffer (line-info)
+ "Format LINE-INFO and insert the result in the current buffer."
+ (let ((usermark (if (svn-status-line-info->has-usermark line-info) "*" " "))
+ (update-available (if (svn-status-line-info->update-available line-info)
+ (svn-add-face (if svn-status-short-mod-flag-p
+ "** "
+ " (Update Available)")
+ 'svn-status-update-available-face)
+ (if svn-status-short-mod-flag-p " " "")))
+ (filename ;; <indentation>file or /path/to/file
+ (concat
+ (if (or svn-status-display-full-path
+ svn-status-hide-unmodified)
+ (svn-add-face
+ (let ((dir-name (file-name-as-directory
+ (svn-status-line-info->directory-containing-line-info
+ line-info nil))))
+ (if (and (<= 2 (length dir-name))
+ (= ?. (aref dir-name 0))
+ (= ?/ (aref dir-name 1)))
+ (substring dir-name 2)
+ dir-name))
+ 'svn-status-directory-face)
+ ;; showing all files, so add indentation
+ (make-string (* 2 (svn-status-count-/
+ (svn-status-line-info->filename line-info)))
+ 32))
+ ;;symlinks get a different face
+ (let ((target (svn-status-line-info->symlink-p line-info)))
+ (if target
+ ;; name -> trget
+ ;; name gets symlink-face, target gets file/directory face
+ (concat
+ (svn-add-face (svn-status-line-info->filename-nondirectory line-info)
+ 'svn-status-symlink-face)
+ " -> "
+ (svn-status-choose-face-to-add
+ ;; TODO: could use different faces for
+ ;; unversioned targets and broken symlinks?
+ (svn-status-line-info->directory-p line-info)
+ target
+ 'svn-status-directory-face
+ 'svn-status-filename-face))
+ ;; else target is not a link
+ (svn-status-choose-face-to-add
+ (svn-status-line-info->directory-p line-info)
+ (svn-status-line-info->filename-nondirectory line-info)
+ 'svn-status-directory-face
+ 'svn-status-filename-face)))
+ ))
+ (elide-hint (if (svn-status-line-info->show-user-elide-continuation line-info) " ..." "")))
+ (svn-puthash (svn-status-line-info->filename line-info)
+ (point)
+ svn-status-filename-to-buffer-position-cache)
+ (insert (svn-status-maybe-add-face
+ (svn-status-line-info->has-usermark line-info)
+ (concat usermark
+ (format svn-status-line-format
+ (svn-status-line-info->filemark line-info)
+ (or (svn-status-line-info->propmark line-info) ? )
+ (or (svn-status-line-info->historymark line-info) ? )
+ (or (svn-status-line-info->localrev line-info) "")
+ (or (svn-status-line-info->lastchangerev line-info) "")
+ (svn-status-line-info->author line-info))
+ (when svn-status-short-mod-flag-p update-available)
+ filename
+ (unless svn-status-short-mod-flag-p update-available)
+ (svn-status-maybe-add-string (svn-status-line-info->locked line-info)
+ " [ LOCKED ]" 'svn-status-locked-face)
+ (svn-status-maybe-add-string (svn-status-line-info->repo-locked line-info)
+ (let ((flag (svn-status-line-info->repo-locked line-info)))
+ (cond ((eq flag ?K) " [ REPO-LOCK-HERE ]")
+ ((eq flag ?O) " [ REPO-LOCK-OTHER ]")
+ ((eq flag ?T) " [ REPO-LOCK-STOLEN ]")
+ ((eq flag ?B) " [ REPO-LOCK-BROKEN ]")
+ (t " [ REPO-LOCK-UNKNOWN ]")))
+ 'svn-status-locked-face)
+ (svn-status-maybe-add-string (svn-status-line-info->switched line-info)
+ " (switched)" 'svn-status-switched-face)
+ elide-hint)
+ 'svn-status-marked-face)
+ "\n")))
+
+(defun svn-status-redraw-status-buffer ()
+ "Redraw the `svn-status-buffer-name' buffer.
+Additionally clear the psvn-extra-info field in all line-info lists."
+ (interactive)
+ (dolist (line-info svn-status-info)
+ (svn-status-line-info->set-psvn-extra-info line-info nil))
+ (svn-status-update-buffer))
+
+(defun svn-status-update-buffer ()
+ "Update the `svn-status-buffer-name' buffer, using `svn-status-info'.
+ This function does not access the repository."
+ (interactive)
+ ;(message "buffer-name: %s" (buffer-name))
+ (unless (string= (buffer-name) svn-status-buffer-name)
+ (set-buffer svn-status-buffer-name))
+ (svn-status-mode)
+ (when svn-status-refresh-info
+ (when (eq svn-status-refresh-info 'once)
+ (setq svn-status-refresh-info nil))
+ (svn-status-parse-info t))
+ (let ((st-info svn-status-info)
+ (buffer-read-only nil)
+ (start-pos)
+ (overlay)
+ (unmodified-count 0) ;how many unmodified files are hidden
+ (unknown-count 0) ;how many unknown files are hidden
+ (custom-hide-count 0) ;how many files are hidden via svn-status-custom-hide-function
+ (marked-count 0) ;how many files are elided
+ (user-elide-count 0)
+ (first-line t)
+ (fname (svn-status-line-info->filename (svn-status-get-line-information)))
+ (fname-pos (point))
+ (window-line-pos (svn-status-window-line-position (get-buffer-window (current-buffer))))
+ (header-line-string)
+ (column (current-column)))
+ (delete-region (point-min) (point-max))
+ (insert "\n")
+ ;; Insert all files and directories
+ (while st-info
+ (setq start-pos (point))
+ (cond ((or (svn-status-line-info->has-usermark (car st-info)) first-line)
+ ;; Show a marked file and the "." always
+ (svn-insert-line-in-status-buffer (car st-info))
+ (setq first-line nil))
+ ((svn-status-line-info->update-available (car st-info))
+ (svn-insert-line-in-status-buffer (car st-info)))
+ ((and svn-status-custom-hide-function
+ (apply svn-status-custom-hide-function (list (car st-info))))
+ (setq custom-hide-count (1+ custom-hide-count)))
+ ((svn-status-line-info->hide-because-user-elide (car st-info))
+ (setq user-elide-count (1+ user-elide-count)))
+ ((svn-status-line-info->hide-because-unknown (car st-info))
+ (setq unknown-count (1+ unknown-count)))
+ ((svn-status-line-info->hide-because-unmodified (car st-info))
+ (setq unmodified-count (1+ unmodified-count)))
+ (t
+ (svn-insert-line-in-status-buffer (car st-info))))
+ (when (svn-status-line-info->has-usermark (car st-info))
+ (setq marked-count (+ marked-count 1)))
+ (setq overlay (make-overlay start-pos (point)))
+ (overlay-put overlay 'svn-info (car st-info))
+ (setq st-info (cdr st-info)))
+ ;; Insert status information at the buffer beginning
+ (goto-char (point-min))
+ (insert (format "svn status for directory %s%s\n"
+ default-directory
+ (if svn-status-head-revision (format " (status against revision: %s)"
+ svn-status-head-revision)
+ "")))
+ (when svn-status-module-name
+ (insert (format "Project name: %s\n" svn-status-module-name)))
+ (when svn-status-branch-list
+ (insert (format "Branches: %s\n" svn-status-branch-list)))
+ (when svn-status-base-info
+ (insert (concat "Repository Root: " (svn-status-base-info->repository-root) "\n"))
+ (insert (concat "Repository Url: " (svn-status-base-info->url) "\n")))
+ (when svn-status-hide-unknown
+ (insert
+ (format "%d Unknown file(s) are hidden - press `?' to toggle hiding\n"
+ unknown-count)))
+ (when svn-status-hide-unmodified
+ (insert
+ (format "%d Unmodified file(s) are hidden - press `_' to toggle hiding\n"
+ unmodified-count)))
+ (when (> custom-hide-count 0)
+ (insert
+ (format "%d file(s) are hidden via the svn-status-custom-hide-function\n"
+ custom-hide-count)))
+ (when (> user-elide-count 0)
+ (insert (format "%d file(s) elided\n" user-elide-count)))
+ (insert (format "%d file(s) marked\n" marked-count))
+ (setq header-line-string (concat (format svn-status-line-format
+ 70 80 72 "BASE" "CMTD" "Author")
+ (if svn-status-short-mod-flag-p "em " "")
+ "File"))
+ (cond ((eq svn-status-use-header-line t)
+ (setq header-line-format (concat " " header-line-string)))
+ ((eq svn-status-use-header-line 'inline)
+ (insert "\n " header-line-string "\n")))
+ (setq svn-start-of-file-list-line-number (+ (count-lines (point-min) (point)) 1))
+ (if fname
+ (progn
+ (goto-char fname-pos)
+ (svn-status-goto-file-name fname)
+ (goto-char (+ column (svn-point-at-bol)))
+ (when window-line-pos
+ (recenter window-line-pos)))
+ (goto-char (+ (next-overlay-change (point-min)) svn-status-default-column)))))
+
+(defun svn-status-parse-info (arg)
+ "Parse the svn info output for the base directory.
+Show the repository url after this call in the `svn-status-buffer-name' buffer.
+When called with the prefix argument 0, reset the information to nil.
+This hides the repository information again.
+
+When ARG is t, don't update the svn status buffer. This is useful for
+non-interactive use."
+ (interactive "P")
+ (if (eq arg 0)
+ (setq svn-status-base-info nil)
+ (let ((svn-process-buffer-name "*svn-info-output*"))
+ (when (get-buffer svn-process-buffer-name)
+ (kill-buffer svn-process-buffer-name))
+ (svn-run nil t 'parse-info "info" ".")
+ (svn-status-parse-info-result)))
+ (unless (eq arg t)
+ (svn-status-update-buffer)))
+
+(defun svn-status-parse-info-result ()
+ "Parse the result from the svn info command.
+Put the found values in `svn-status-base-info'."
+ (let ((url)
+ (repository-root)
+ (last-changed-author))
+ (save-excursion
+ (set-buffer svn-process-buffer-name)
+ (goto-char (point-min))
+ (let ((case-fold-search t))
+ (search-forward "url: ")
+ (setq url (buffer-substring-no-properties (point) (svn-point-at-eol)))
+ (when (search-forward "repository root: " nil t)
+ (setq repository-root (buffer-substring-no-properties (point) (svn-point-at-eol))))
+ (when (search-forward "last changed author: " nil t)
+ (setq last-changed-author (buffer-substring-no-properties (point) (svn-point-at-eol))))))
+ (setq svn-status-base-info `((url ,url) (repository-root ,repository-root) (last-changed-author ,last-changed-author)))))
+
+(defun svn-status-base-info->url ()
+ "Extract the url part from `svn-status-base-info'."
+ (if svn-status-base-info
+ (cadr (assoc 'url svn-status-base-info))
+ ""))
+
+(defun svn-status-base-info->repository-root ()
+ "Extract the repository-root part from `svn-status-base-info'."
+ (if svn-status-base-info
+ (cadr (assoc 'repository-root svn-status-base-info))
+ ""))
+
+(defun svn-status-checkout-prefix-path ()
+ "When only a part of the svn repository is checked out, return the file path for this checkout."
+ (interactive)
+ (svn-status-parse-info t)
+ (let ((root (svn-status-base-info->repository-root))
+ (url (svn-status-base-info->url))
+ (p)
+ (base-dir (svn-status-base-dir))
+ (wc-checkout-prefix))
+ (setq p (substring url (length root)))
+ (setq wc-checkout-prefix (file-relative-name default-directory base-dir))
+ (when (string= wc-checkout-prefix "./")
+ (setq wc-checkout-prefix ""))
+ ;; (message "svn-status-checkout-prefix-path: wc-checkout-prefix: '%s' p: '%s' base-dir: %s" wc-checkout-prefix p base-dir)
+ (setq p (substring p 0 (- (length p) (length wc-checkout-prefix))))
+ (when (interactive-p)
+ (message "svn-status-checkout-prefix-path: '%s'" p))
+ p))
+
+(defun svn-status-ls (path &optional synchron)
+ "Run svn ls PATH."
+ (interactive "sPath for svn ls: ")
+ (svn-run (not synchron) t 'ls "ls" path)
+ (when synchron
+ (split-string (with-current-buffer svn-process-buffer-name
+ (buffer-substring-no-properties (point-min) (point-max))))))
+
+(defun svn-status-ls-branches ()
+ "Show, which branches exist for the actual working copy.
+Note: this command assumes the proposed standard svn repository layout."
+ (interactive)
+ (svn-status-parse-info t)
+ (svn-status-ls (concat (svn-status-base-info->repository-root) "/branches")))
+
+(defun svn-status-ls-tags ()
+ "Show, which tags exist for the actual working copy.
+Note: this command assumes the proposed standard svn repository layout."
+ (interactive)
+ (svn-status-parse-info t)
+ (svn-status-ls (concat (svn-status-base-info->repository-root) "/tags")))
+
+(defun svn-status-toggle-edit-cmd-flag (&optional reset)
+ "Allow the user to edit the parameters for the next svn command.
+This command toggles between
+* editing the next command parameters (EditCmd)
+* editing all all command parameters (EditCmd#)
+* don't edit the command parameters ()
+The string in parentheses is shown in the status line to show the state."
+ (interactive)
+ (cond ((or reset (eq svn-status-edit-svn-command 'sticky))
+ (setq svn-status-edit-svn-command nil))
+ ((eq svn-status-edit-svn-command nil)
+ (setq svn-status-edit-svn-command t))
+ ((eq svn-status-edit-svn-command t)
+ (setq svn-status-edit-svn-command 'sticky)))
+ (cond ((eq svn-status-edit-svn-command t)
+ (setq svn-status-mode-line-process-edit-flag " EditCmd"))
+ ((eq svn-status-edit-svn-command 'sticky)
+ (setq svn-status-mode-line-process-edit-flag " EditCmd#"))
+ (t
+ (setq svn-status-mode-line-process-edit-flag "")))
+ (svn-status-update-mode-line))
+
+(defun svn-status-goto-root-or-return ()
+ "Bounce point between the root (\".\") and the current line."
+ (interactive)
+ (if (string= (svn-status-line-info->filename (svn-status-get-line-information)) ".")
+ (when svn-status-root-return-info
+ (svn-status-goto-file-name
+ (svn-status-line-info->filename svn-status-root-return-info)))
+ (setq svn-status-root-return-info (svn-status-get-line-information))
+ (svn-status-goto-file-name ".")))
+
+(defun svn-status-next-line (nr-of-lines)
+ "Go to the next line that holds a file information.
+When called with a prefix argument advance the given number of lines."
+ (interactive "p")
+ (while (progn
+ (forward-line nr-of-lines)
+ (and (not (eobp))
+ (not (svn-status-get-line-information)))))
+ (when (svn-status-get-line-information)
+ (goto-char (+ (svn-point-at-bol) svn-status-default-column))))
+
+(defun svn-status-previous-line (nr-of-lines)
+ "Go to the previous line that holds a file information.
+When called with a prefix argument go back the given number of lines."
+ (interactive "p")
+ (while (progn
+ (forward-line (- nr-of-lines))
+ (and (not (bobp))
+ (not (svn-status-get-line-information)))))
+ (when (svn-status-get-line-information)
+ (goto-char (+ (svn-point-at-bol) svn-status-default-column))))
+
+(defun svn-status-dired-jump ()
+ "Jump to a dired buffer, containing the file at point."
+ (interactive)
+ (let* ((line-info (svn-status-get-line-information))
+ (file-full-path (if line-info
+ (svn-status-line-info->full-path line-info)
+ default-directory)))
+ (let ((default-directory
+ (file-name-as-directory
+ (expand-file-name (if line-info
+ (svn-status-line-info->directory-containing-line-info line-info t)
+ default-directory)))))
+ (if (fboundp 'dired-jump-back) (dired-jump-back) (dired-jump))) ;; Xemacs uses dired-jump-back
+ (dired-goto-file file-full-path)))
+
+(defun svn-status-possibly-negate-meaning-of-arg (arg &optional command)
+ "Negate arg, if this-command is a member of svn-status-possibly-negate-meaning-of-arg."
+ (unless command
+ (setq command this-command))
+ (if (member command svn-status-negate-meaning-of-arg-commands)
+ (not arg)
+ arg))
+
+(defun svn-status-update (&optional arg)
+ "Run 'svn status -v'.
+When called with a prefix argument run 'svn status -vu'."
+ (interactive "P")
+ (unless (interactive-p)
+ (save-excursion
+ (set-buffer svn-process-buffer-name)
+ (setq svn-status-update-previous-process-output
+ (buffer-substring (point-min) (point-max)))))
+ (svn-status default-directory arg))
+
+(defun svn-status-get-line-information ()
+ "Find out about the file under point.
+The result may be parsed with the various `svn-status-line-info->...' functions."
+ (if (eq major-mode 'svn-status-mode)
+ (let ((svn-info nil))
+ (dolist (overlay (overlays-at (point)))
+ (setq svn-info (or svn-info
+ (overlay-get overlay 'svn-info))))
+ svn-info)
+ ;; different mode, means called not from the *svn-status* buffer
+ (if svn-status-get-line-information-for-file
+ (svn-status-make-line-info (if (eq svn-status-get-line-information-for-file 'relative)
+ (file-relative-name (buffer-file-name) (svn-status-base-dir))
+ (buffer-file-name)))
+ (svn-status-make-line-info "."))))
+
+
+(defun svn-status-get-file-list (use-marked-files)
+ "Get either the selected files or the file under point.
+USE-MARKED-FILES decides which we do.
+See `svn-status-marked-files' for what counts as selected."
+ (if use-marked-files
+ (svn-status-marked-files)
+ (list (svn-status-get-line-information))))
+
+(defun svn-status-get-file-list-names (use-marked-files)
+ (mapcar 'svn-status-line-info->filename (svn-status-get-file-list use-marked-files)))
+
+(defun svn-status-get-file-information ()
+ "Find out about the file under point.
+The result may be parsed with the various `svn-status-line-info->...' functions.
+When called from a *svn-status* buffer, do the same as `svn-status-get-line-information'.
+When called from a file buffer provide a structure that contains the filename."
+ (cond ((eq major-mode 'svn-status-mode)
+ (svn-status-get-line-information))
+ (t
+ ;; a fake strukture that contains the buffername for the current buffer
+ (svn-status-make-line-info (buffer-file-name (current-buffer))))))
+
+(defun svn-status-select-line ()
+ "Return information about the file under point.
+\(Only used for debugging\)"
+ (interactive)
+ (let ((info (svn-status-get-line-information)))
+ (if info
+ (message "%S hide-because-unknown: %S hide-because-unmodified: %S" info
+ (svn-status-line-info->hide-because-unknown info)
+ (svn-status-line-info->hide-because-unmodified info))
+ (message "No file on this line"))))
+
+(defun svn-status-ensure-cursor-on-file ()
+ "Raise an error unless point is on a valid file."
+ (unless (svn-status-get-line-information)
+ (error "No file on the current line")))
+
+(defun svn-status-directory-containing-point (allow-self)
+ "Find the (full path of) directory containing the file under point.
+
+If ALLOW-SELF and the file is a directory, return that directory,
+otherwise return the directory containing the file under point."
+ ;;the first `or' below is because s-s-g-l-i returns `nil' if
+ ;;point was outside the file list, but we need
+ ;;s-s-l-i->f to return a string to add to `default-directory'.
+ (let ((line-info (or (svn-status-get-line-information)
+ (svn-status-make-line-info))))
+ (file-name-as-directory
+ (expand-file-name
+ (svn-status-line-info->directory-containing-line-info line-info allow-self)))))
+
+(defun svn-status-line-info->directory-containing-line-info (line-info allow-self)
+ "Find the directory containing for LINE-INFO.
+
+If ALLOW-SELF is t and LINE-INFO refers to a directory then return the
+directory itself, in all other cases find the parent directory"
+ (if (and allow-self (svn-status-line-info->directory-p line-info))
+ (svn-status-line-info->filename line-info)
+ ;;The next `or' is because (file-name-directory "file") returns nil
+ (or (file-name-directory (svn-status-line-info->filename line-info))
+ ".")))
+
+(defun svn-status-set-user-mark (arg)
+ "Set a user mark on the current file or directory.
+If the cursor is on a file this file is marked and the cursor advances to the next line.
+If the cursor is on a directory all files in this directory are marked.
+
+If this function is called with a prefix argument, only the current line is
+marked, even if it is a directory."
+ (interactive "P")
+ (setq arg (svn-status-possibly-negate-meaning-of-arg arg 'svn-status-set-user-mark))
+ (let ((info (svn-status-get-line-information)))
+ (if info
+ (progn
+ (svn-status-apply-usermark t arg)
+ (svn-status-next-line 1))
+ (message "No file on this line - cannot set a mark"))))
+
+(defun svn-status-unset-user-mark (arg)
+ "Remove a user mark on the current file or directory.
+If the cursor is on a file, this file is unmarked and the cursor advances to the next line.
+If the cursor is on a directory, all files in this directory are unmarked.
+
+If this function is called with a prefix argument, only the current line is
+unmarked, even if is a directory."
+ (interactive "P")
+ (setq arg (svn-status-possibly-negate-meaning-of-arg arg 'svn-status-set-user-mark))
+ (let ((info (svn-status-get-line-information)))
+ (if info
+ (progn
+ (svn-status-apply-usermark nil arg)
+ (svn-status-next-line 1))
+ (message "No file on this line - cannot unset a mark"))))
+
+(defun svn-status-unset-user-mark-backwards ()
+ "Remove a user mark from the previous file.
+Then move to that line."
+ ;; This is consistent with `dired-unmark-backward' and
+ ;; `cvs-mode-unmark-up'.
+ (interactive)
+ (let ((info (save-excursion
+ (svn-status-next-line -1)
+ (svn-status-get-line-information))))
+ (if info
+ (progn
+ (svn-status-next-line -1)
+ (svn-status-apply-usermark nil t))
+ (message "No file on previous line - cannot unset a mark"))))
+
+(defun svn-status-apply-usermark (set-mark only-this-line)
+ "Do the work for the various marking/unmarking functions."
+ (let* ((st-info svn-status-info)
+ (mark-count 0)
+ (line-info (svn-status-get-line-information))
+ (file-name (svn-status-line-info->filename line-info))
+ (sub-file-regexp (if (file-directory-p file-name)
+ (concat "^" (regexp-quote
+ (file-name-as-directory file-name)))
+ nil))
+ (newcursorpos-fname)
+ (i-fname)
+ (first-line t)
+ (current-line svn-start-of-file-list-line-number))
+ (while st-info
+ (when (or (svn-status-line-info->is-visiblep (car st-info)) first-line)
+ (setq current-line (1+ current-line))
+ (setq first-line nil))
+ (setq i-fname (svn-status-line-info->filename (car st-info)))
+ (when (or (string= file-name i-fname)
+ (when sub-file-regexp
+ (string-match sub-file-regexp i-fname)))
+ (when (svn-status-line-info->is-visiblep (car st-info))
+ (when (or (not only-this-line) (string= file-name i-fname))
+ (setq newcursorpos-fname i-fname)
+ (unless (eq (car (svn-status-line-info->ui-status (car st-info))) set-mark)
+ (setcar (svn-status-line-info->ui-status (car st-info)) set-mark)
+ (setq mark-count (+ 1 mark-count))
+ (save-excursion
+ (let ((buffer-read-only nil))
+ (goto-line current-line)
+ (delete-region (svn-point-at-bol) (svn-point-at-eol))
+ (svn-insert-line-in-status-buffer (car st-info))
+ (delete-char 1)))
+ (message "%s %s" (if set-mark "Marked" "Unmarked") i-fname)))))
+ (setq st-info (cdr st-info)))
+ ;;(svn-status-update-buffer)
+ (svn-status-goto-file-name newcursorpos-fname)
+ (when (> mark-count 1)
+ (message "%s %d files" (if set-mark "Marked" "Unmarked") mark-count))))
+
+(defun svn-status-apply-usermark-checked (check-function set-mark)
+ "Mark or unmark files, whether a given function returns t.
+The function is called with the line information. Therefore the
+svn-status-line-info->* functions can be used in the check."
+ (let ((st-info svn-status-info)
+ (mark-count 0))
+ (while st-info
+ (when (apply check-function (list (car st-info)))
+ (unless (eq (svn-status-line-info->has-usermark (car st-info)) set-mark)
+ (setq mark-count (+ 1 mark-count))
+ (message "%s %s"
+ (if set-mark "Marked" "Unmarked")
+ (svn-status-line-info->filename (car st-info))))
+ (setcar (svn-status-line-info->ui-status (car st-info)) set-mark))
+ (setq st-info (cdr st-info)))
+ (svn-status-update-buffer)
+ (when (> mark-count 1)
+ (message "%s %d files" (if set-mark "Marked" "Unmarked") mark-count))))
+
+(defun svn-status-mark-unknown (arg)
+ "Mark all unknown files.
+These are the files marked with '?' in the `svn-status-buffer-name' buffer.
+If the function is called with a prefix arg, unmark all these files."
+ (interactive "P")
+ (svn-status-apply-usermark-checked
+ '(lambda (info) (eq (svn-status-line-info->filemark info) ??)) (not arg)))
+
+(defun svn-status-mark-added (arg)
+ "Mark all added files.
+These are the files marked with 'A' in the `svn-status-buffer-name' buffer.
+If the function is called with a prefix ARG, unmark all these files."
+ (interactive "P")
+ (svn-status-apply-usermark-checked
+ '(lambda (info) (eq (svn-status-line-info->filemark info) ?A)) (not arg)))
+
+(defun svn-status-mark-modified (arg)
+ "Mark all modified files.
+These are the files marked with 'M' in the `svn-status-buffer-name' buffer.
+Changed properties are considered.
+If the function is called with a prefix ARG, unmark all these files."
+ (interactive "P")
+ (svn-status-apply-usermark-checked
+ '(lambda (info) (or (eq (svn-status-line-info->filemark info) ?M)
+ (eq (svn-status-line-info->filemark info)
+ svn-status-file-modified-after-save-flag)
+ (eq (svn-status-line-info->propmark info) ?M)))
+ (not arg)))
+
+(defun svn-status-mark-modified-properties (arg)
+ "Mark all files and directories with modified properties.
+If the function is called with a prefix ARG, unmark all these entries."
+ (interactive "P")
+ (svn-status-apply-usermark-checked
+ '(lambda (info) (or (eq (svn-status-line-info->propmark info) ?M)))
+ (not arg)))
+
+(defun svn-status-mark-deleted (arg)
+ "Mark all files scheduled for deletion.
+These are the files marked with 'D' in the `svn-status-buffer-name' buffer.
+If the function is called with a prefix ARG, unmark all these files."
+ (interactive "P")
+ (svn-status-apply-usermark-checked
+ '(lambda (info) (eq (svn-status-line-info->filemark info) ?D)) (not arg)))
+
+(defun svn-status-mark-changed (arg)
+ "Mark all files that could be committed.
+This means we mark
+* all modified files
+* all files scheduled for addition
+* all files scheduled for deletion
+
+The last two categories include all copied and moved files.
+If called with a prefix ARG, unmark all such files."
+ (interactive "P")
+ (svn-status-mark-added arg)
+ (svn-status-mark-modified arg)
+ (svn-status-mark-deleted arg))
+
+(defun svn-status-unset-all-usermarks ()
+ (interactive)
+ (svn-status-apply-usermark-checked '(lambda (info) t) nil))
+
+(defun svn-status-store-usermarks (arg)
+ "Store the current usermarks in `svn-status-usermark-storage'.
+When called with a prefix argument it is possible to store different sets of marks."
+ (interactive "P")
+ (let ((file-list (svn-status-get-file-list-names t)))
+ (svn-puthash arg file-list svn-status-usermark-storage)
+ (message "psvn stored %d user marks" (length file-list))))
+
+(defun svn-status-load-usermarks (arg)
+ "Load previously stored user marks from `svn-status-usermark-storage'.
+When called with a prefix argument it is possible to store/load different sets of marks."
+ (interactive "P")
+ (let ((file-list (gethash arg svn-status-usermark-storage)))
+ (svn-status-apply-usermark-checked
+ '(lambda (info) (member (svn-status-line-info->filename info) file-list)) t)))
+
+(defvar svn-status-regexp-history nil
+ "History list of regular expressions used in svn status commands.")
+
+(defun svn-status-read-regexp (prompt)
+ (read-from-minibuffer prompt nil nil nil 'svn-status-regexp-history))
+
+(defun svn-status-mark-filename-regexp (regexp &optional unmark)
+ "Mark all files matching REGEXP.
+If the function is called with a prefix arg, unmark all these files."
+ (interactive
+ (list (svn-status-read-regexp (concat (if current-prefix-arg "Unmark" "Mark")
+ " files (regexp): "))
+ (if current-prefix-arg t nil)))
+ (svn-status-apply-usermark-checked
+ '(lambda (info) (string-match regexp (svn-status-line-info->filename-nondirectory info))) (not unmark)))
+
+(defun svn-status-mark-by-file-ext (ext &optional unmark)
+ "Mark all files matching the given file extension EXT.
+If the function is called with a prefix arg, unmark all these files."
+ (interactive
+ (list (read-string (concat (if current-prefix-arg "Unmark" "Mark")
+ " files with extensions: "))
+ (if current-prefix-arg t nil)))
+ (svn-status-apply-usermark-checked
+ '(lambda (info) (let ((case-fold-search nil))
+ (string-match (concat "\\." ext "$") (svn-status-line-info->filename-nondirectory info)))) (not unmark)))
+
+(defun svn-status-toggle-hide-unknown ()
+ (interactive)
+ (setq svn-status-hide-unknown (not svn-status-hide-unknown))
+ (svn-status-update-buffer))
+
+(defun svn-status-toggle-hide-unmodified ()
+ (interactive)
+ (setq svn-status-hide-unmodified (not svn-status-hide-unmodified))
+ (svn-status-update-buffer))
+
+(defun svn-status-get-file-name-buffer-position (name)
+ "Find the buffer position for a file.
+If the file is not found, return nil."
+ (let ((start-pos (let ((cached-pos (gethash name
+ svn-status-filename-to-buffer-position-cache)))
+ (when cached-pos
+ (goto-char (previous-overlay-change cached-pos)))
+ (point)))
+ (found))
+ ;; performance optimization: search from point to end of buffer
+ (while (and (not found) (< (point) (point-max)))
+ (goto-char (next-overlay-change (point)))
+ (when (string= name (svn-status-line-info->filename
+ (svn-status-get-line-information)))
+ (setq start-pos (+ (point) svn-status-default-column))
+ (setq found t)))
+ ;; search from buffer start to point
+ (goto-char (point-min))
+ (while (and (not found) (< (point) start-pos))
+ (goto-char (next-overlay-change (point)))
+ (when (string= name (svn-status-line-info->filename
+ (svn-status-get-line-information)))
+ (setq start-pos (+ (point) svn-status-default-column))
+ (setq found t)))
+ (and found start-pos)))
+
+(defun svn-status-goto-file-name (name)
+ "Move the cursor the the line that displays NAME."
+ (let ((pos (svn-status-get-file-name-buffer-position name)))
+ (if pos
+ (goto-char pos)
+ (svn-status-message 7 "Note: svn-status-goto-file-name: %s not found" name))))
+
+(defun svn-status-find-info-for-file-name (name)
+ (let* ((st-info svn-status-info)
+ (info))
+ (while st-info
+ (when (string= name (svn-status-line-info->filename (car st-info)))
+ (setq info (car st-info))
+ (setq st-info nil)) ; terminate loop
+ (setq st-info (cdr st-info)))
+ info))
+
+(defun svn-status-marked-files ()
+ "Return all files marked by `svn-status-set-user-mark',
+or (if no files were marked) the file under point."
+ (if (eq major-mode 'svn-status-mode)
+ (let* ((st-info svn-status-info)
+ (file-list))
+ (while st-info
+ (when (svn-status-line-info->has-usermark (car st-info))
+ (setq file-list (append file-list (list (car st-info)))))
+ (setq st-info (cdr st-info)))
+ (or file-list
+ (if (svn-status-get-line-information)
+ (list (svn-status-get-line-information))
+ nil)))
+ ;; different mode, means called not from the *svn-status* buffer
+ (if svn-status-get-line-information-for-file
+ (list (svn-status-make-line-info (if (eq svn-status-get-line-information-for-file 'relative)
+ (file-relative-name (buffer-file-name) (svn-status-base-dir))
+ (buffer-file-name))))
+ (list (svn-status-make-line-info ".")))))
+
+(defun svn-status-marked-file-names ()
+ (mapcar 'svn-status-line-info->filename (svn-status-marked-files)))
+
+(defun svn-status-some-files-marked-p ()
+ "Return non-nil iff a file has been marked by `svn-status-set-user-mark'.
+Unlike `svn-status-marked-files', this does not select the file under point
+if no files have been marked."
+ ;; `some' would be shorter but requires cl-seq at runtime.
+ ;; (Because it accepts both lists and vectors, it is difficult to inline.)
+ (loop for line-info in svn-status-info
+ thereis (svn-status-line-info->has-usermark line-info)))
+
+(defun svn-status-only-dirs-or-nothing-marked-p ()
+ "Return non-nil iff only dirs has been marked by `svn-status-set-user-mark'."
+ ;; `some' would be shorter but requires cl-seq at runtime.
+ ;; (Because it accepts both lists and vectors, it is difficult to inline.)
+ (loop for line-info in svn-status-info
+ thereis (and (not (svn-status-line-info->directory-p line-info))
+ (svn-status-line-info->has-usermark line-info))))
+
+(defun svn-status-ui-information-hash-table ()
+ (let ((st-info svn-status-info)
+ (svn-status-ui-information (make-hash-table :test 'equal)))
+ (while st-info
+ (svn-puthash (svn-status-line-info->filename (car st-info))
+ (svn-status-line-info->ui-status (car st-info))
+ svn-status-ui-information)
+ (setq st-info (cdr st-info)))
+ svn-status-ui-information))
+
+
+(defun svn-status-create-arg-file (file-name prefix file-info-list postfix)
+ (with-temp-file file-name
+ (insert prefix)
+ (let ((st-info file-info-list))
+ (while st-info
+ (insert (svn-status-line-info->filename (car st-info)))
+ (insert "\n")
+ (setq st-info (cdr st-info)))
+
+ (insert postfix))))
+
+(defun svn-status-show-process-buffer-internal (&optional scroll-to-top)
+ (let ((cur-buff (current-buffer)))
+ (unless svn-status-preserve-window-configuration
+ (when (string= (buffer-name) svn-status-buffer-name)
+ (delete-other-windows)))
+ (pop-to-buffer svn-process-buffer-name)
+ (svn-process-mode)
+ (when scroll-to-top
+ (goto-char (point-min)))
+ (pop-to-buffer cur-buff)))
+
+(defun svn-status-show-process-output (cmd &optional scroll-to-top)
+ "Display the result of a svn command.
+Consider svn-status-window-alist to choose the buffer name."
+ (let ((window-mode (cadr (assoc cmd svn-status-window-alist)))
+ (process-default-directory))
+ (cond ((eq window-mode nil) ;; use *svn-process* buffer
+ (setq svn-status-last-output-buffer-name svn-process-buffer-name))
+ ((eq window-mode t) ;; use *svn-info* buffer
+ (setq svn-status-last-output-buffer-name "*svn-info*"))
+ ((eq window-mode 'invisible) ;; don't display the buffer
+ (setq svn-status-last-output-buffer-name nil))
+ (t
+ (setq svn-status-last-output-buffer-name window-mode)))
+ (when svn-status-last-output-buffer-name
+ (if window-mode
+ (progn
+ (unless svn-status-preserve-window-configuration
+ (when (string= (buffer-name) svn-status-buffer-name)
+ (delete-other-windows)))
+ (pop-to-buffer svn-process-buffer-name)
+ (setq process-default-directory default-directory)
+ (switch-to-buffer (get-buffer-create svn-status-last-output-buffer-name))
+ (setq default-directory process-default-directory)
+ (let ((buffer-read-only nil))
+ (delete-region (point-min) (point-max))
+ (insert-buffer-substring svn-process-buffer-name)
+ (when scroll-to-top
+ (goto-char (point-min))))
+ (when (eq window-mode t) ;; *svn-info* buffer
+ (svn-info-mode))
+ (other-window 1))
+ (svn-status-show-process-buffer-internal scroll-to-top)))))
+
+(defun svn-status-svn-log-switches (arg)
+ (cond ((eq arg 0) '())
+ ((or (eq arg -1) (eq arg '-)) '("-q"))
+ (arg '("-v"))
+ (t svn-status-default-log-arguments)))
+
+(defun svn-status-show-svn-log (arg)
+ "Run `svn log' on selected files.
+The output is put into the *svn-log* buffer
+The optional prefix argument ARG determines which switches are passed to `svn log':
+ no prefix --- use whatever is in the list `svn-status-default-log-arguments'
+ prefix argument of -1: --- use the -q switch (quiet)
+ prefix argument of 0 --- use no arguments
+ other prefix arguments: --- use the -v switch (verbose)
+
+See `svn-status-marked-files' for what counts as selected."
+ (interactive "P")
+ (let ((switches (svn-status-svn-log-switches arg))
+ (svn-status-get-line-information-for-file t))
+ ;; (message "svn-status-show-svn-log %S" arg)
+ (svn-status-create-arg-file svn-status-temp-arg-file "" (svn-status-marked-files) "")
+ (svn-run t t 'log "log" "--targets" svn-status-temp-arg-file switches)))
+
+(defun svn-status-version ()
+ "Show the version numbers for psvn.el and the svn command line client.
+The version number of the client is cached in `svn-client-version'."
+ (interactive)
+ (let ((window-conf (current-window-configuration))
+ (version-string))
+ (if (or (interactive-p) (not svn-status-cached-version-string))
+ (progn
+ (svn-run nil t 'version "--version")
+ (when (interactive-p)
+ (svn-status-show-process-output 'info t))
+ (with-current-buffer svn-status-last-output-buffer-name
+ (goto-char (point-min))
+ (setq svn-client-version
+ (when (re-search-forward "svn, version \\([0-9\.]+\\) " nil t)
+ (mapcar 'string-to-number (split-string (match-string 1) "\\."))))
+ (let ((buffer-read-only nil))
+ (goto-char (point-min))
+ (insert (format "psvn.el revision: %s\n\n" svn-psvn-revision)))
+ (setq version-string (buffer-substring-no-properties (point-min) (point-max))))
+ (setq svn-status-cached-version-string version-string))
+ (setq version-string svn-status-cached-version-string)
+ (unless (interactive-p)
+ (set-window-configuration window-conf)
+ version-string))))
+
+(defun svn-status-info ()
+ "Run `svn info' on all selected files.
+See `svn-status-marked-files' for what counts as selected."
+ (interactive)
+ (svn-status-create-arg-file svn-status-temp-arg-file "" (svn-status-marked-files) "")
+ (svn-run t t 'info "info" "--targets" svn-status-temp-arg-file))
+
+(defun svn-status-info-for-path (path)
+ "Run svn info on the given PATH.
+Return some interesting parts of the resulting output.
+At the moment a list containing the last changed author is returned."
+ (let ((svn-process-buffer-name "*svn-info-output*")
+ (last-changed-author))
+ (svn-run nil t 'info "info" path)
+ (with-current-buffer svn-process-buffer-name
+ (goto-char (point-min))
+ (when (search-forward "last changed author: " nil t)
+ (setq last-changed-author (buffer-substring-no-properties (point) (svn-point-at-eol)))))
+ (svn-status-message 7 "last-changed-author for '%s': %s" path last-changed-author)
+ (list last-changed-author)))
+
+(defun svn-status-blame (revision &optional file-name)
+ "Run `svn blame' on the current file.
+When called with a prefix argument, ask the user for the REVISION to use.
+When called from a file buffer, go to the current line in the resulting blame output."
+ (interactive "P")
+ (when current-prefix-arg
+ (setq revision (svn-status-read-revision-string "Blame for version: " "BASE")))
+ (unless revision (setq revision "BASE"))
+ (setq svn-status-blame-revision revision)
+ (setq svn-status-blame-file-name (if file-name
+ file-name
+ (svn-status-line-info->filename (svn-status-get-file-information))))
+ (svn-run t t 'blame "blame" svn-status-default-blame-arguments "-r" revision svn-status-blame-file-name))
+
+(defun svn-blame-blame-again (arg)
+ "Run svn blame again, using the revision before the change at point.
+When point is at revision 3472, run it with 3471."
+ (interactive "P")
+ (let ((rev (svn-blame-rev-at-point)))
+ (setq rev (number-to-string (- (string-to-number rev) 1)))
+ (when current-prefix-arg
+ (setq rev (svn-status-read-revision-string (format "Svn blame for rev#? ") rev)))
+ (svn-status-blame rev svn-status-blame-file-name)))
+
+(defun svn-status-show-svn-diff (arg)
+ "Run `svn diff' on the current file.
+If the current file is a directory, compare it recursively.
+If there is a newer revision in the repository, the diff is done against HEAD,
+otherwise compare the working copy with BASE.
+If ARG then prompt for revision to diff against (unless arg is '-)
+When called with a negative prefix argument, do a non recursive diff."
+ (interactive "P")
+ (let ((non-recursive (or (and (numberp arg) (< arg 0)) (eq arg '-)))
+ (revision (if (and (not (eq arg '-)) arg) :ask :auto)))
+ (svn-status-ensure-cursor-on-file)
+ (svn-status-show-svn-diff-internal (list (svn-status-get-line-information)) (not non-recursive)
+ revision)))
+
+(defun svn-file-show-svn-diff (arg)
+ "Run `svn diff' on the current file.
+If there is a newer revision in the repository, the diff is done against HEAD,
+otherwise compare the working copy with BASE.
+If ARG then prompt for revision to diff against."
+ (interactive "P")
+ (svn-status-show-svn-diff-internal (list (svn-status-make-line-info buffer-file-name)) nil
+ (if arg :ask :auto)))
+
+(defun svn-status-show-svn-diff-for-marked-files (arg)
+ "Run `svn diff' on all selected files.
+If some files have been marked, compare those non-recursively;
+this is because marking a directory with \\[svn-status-set-user-mark]
+normally marks all of its files as well.
+If no files have been marked, compare recursively the file at point.
+If ARG then prompt for revision to diff against, else compare working copy with BASE."
+ (interactive "P")
+ (svn-status-show-svn-diff-internal (svn-status-marked-files)
+ (not (svn-status-some-files-marked-p))
+ (if arg :ask "BASE")))
+
+(defun svn-status-diff-show-changeset (rev &optional user-confirmation rev-against)
+ "Show the changeset for a given log entry.
+When called with a prefix argument, ask the user for the revision."
+ (let* ((upper-rev (if rev-against rev-against rev))
+ (lower-rev (if rev-against rev (number-to-string (- (string-to-number upper-rev) 1))))
+ (rev-arg (concat lower-rev ":" upper-rev)))
+ (when user-confirmation
+ (setq rev-arg (read-string "Revision for changeset: " rev-arg)))
+ (svn-run nil t 'diff "diff" svn-status-default-diff-arguments (concat "-r" rev-arg))
+ (svn-status-activate-diff-mode)))
+
+(defun svn-status-show-svn-diff-internal (line-infos recursive revision)
+ ;; REVISION must be one of:
+ ;; - a string: whatever the -r option allows.
+ ;; - `:ask': asks the user to specify the revision, which then becomes
+ ;; saved in `minibuffer-history' rather than in `command-history'.
+ ;; - `:auto': use "HEAD" if an update is known to exist, "BASE" otherwise.
+ ;; In the future, `nil' might mean omit the -r option entirely;
+ ;; but that currently seems to imply "BASE", so we just use that.
+ (when (eq revision :ask)
+ (setq revision (svn-status-read-revision-string
+ "Diff with files for version: " "PREV")))
+
+ (setq svn-status-last-diff-options (list line-infos recursive revision))
+
+ (let ((clear-buf t)
+ (beginning nil))
+ (dolist (line-info line-infos)
+ (svn-run nil clear-buf 'diff "diff" svn-status-default-diff-arguments
+ "-r" (if (eq revision :auto)
+ (if (svn-status-line-info->update-available line-info)
+ "HEAD" "BASE")
+ revision)
+ (unless recursive "--non-recursive")
+ (svn-status-line-info->filename line-info))
+ (setq clear-buf nil)
+
+ ;; "svn diff --non-recursive" skips only subdirectories, not files.
+ ;; But a non-recursive diff via psvn should skip files too, because
+ ;; the user would have marked them if he wanted them to be compared.
+ ;; So we'll look for the "Index: foo" line that marks the first file
+ ;; in the diff output, and delete it and everything that follows.
+ ;; This is made more complicated by the fact that `svn-status-activate-diff-mode'
+ ;; expects the output to be left in the *svn-process* buffer.
+ (unless recursive
+ ;; Check `directory-p' relative to the `default-directory' of the
+ ;; "*svn-status*" buffer, not that of the svn-process-buffer-name buffer.
+ (let ((directory-p (svn-status-line-info->directory-p line-info)))
+ (with-current-buffer svn-process-buffer-name
+ (when directory-p
+ (goto-char (or beginning (point-min)))
+ (when (re-search-forward "^Index: " nil t)
+ (delete-region (match-beginning 0) (point-max))))
+ (goto-char (setq beginning (point-max))))))))
+ (svn-status-activate-diff-mode))
+
+(defun svn-status-diff-save-current-defun-as-kill ()
+ "Copy the function name for the change at point to the kill-ring.
+That function uses `add-log-current-defun'"
+ (interactive)
+ (let ((func-name (add-log-current-defun)))
+ (if func-name
+ (progn
+ (kill-new func-name)
+ (message "Copied %S" func-name))
+ (message "No current defun detected."))))
+
+(defun svn-status-diff-pop-to-commit-buffer ()
+ "Temporary switch to the `svn-status-buffer-name' buffer and start a commit from there."
+ (interactive)
+ (let ((window-conf (current-window-configuration)))
+ (svn-status-switch-to-status-buffer)
+ (svn-status-commit)
+ (set-window-configuration window-conf)
+ (setq svn-status-pre-commit-window-configuration window-conf)
+ (pop-to-buffer svn-log-edit-buffer-name)))
+
+(defun svn-status-activate-diff-mode ()
+ "Show the `svn-process-buffer-name' buffer, using the diff-mode."
+ (svn-status-show-process-output 'diff t)
+ (let ((working-directory default-directory))
+ (save-excursion
+ (set-buffer svn-status-last-output-buffer-name)
+ (setq default-directory working-directory)
+ (svn-status-diff-mode)
+ (setq buffer-read-only t))))
+
+(define-derived-mode svn-status-diff-mode fundamental-mode "svn-diff"
+ "Major mode to display svn diffs. Derives from `diff-mode'.
+
+Commands:
+\\{svn-status-diff-mode-map}
+"
+ (let ((diff-mode-shared-map (copy-keymap svn-status-diff-mode-map))
+ major-mode mode-name)
+ (diff-mode)
+ (set (make-local-variable 'revert-buffer-function) 'svn-status-diff-update)))
+
+(defun svn-status-diff-update (arg noconfirm)
+ "Rerun the last svn diff command and update the *svn-diff* buffer."
+ (interactive)
+ (svn-status-save-some-buffers)
+ (save-window-excursion
+ (apply 'svn-status-show-svn-diff-internal svn-status-last-diff-options)))
+
+(defun svn-status-show-process-buffer ()
+ "Show the content of the `svn-process-buffer-name' buffer"
+ (interactive)
+ (svn-status-show-process-output nil))
+
+(defun svn-status-pop-to-partner-buffer ()
+ "Pop to the `svn-status-partner-buffer' if that variable is set."
+ (interactive)
+ (when svn-status-partner-buffer
+ (let ((cur-buf (current-buffer)))
+ (pop-to-buffer svn-status-partner-buffer)
+ (setq svn-status-partner-buffer cur-buf))))
+
+(defun svn-status-pop-to-new-partner-buffer (buffer)
+ "Call `pop-to-buffer' and register the current buffer as partner buffer for BUFFER."
+ (let ((cur-buf (current-buffer)))
+ (pop-to-buffer buffer)
+ (setq svn-status-partner-buffer cur-buf)))
+
+(defun svn-status-add-file-recursively (arg)
+ "Run `svn add' on all selected files.
+When a directory is added, add files recursively.
+See `svn-status-marked-files' for what counts as selected.
+When this function is called with a prefix argument, use the actual file instead."
+ (interactive "P")
+ (message "adding: %S" (svn-status-get-file-list-names (not arg)))
+ (svn-status-create-arg-file svn-status-temp-arg-file "" (svn-status-get-file-list (not arg)) "")
+ (svn-run t t 'add "add" "--targets" svn-status-temp-arg-file))
+
+(defun svn-status-add-file (arg)
+ "Run `svn add' on all selected files.
+When a directory is added, don't add the files of the directory
+ (svn add --non-recursive <file-list> is called).
+See `svn-status-marked-files' for what counts as selected.
+When this function is called with a prefix argument, use the actual file instead."
+ (interactive "P")
+ (message "adding: %S" (svn-status-get-file-list-names (not arg)))
+ (svn-status-create-arg-file svn-status-temp-arg-file "" (svn-status-get-file-list (not arg)) "")
+ (svn-run t t 'add "add" "--non-recursive" "--targets" svn-status-temp-arg-file))
+
+(defun svn-status-lock (arg)
+ "Run `svn lock' on all selected files.
+See `svn-status-marked-files' for what counts as selected."
+ (interactive "P")
+ (message "locking: %S" (svn-status-get-file-list-names t))
+ (svn-status-create-arg-file svn-status-temp-arg-file "" (svn-status-get-file-list t) "")
+ (svn-run t t 'lock "lock" "--targets" svn-status-temp-arg-file))
+
+(defun svn-status-unlock (arg)
+ "Run `svn unlock' on all selected files.
+See `svn-status-marked-files' for what counts as selected."
+ (interactive "P")
+ (message "unlocking: %S" (svn-status-get-file-list-names t))
+ (svn-status-create-arg-file svn-status-temp-arg-file "" (svn-status-get-file-list t) "")
+ (svn-run t t 'unlock "unlock" "--targets" svn-status-temp-arg-file))
+
+(defun svn-status-make-directory (dir)
+ "Run `svn mkdir DIR'."
+ ;; TODO: Allow entering a URI interactively.
+ ;; Currently, `read-file-name' corrupts it.
+ (interactive (list (read-file-name "Make directory: "
+ (svn-status-directory-containing-point t))))
+ (unless (string-match "^[^:/]+://" dir) ; Is it a URI?
+ (setq dir (file-relative-name dir)))
+ (svn-run t t 'mkdir "mkdir" "--" dir))
+
+(defun svn-status-mv ()
+ "Prompt for a destination, and `svn mv' selected files there.
+See `svn-status-marked-files' for what counts as `selected'.
+
+If one file was selected then the destination DEST should be a
+filename to rename the selected file to, or a directory to move the
+file into; if multiple files were selected then DEST should be a
+directory to move the selected files into.
+
+The default DEST is the directory containing point.
+
+BUG: If we've marked some directory containging a file as well as the
+file itself, then we should just mv the directory, but this implementation
+doesn't check for that.
+SOLUTION: for each dir, umark all its contents (but not the dir
+itself) before running mv."
+ (interactive)
+ (svn-status-mv-cp "mv" "Rename" "Move" "mv"))
+
+(defun svn-status-cp ()
+ "See `svn-status-mv'"
+ (interactive)
+ (svn-status-mv-cp "cp" "Copy" "Copy" "cp"))
+
+(defun svn-status-mv-cp (command singleprompt manyprompt fallback)
+ "Run svn COMMAND on marked files, prompting for destination
+
+This function acts on `svn-status-marked-files': at the prompt the
+user can enter a new file name, or an existing directory: this is used as the argument for svn COMMAND.
+ COMMAND --- string saying what to do: \"mv\" or \"cp\"
+ SINGLEPROMPT --- string at start of prompt when one file marked
+ MANYPROMPT --- string at start of prompt when multiple files marked
+ FALLBACK --- If any marked file is unversioned, use this instead of 'svn COMMAND'"
+ (let* ((marked-files (svn-status-marked-files))
+ (num-of-files (length marked-files))
+ dest)
+ (if (= 1 num-of-files)
+ ;; one file to act on: new name, or directory to hold results
+ (setq dest (read-file-name
+ (format "%s %s to: " singleprompt
+ (svn-status-line-info->filename (car marked-files)))
+ (svn-status-directory-containing-point t)
+ (svn-status-line-info->full-path (car marked-files))))
+ ;;TODO: (when file-exists-p but-no-dir-p dest (error "%s already exists" dest))
+ ;;multiple files selected, so prompt for existing directory to mv them into.
+ (setq dest (svn-read-directory-name
+ (format "%s %d files to directory: " manyprompt num-of-files)
+ (svn-status-directory-containing-point t) nil t))
+ (unless (file-directory-p dest)
+ (error "%s is not a directory" dest)))
+ (when (string= dest "")
+ (error "No destination entered"))
+ (unless (string-match "^[^:/]+://" dest) ; Is it a URI?
+ (setq dest (file-relative-name dest)))
+
+ ;;do the move: svn mv only lets us move things once at a time, so
+ ;;we need to run svn mv once for each file (hence second arg to
+ ;;svn-run is nil.)
+
+ ;;TODO: before doing any moving, For every marked directory,
+ ;;ensure none of its contents are also marked, since we dont want
+ ;;to move both file *and* its parent...
+ ;; what about elided files? what if user marks a dir+contents, then presses `_' ?
+;; ;one solution:
+;; (dolist (original marked-files)
+;; (when (svn-status-line-info->directory-p original)
+;; ;; run svn-status-goto-file-name to move point to line of file
+;; ;; run svn-status-unset-user-mark to unmark dir+all contents
+;; ;; run svn-status-set-user-mark to remark dir
+;; ;; maybe check for local mods here, and unmark if user does't say --force?
+;; ))
+ (dolist (original marked-files)
+ (let ((original-name (svn-status-line-info->filename original))
+ (original-filemarks (svn-status-line-info->filemark original))
+ (original-propmarks (svn-status-line-info->propmark original))
+ (moved nil))
+ (cond
+ ((or (eq original-filemarks ?M) ;local mods: maybe do `svn mv --force'
+ (eq original-propmarks ?M)) ;local prop mods: maybe do `svn mv --force'
+ (if (yes-or-no-p
+ (format "%s has local modifications; use `--force' to really move it? " original-name))
+ (progn
+ (svn-status-run-mv-cp command original-name dest t)
+ (setq moved t))
+ (message "Not acting on %s" original-name)))
+ ((eq original-filemarks ??) ;original is unversioned: use fallback
+ (if (yes-or-no-p (format "%s is unversioned. Use `%s -i -- %s %s'? "
+ original-name fallback original-name dest))
+ ;; TODO: consider svn-call-process-function here also...
+ (progn (call-process fallback nil (get-buffer-create svn-process-buffer-name) nil
+ "-i" "--" original-name dest)
+ (setq moved t))
+ ;;new files created by fallback are not in *svn-status* now,
+ ;;TODO: so call (svn-status-update) here?
+ (message "Not acting on %s" original-name)))
+
+ ((eq original-filemarks ?A) ;;`A' (`svn add'ed, but not committed)
+ (message "Not acting on %s (commit it first)" original-name))
+
+ ((eq original-filemarks ? ) ;original is unmodified: can proceed
+ (svn-status-run-mv-cp command original-name dest)
+ (setq moved t))
+
+ ;;file has some other mark (eg conflicted)
+ (t
+ (if (yes-or-no-p
+ (format "The status of %s looks scary. Risk moving it anyway? "
+ original-name))
+ (progn
+ (svn-status-run-mv-cp command original-name dest)
+ (setq moved t))
+ (message "Not acting on %s" original-name))))
+ (when moved
+ (message "psvn: did '%s' from %s to %s" command original-name dest)
+ ;; Silently rename the visited file of any buffer visiting this file.
+ (when (get-file-buffer original-name)
+ (with-current-buffer (get-file-buffer original-name)
+ (set-visited-file-name dest nil t))))))
+ (svn-status-update)))
+
+(defun svn-status-run-mv-cp (command original destination &optional force)
+ "Actually run svn mv or svn cp.
+This is just to prevent duplication in `svn-status-prompt-and-act-on-files'"
+ (if force
+ (svn-run nil t (intern command) command "--force" "--" original destination)
+ (svn-run nil t (intern command) command "--" original destination))
+;;;TODO: use something like the following instead of calling svn-status-update
+;;; at the end of svn-status-mv-cp.
+;; (let ((output (svn-status-parse-ar-output))
+;; newfile
+;; buffer-read-only) ; otherwise insert-line-in-status-buffer fails
+;; (dolist (new-file output)
+;; (when (eq (cadr new-file) 'added-wc)
+;; ;; files with 'wc-added action do not exist in *svn-status*
+;; ;; buffer yet, so give each of them their own line-info
+;; ;; TODO: need to insert the new line-info in a sensible place, ie in the correct directory! [svn-status-filename-to-buffer-position-cache might help?]
+
+;; (svn-insert-line-in-status-buffer
+;; (svn-status-make-line-info (car new-file)))))
+;; (svn-status-update-with-command-list output))
+ )
+
+(defun svn-status-revert ()
+ "Run `svn revert' on all selected files.
+See `svn-status-marked-files' for what counts as selected."
+ (interactive)
+ (let* ((marked-files (svn-status-marked-files))
+ (num-of-files (length marked-files)))
+ (when (yes-or-no-p
+ (if (= 1 num-of-files)
+ (format "Revert %s? " (svn-status-line-info->filename (car marked-files)))
+ (format "Revert %d files? " num-of-files)))
+ (message "reverting: %S" (svn-status-marked-file-names))
+ (svn-status-create-arg-file svn-status-temp-arg-file "" (svn-status-marked-files) "")
+ (svn-run t t 'revert "revert" "--targets" svn-status-temp-arg-file))))
+
+(defun svn-file-revert ()
+ "Run `svn revert' on the current file."
+ (interactive)
+ (when (y-or-n-p (format "Revert %s? " buffer-file-name))
+ (svn-run t t 'revert "revert" buffer-file-name)))
+
+(defun svn-status-rm (force)
+ "Run `svn rm' on all selected files.
+See `svn-status-marked-files' for what counts as selected.
+When called with a prefix argument add the command line switch --force.
+
+Forcing the deletion can also be used to delete files not under svn control."
+ (interactive "P")
+ (let* ((marked-files (svn-status-marked-files))
+ (num-of-files (length marked-files)))
+ (when (yes-or-no-p
+ (if (= 1 num-of-files)
+ (format "%sRemove %s? " (if force "Force " "") (svn-status-line-info->filename (car marked-files)))
+ (format "%sRemove %d files? " (if force "Force " "") num-of-files)))
+ (message "removing: %S" (svn-status-marked-file-names))
+ (svn-status-create-arg-file svn-status-temp-arg-file "" (svn-status-marked-files) "")
+ (if force
+ (save-excursion
+ (svn-run t t 'rm "rm" "--force" "--targets" svn-status-temp-arg-file)
+ (dolist (to-delete (svn-status-marked-files))
+ (when (eq (svn-status-line-info->filemark to-delete) ??)
+ (svn-status-goto-file-name (svn-status-line-info->filename to-delete))
+ (let ((buffer-read-only nil))
+ (delete-region (svn-point-at-bol) (+ 1 (svn-point-at-eol)))
+ (delete to-delete svn-status-info)))))
+ (svn-run t t 'rm "rm" "--targets" svn-status-temp-arg-file)))))
+
+(defun svn-status-update-cmd (arg)
+ "Run svn update.
+When called with a prefix argument, ask the user for the revision to update to.
+When called with a negative prefix argument, only update the selected files."
+ (interactive "P")
+ (let* ((selective-update (or (and (numberp arg) (< arg 0)) (eq arg '-)))
+ (rev (when arg (svn-status-read-revision-string
+ (if selective-update
+ (format "Selected entries: Run svn update -r ")
+ (format "Directory: %s: Run svn update -r " default-directory))
+ (if selective-update "HEAD" nil)))))
+ (if selective-update
+ (progn
+ (message "Running svn-update for %s" (svn-status-marked-file-names))
+ (svn-run t t 'update "update"
+ (when rev (list "-r" rev))
+ (list "--non-interactive")
+ (svn-status-marked-file-names)))
+ (message "Running svn-update for %s" default-directory)
+ (svn-run t t 'update "update"
+ (when rev (list "-r" rev))
+ (list "--non-interactive") (expand-file-name default-directory)))))
+
+(defun svn-status-commit ()
+ "Commit selected files.
+If some files have been marked, commit those non-recursively;
+this is because marking a directory with \\[svn-status-set-user-mark]
+normally marks all of its files as well.
+If no files have been marked, commit recursively the file at point."
+ (interactive)
+ (svn-status-save-some-buffers)
+ (let* ((selected-files (svn-status-marked-files)))
+ (setq svn-status-files-to-commit selected-files
+ svn-status-recursive-commit (not (svn-status-only-dirs-or-nothing-marked-p)))
+ (svn-log-edit-show-files-to-commit)
+ (svn-status-pop-to-commit-buffer)
+ (when svn-log-edit-insert-files-to-commit
+ (svn-log-edit-insert-files-to-commit))
+ (when svn-log-edit-show-diff-for-commit
+ (svn-log-edit-svn-diff nil))))
+
+(defun svn-status-pop-to-commit-buffer ()
+ "Pop to the svn commit buffer.
+If a saved log message exists in `svn-log-edit-file-name' insert it in the buffer."
+ (interactive)
+ (setq svn-status-pre-commit-window-configuration (current-window-configuration))
+ (let* ((use-existing-buffer (get-buffer svn-log-edit-buffer-name))
+ (commit-buffer (get-buffer-create svn-log-edit-buffer-name))
+ (dir default-directory)
+ (log-edit-file-name))
+ (pop-to-buffer commit-buffer)
+ (setq default-directory dir)
+ (setq log-edit-file-name (svn-log-edit-file-name))
+ (unless use-existing-buffer
+ (when (and log-edit-file-name (file-readable-p log-edit-file-name))
+ (insert-file-contents log-edit-file-name)))
+ (svn-log-edit-mode)))
+
+(defun svn-status-switch-to-status-buffer ()
+ "Switch to the `svn-status-buffer-name' buffer."
+ (interactive)
+ (switch-to-buffer svn-status-buffer-name))
+
+(defun svn-status-pop-to-status-buffer ()
+ "Pop to the `svn-status-buffer-name' buffer."
+ (interactive)
+ (pop-to-buffer svn-status-buffer-name))
+
+(defun svn-status-via-bookmark (bookmark)
+ "Allows a quick selection of a bookmark in `svn-bookmark-list'.
+Run `svn-status' on the selected bookmark."
+ (interactive
+ (list
+ (let ((completion-ignore-case t))
+ (funcall svn-status-completing-read-function "SVN status bookmark: " svn-bookmark-list))))
+ (unless bookmark
+ (error "No bookmark specified"))
+ (let ((directory (cdr (assoc bookmark svn-bookmark-list))))
+ (if (file-directory-p directory)
+ (svn-status directory)
+ (error "%s is not a directory" directory))))
+
+(defun svn-status-export ()
+ "Run `svn export' for the current working copy.
+Ask the user for the destination path.
+`svn-status-default-export-directory' is suggested as export directory."
+ (interactive)
+ (let* ((src default-directory)
+ (dir1-name (nth 1 (nreverse (split-string src "/"))))
+ (dest (read-file-name (format "Export %s to " src) (concat svn-status-default-export-directory dir1-name))))
+ (svn-run t t 'export "export" (expand-file-name src) (expand-file-name dest))
+ (message "svn-status-export %s %s" src dest)))
+
+(defun svn-status-cleanup (arg)
+ "Run `svn cleanup' on all selected files.
+See `svn-status-marked-files' for what counts as selected.
+When this function is called with a prefix argument, use the actual file instead."
+ (interactive "P")
+ (let ((file-names (svn-status-get-file-list-names (not arg))))
+ (if file-names
+ (progn
+ (message "svn-status-cleanup %S" file-names)
+ (svn-run t t 'cleanup (append (list "cleanup") file-names)))
+ (message "No valid file selected - No status cleanup possible"))))
+
+(defun svn-status-resolved ()
+ "Run `svn resolved' on all selected files.
+See `svn-status-marked-files' for what counts as selected."
+ (interactive)
+ (let* ((marked-files (svn-status-marked-files))
+ (num-of-files (length marked-files)))
+ (when (yes-or-no-p
+ (if (= 1 num-of-files)
+ (format "Resolve %s? " (svn-status-line-info->filename (car marked-files)))
+ (format "Resolve %d files? " num-of-files)))
+ (message "resolving: %S" (svn-status-marked-file-names))
+ (svn-status-create-arg-file svn-status-temp-arg-file "" (svn-status-marked-files) "")
+ (svn-run t t 'resolved "resolved" "--targets" svn-status-temp-arg-file))))
+
+
+(defun svn-status-svnversion ()
+ "Run svnversion on the directory that contains the file at point."
+ (interactive)
+ (svn-status-ensure-cursor-on-file)
+ (let ((simple-path (svn-status-line-info->filename (svn-status-get-line-information)))
+ (full-path (svn-status-line-info->full-path (svn-status-get-line-information)))
+ (version))
+ (unless (file-directory-p simple-path)
+ (setq simple-path (or (file-name-directory simple-path) "."))
+ (setq full-path (file-name-directory full-path)))
+ (setq version (shell-command-to-string (concat "svnversion -n " full-path)))
+ (message "svnversion for '%s': %s" simple-path version)
+ version))
+
+;; --------------------------------------------------------------------------------
+;; Update the `svn-status-buffer-name' buffer, when a file is saved
+;; --------------------------------------------------------------------------------
+
+(defvar svn-status-file-modified-after-save-flag ?m
+ "Flag shown whenever a file is modified and saved in Emacs.
+The flag is shown in the `svn-status-buffer-name' buffer.
+Recommended values are ?m or ?M.")
+(defun svn-status-after-save-hook ()
+ "Set a modified indication, when a file is saved from a svn working copy."
+ (let* ((svn-dir (car-safe svn-status-directory-history))
+ (svn-dir (when svn-dir (expand-file-name svn-dir)))
+ (file-dir (file-name-directory (buffer-file-name)))
+ (svn-dir-len (length (or svn-dir "")))
+ (file-dir-len (length file-dir))
+ (file-name))
+ (when (and (get-buffer svn-status-buffer-name)
+ svn-dir
+ (>= file-dir-len svn-dir-len)
+ (string= (substring file-dir 0 svn-dir-len) svn-dir))
+ (setq file-name (substring (buffer-file-name) svn-dir-len))
+ ;;(message "In svn-status directory %S" file-name)
+ (let ((st-info svn-status-info)
+ (i-fname))
+ (while st-info
+ (setq i-fname (svn-status-line-info->filename (car st-info)))
+ ;;(message "i-fname=%S" i-fname)
+ (when (and (string= file-name i-fname)
+ (not (eq (svn-status-line-info->filemark (car st-info)) ??)))
+ (svn-status-line-info->set-filemark (car st-info)
+ svn-status-file-modified-after-save-flag)
+ (save-window-excursion
+ (set-buffer svn-status-buffer-name)
+ (save-excursion
+ (let ((buffer-read-only nil)
+ (pos (svn-status-get-file-name-buffer-position i-fname)))
+ (if pos
+ (progn
+ (goto-char pos)
+ (delete-region (svn-point-at-bol) (svn-point-at-eol))
+ (svn-insert-line-in-status-buffer (car st-info))
+ (delete-char 1))
+ (svn-status-message 3 "psvn: file %s not found, updating %s buffer content..."
+ i-fname svn-status-buffer-name)
+ (svn-status-update-buffer))))))
+ (setq st-info (cdr st-info))))))
+ nil)
+
+(add-hook 'after-save-hook 'svn-status-after-save-hook)
+
+;; --------------------------------------------------------------------------------
+;; vc-svn integration
+;; --------------------------------------------------------------------------------
+(defvar svn-status-state-mark-modeline t) ; modeline mark display or not
+(defvar svn-status-state-mark-tooltip nil) ; modeline tooltip display
+
+(defun svn-status-state-mark-modeline-dot (color)
+ (propertize " "
+ 'help-echo 'svn-status-state-mark-tooltip
+ 'display
+ `(image :type xpm
+ :data ,(format "/* XPM */
+static char * data[] = {
+\"18 13 3 1\",
+\" c None\",
+\"+ c #000000\",
+\". c %s\",
+\" \",
+\" +++++ \",
+\" +.....+ \",
+\" +.......+ \",
+\" +.........+ \",
+\" +.........+ \",
+\" +.........+ \",
+\" +.........+ \",
+\" +.........+ \",
+\" +.......+ \",
+\" +.....+ \",
+\" +++++ \",
+\" \"};"
+ color)
+ :ascent center)))
+
+(defun svn-status-install-state-mark-modeline (color)
+ (push `(svn-status-state-mark-modeline
+ ,(svn-status-state-mark-modeline-dot color))
+ mode-line-format)
+ (force-mode-line-update t))
+
+(defun svn-status-uninstall-state-mark-modeline ()
+ (setq mode-line-format
+ (remove-if #'(lambda (mode) (eq (car-safe mode)
+ 'svn-status-state-mark-modeline))
+ mode-line-format))
+ (force-mode-line-update t))
+
+(defun svn-status-update-state-mark-tooltip (tooltip)
+ (setq svn-status-state-mark-tooltip tooltip))
+
+(defun svn-status-update-state-mark (color)
+ (svn-status-uninstall-state-mark-modeline)
+ (svn-status-install-state-mark-modeline color))
+
+(defsubst svn-status-in-vc-mode? ()
+ "Is vc-svn active?"
+ (and vc-mode (string-match "^ SVN" (svn-substring-no-properties vc-mode))))
+
+(when svn-status-fancy-file-state-in-modeline
+ (defadvice vc-find-file-hook (after svn-status-vc-svn-find-file-hook activate)
+ "vc-find-file-hook advice for synchronizing psvn with vc-svn interface"
+ (when (svn-status-in-vc-mode?) (svn-status-update-modeline)))
+
+ (defadvice vc-after-save (after svn-status-vc-svn-after-save activate)
+ "vc-after-save advice for synchronizing psvn when saving buffer"
+ (when (svn-status-in-vc-mode?) (svn-status-update-modeline)))
+
+ (defadvice ediff-refresh-mode-lines
+ (around svn-modeline-ediff-fixup activate compile)
+ "Fixup svn file status in the modeline when using ediff"
+ (ediff-with-current-buffer ediff-buffer-A
+ (svn-status-uninstall-state-mark-modeline))
+ (ediff-with-current-buffer ediff-buffer-B
+ (svn-status-uninstall-state-mark-modeline))
+ ad-do-it
+ (ediff-with-current-buffer ediff-buffer-A
+ (svn-status-update-modeline))
+ (ediff-with-current-buffer ediff-buffer-B
+ (svn-status-update-modeline))))
+
+(defun svn-status-update-modeline ()
+ "Update modeline state dot mark properly"
+ (when (and buffer-file-name (svn-status-in-vc-mode?))
+ (svn-status-update-state-mark
+ (svn-status-interprete-state-mode-color
+ (vc-svn-state buffer-file-name)))))
+
+(defsubst svn-status-interprete-state-mode-color (stat)
+ "Interpret vc-svn-state symbol to mode line color"
+ (case stat
+ ('edited "tomato" )
+ ('up-to-date "GreenYellow" )
+ ;; what is missing here??
+ ;; ('unknown "gray" )
+ ;; ('added "blue" )
+ ;; ('deleted "red" )
+ ;; ('unmerged "purple" )
+ (t "red")))
+
+;; --------------------------------------------------------------------------------
+;; Getting older revisions
+;; --------------------------------------------------------------------------------
+
+(defun svn-status-get-specific-revision (arg)
+ "Retrieve older revisions.
+The older revisions are stored in backup files named F.~REVISION~.
+
+When the function is called without a prefix argument: get all marked files.
+With a prefix argument: get only the actual file."
+ (interactive "P")
+ (svn-status-get-specific-revision-internal
+ (svn-status-get-file-list (not arg)) :ask t))
+
+(defun svn-status-get-specific-revision-internal (line-infos revision handle-relative-svn-status-dir)
+ "Retrieve older revisions of files.
+LINE-INFOS is a list of line-info structures (see
+`svn-status-get-line-information').
+REVISION is one of:
+- a string: whatever the -r option allows.
+- `:ask': asks the user to specify the revision, which then becomes
+ saved in `minibuffer-history' rather than in `command-history'.
+- `:auto': Use \"HEAD\" if an update is known to exist, \"BASE\" otherwise.
+
+After the call, `svn-status-get-revision-file-info' will be an alist
+\((WORKING-FILE-NAME . RETRIEVED-REVISION-FILE-NAME) ...). These file
+names are relative to the directory where `svn-status' was run."
+ ;; In `svn-status-show-svn-diff-internal', there is a comment
+ ;; that REVISION `nil' might mean omitting the -r option entirely.
+ ;; That doesn't seem like a good idea with svn cat.
+
+ ;; (message "svn-status-get-specific-revision-internal: %S %S" line-infos revision)
+
+ (when (eq revision :ask)
+ (setq revision (svn-status-read-revision-string
+ "Get files for version: " "PREV")))
+
+ (let ((count (length line-infos)))
+ (if (= count 1)
+ (let ((line-info (car line-infos)))
+ (message "Getting revision %s of %s"
+ (if (eq revision :auto)
+ (if (svn-status-line-info->update-available line-info)
+ "HEAD" "BASE")
+ revision)
+ (svn-status-line-info->filename line-info)))
+ ;; We could compute "Getting HEAD of 8 files and BASE of 11 files"
+ ;; but that'd be more bloat than it's worth.
+ (message "Getting revision %s of %d files"
+ (if (eq revision :auto) "HEAD or BASE" revision)
+ count)))
+
+ (let ((svn-status-get-specific-revision-file-info '()))
+ (dolist (line-info line-infos)
+ (let* ((revision (if (eq revision :auto)
+ (if (svn-status-line-info->update-available line-info)
+ "HEAD" "BASE")
+ revision)) ;must be a string by this point
+ (file-name (svn-status-line-info->filename line-info))
+ ;; If REVISION is e.g. "HEAD", should we find out the actual
+ ;; revision number and save "foo.~123~" rather than "foo.~HEAD~"?
+ ;; OTOH, `auto-mode-alist' already ignores ".~HEAD~" suffixes,
+ ;; and if users often want to know the revision numbers of such
+ ;; files, they can use svn:keywords.
+ (file-name-with-revision (concat (file-name-nondirectory file-name) ".~" revision "~"))
+ (default-directory (concat (svn-status-base-dir)
+ (if handle-relative-svn-status-dir
+ (file-relative-name default-directory (svn-status-base-dir))
+ "")
+ (file-name-directory file-name))))
+ ;; `add-to-list' would unnecessarily check for duplicates.
+ (push (cons file-name (concat (file-name-directory file-name) file-name-with-revision))
+ svn-status-get-specific-revision-file-info)
+ (svn-status-message 3 "svn-status-get-specific-revision-internal: file: %s, default-directory: %s"
+ file-name default-directory)
+ (svn-status-message 3 "svn-status-get-specific-revision-internal: file-name-with-revision: %s %S"
+ file-name-with-revision (file-exists-p file-name-with-revision))
+ (save-excursion
+ (if (or (not (file-exists-p file-name-with-revision)) ;; file does not exist
+ (not (string= (number-to-string (string-to-number revision)) revision))) ;; revision is not a number
+ (progn
+ (message "Getting revision %s of %s, target: %s" revision file-name
+ (expand-file-name(concat default-directory file-name-with-revision)))
+ (let ((content
+ (with-temp-buffer
+ (if (string= revision "BASE")
+ (insert-file-contents (concat (svn-wc-adm-dir-name)
+ "/text-base/"
+ (file-name-nondirectory file-name)
+ ".svn-base"))
+ (progn
+ (svn-run nil t 'cat "cat" "-r" revision
+ (concat default-directory (file-name-nondirectory file-name)))
+ ;;todo: error processing
+ ;;svn: Filesystem has no item
+ ;;svn: file not found: revision `15', path `/trunk/file.txt'
+ (insert-buffer-substring svn-process-buffer-name)))
+ (buffer-string))))
+ (find-file file-name-with-revision)
+ (setq buffer-read-only nil)
+ (erase-buffer) ;Widen, because we'll save the whole buffer.
+ (insert content)
+ (goto-char (point-min))
+ (let ((write-file-functions nil)
+ (require-final-newline nil))
+ (save-buffer))))
+ (find-file file-name-with-revision)))))
+ ;;(message "default-directory: %s revision-file-info: %S" default-directory svn-status-get-specific-revision-file-info)
+ (nreverse svn-status-get-specific-revision-file-info)))
+
+(defun svn-status-ediff-with-revision (arg)
+ "Run ediff on the current file with a different revision.
+If there is a newer revision in the repository, the diff is done against HEAD,
+otherwise compare the working copy with BASE.
+If ARG then prompt for revision to diff against."
+ (interactive "P")
+ (let* ((svn-status-get-specific-revision-file-info
+ (svn-status-get-specific-revision-internal
+ (list (svn-status-make-line-info
+ (file-relative-name
+ (svn-status-line-info->full-path (svn-status-get-line-information))
+ (svn-status-base-dir))
+ nil nil nil nil nil nil
+ (svn-status-line-info->update-available (svn-status-get-line-information))))
+ (if arg :ask :auto)
+ nil))
+ (ediff-after-quit-destination-buffer (current-buffer))
+ (default-directory (svn-status-base-dir))
+ (my-buffer (find-file-noselect (caar svn-status-get-specific-revision-file-info)))
+ (base-buff (find-file-noselect (cdar svn-status-get-specific-revision-file-info)))
+ (svn-transient-buffers (list my-buffer base-buff))
+ (startup-hook '(svn-ediff-startup-hook)))
+ (ediff-buffers base-buff my-buffer startup-hook)))
+
+(defun svn-ediff-startup-hook ()
+ ;; (message "svn-ediff-startup-hook: ediff-after-quit-hook-internal: %S" ediff-after-quit-hook-internal)
+ (add-hook 'ediff-after-quit-hook-internal
+ `(lambda ()
+ (svn-ediff-exit-hook
+ ',ediff-after-quit-destination-buffer ',svn-transient-buffers))
+ nil 'local))
+
+(defun svn-ediff-exit-hook (svn-buf tmp-bufs)
+ ;; (message "svn-ediff-exit-hook: svn-buf: %s, tmp-bufs: %s" svn-buf tmp-bufs)
+ ;; kill the temp buffers (and their associated windows)
+ (dolist (tb tmp-bufs)
+ (when (and tb (buffer-live-p tb) (not (buffer-modified-p tb)))
+ (let* ((win (get-buffer-window tb t))
+ (file-name (buffer-file-name tb))
+ (is-temp-file (numberp (string-match "~\\([0-9]+\\|BASE\\)~" file-name))))
+ ;; (message "svn-ediff-exit-hook - is-temp-file: %s, temp-buf:: %s - %s " is-temp-file (current-buffer) file-name)
+ (when (and win (> (count-windows) 1)
+ (delete-window win)))
+ (kill-buffer tb)
+ (when (and is-temp-file svn-status-ediff-delete-temporary-files)
+ (when (or (eq svn-status-ediff-delete-temporary-files t)
+ (y-or-n-p (format "Delete File '%s' ? " file-name)))
+ (delete-file file-name))))))
+ ;; switch back to the *svn* buffer
+ (when (and svn-buf (buffer-live-p svn-buf)
+ (not (get-buffer-window svn-buf t)))
+ (ignore-errors (switch-to-buffer svn-buf))))
+
+
+(defun svn-status-read-revision-string (prompt &optional default-value)
+ "Prompt the user for a svn revision number."
+ (interactive)
+ (read-string prompt default-value))
+
+(defun svn-file-show-svn-ediff (arg)
+ "Run ediff on the current file with a previous revision.
+If ARG then prompt for revision to diff against."
+ (interactive "P")
+ (let ((svn-status-get-line-information-for-file 'relative)
+ (default-directory (svn-status-base-dir)))
+ (svn-status-ediff-with-revision arg)))
+
+;; --------------------------------------------------------------------------------
+;; SVN process handling
+;; --------------------------------------------------------------------------------
+
+(defun svn-process-kill ()
+ "Kill the current running svn process."
+ (interactive)
+ (let ((process (get-process "svn")))
+ (if process
+ (delete-process process)
+ (message "No running svn process"))))
+
+(defun svn-process-send-string (string &optional send-passwd)
+ "Send a string to the running svn process.
+This is useful, if the running svn process asks the user a question.
+Note: use C-q C-j to send a line termination character."
+ (interactive "sSend string to svn process: ")
+ (save-excursion
+ (set-buffer svn-process-buffer-name)
+ (goto-char (point-max))
+ (let ((buffer-read-only nil))
+ (insert (if send-passwd (make-string (length string) ?.) string)))
+ (set-marker (process-mark (get-process "svn")) (point)))
+ (process-send-string "svn" string))
+
+(defun svn-process-send-string-and-newline (string &optional send-passwd)
+ "Send a string to the running svn process.
+Just call `svn-process-send-string' with STRING and an end of line termination.
+When called with a prefix argument, read the data from user as password."
+ (interactive (let* ((use-passwd current-prefix-arg)
+ (s (if use-passwd
+ (read-passwd "Send secret line to svn process: ")
+ (read-string "Send line to svn process: "))))
+ (list s use-passwd)))
+ (svn-process-send-string (concat string "\n") send-passwd))
+
+;; --------------------------------------------------------------------------------
+;; Search interface
+;; --------------------------------------------------------------------------------
+
+(defun svn-status-grep-files (regexp)
+ "Run grep on selected file(s).
+See `svn-status-marked-files' for what counts as selected."
+ (interactive "sGrep files for: ")
+ (unless grep-command
+ (grep-compute-defaults))
+ (grep (format "%s %s %s" grep-command (shell-quote-argument regexp)
+ (mapconcat 'identity (svn-status-marked-file-names) " "))))
+
+(defun svn-status-search-files (search-string)
+ "Search selected file(s) for a fixed SEARCH-STRING.
+See `svn-status-marked-files' for what counts as selected."
+ (interactive "sSearch files for: ")
+ (svn-status-grep-files (regexp-quote search-string)))
+
+;; --------------------------------------------------------------------------------
+;; Property List stuff
+;; --------------------------------------------------------------------------------
+
+(defun svn-status-property-list ()
+ (interactive)
+ (let ((file-names (svn-status-marked-file-names)))
+ (if file-names
+ (progn
+ (svn-run t t 'proplist (append (list "proplist" "-v") file-names)))
+ (message "No valid file selected - No property listing possible"))))
+
+(defun svn-status-proplist-start ()
+ (svn-status-ensure-cursor-on-file)
+ (svn-run t t 'proplist-parse "proplist" (svn-status-line-info->filename
+ (svn-status-get-line-information))))
+(defun svn-status-property-edit-one-entry (arg)
+ "Edit a property.
+When called with a prefix argument, it is possible to enter a new property."
+ (interactive "P")
+ (setq svn-status-property-edit-must-match-flag (not arg))
+ (svn-status-proplist-start))
+
+(defun svn-status-property-set ()
+ (interactive)
+ (setq svn-status-property-edit-must-match-flag nil)
+ (svn-status-proplist-start))
+
+(defun svn-status-property-delete ()
+ (interactive)
+ (setq svn-status-property-edit-must-match-flag t)
+ (svn-status-proplist-start))
+
+(defun svn-status-property-parse-property-names ()
+ ;(svn-status-show-process-buffer-internal t)
+ (message "svn-status-property-parse-property-names")
+ (let ((pl)
+ (prop-name)
+ (prop-value))
+ (save-excursion
+ (set-buffer svn-process-buffer-name)
+ (goto-char (point-min))
+ (forward-line 1)
+ (while (looking-at " \\(.+\\)")
+ (setq pl (append pl (list (match-string 1))))
+ (forward-line 1)))
+ ;(cond last-command: svn-status-property-set, svn-status-property-edit-one-entry
+ (cond ((eq last-command 'svn-status-property-edit-one-entry)
+ ;;(message "svn-status-property-edit-one-entry")
+ (setq prop-name
+ (completing-read "Set Property - Name: " (mapcar 'list pl)
+ nil svn-status-property-edit-must-match-flag))
+ (unless (string= prop-name "")
+ (save-excursion
+ (set-buffer svn-status-buffer-name)
+ (svn-status-property-edit (list (svn-status-get-line-information))
+ prop-name))))
+ ((eq last-command 'svn-status-property-set)
+ (message "svn-status-property-set")
+ (setq prop-name
+ (completing-read "Set Property - Name: " (mapcar 'list pl) nil nil))
+ (setq prop-value (read-from-minibuffer "Property value: "))
+ (unless (string= prop-name "")
+ (save-excursion
+ (set-buffer svn-status-buffer-name)
+ (message "Setting property %s := %s for %S" prop-name prop-value
+ (svn-status-marked-file-names))
+ (let ((file-names (svn-status-marked-file-names)))
+ (when file-names
+ (svn-run nil t 'propset
+ (append (list "propset" prop-name prop-value) file-names))
+ )
+ )
+ (message "propset finished.")
+ )))
+ ((eq last-command 'svn-status-property-delete)
+ (setq prop-name
+ (completing-read "Delete Property - Name: " (mapcar 'list pl) nil t))
+ (unless (string= prop-name "")
+ (save-excursion
+ (set-buffer svn-status-buffer-name)
+ (let ((file-names (svn-status-marked-file-names)))
+ (when file-names
+ (message "Going to delete prop %s for %s" prop-name file-names)
+ (svn-run t t 'propdel
+ (append (list "propdel" prop-name) file-names))))))))))
+
+(defun svn-status-property-edit (file-info-list prop-name &optional new-prop-value remove-values)
+ (let* ((commit-buffer (get-buffer-create "*svn-property-edit*"))
+ (dir default-directory)
+ ;; now only one file is implemented ...
+ (file-name (svn-status-line-info->filename (car file-info-list)))
+ (prop-value))
+ (message "Edit property %s for file %s" prop-name file-name)
+ (svn-run nil t 'propget-parse "propget" prop-name file-name)
+ (save-excursion
+ (set-buffer svn-process-buffer-name)
+ (setq prop-value (if (> (point-max) 1)
+ (buffer-substring (point-min) (- (point-max) 1))
+ "")))
+ (setq svn-status-propedit-property-name prop-name)
+ (setq svn-status-propedit-file-list file-info-list)
+ (setq svn-status-pre-propedit-window-configuration (current-window-configuration))
+ (pop-to-buffer commit-buffer)
+ ;; If the buffer has been narrowed, `svn-prop-edit-done' will use
+ ;; only the accessible part. So we need not erase the rest here.
+ (delete-region (point-min) (point-max))
+ (setq default-directory dir)
+ (insert prop-value)
+ (svn-status-remove-control-M)
+ (when new-prop-value
+ (when (listp new-prop-value)
+ (if remove-values
+ (message "Remove prop values %S " new-prop-value)
+ (message "Adding new prop values %S " new-prop-value))
+ (while new-prop-value
+ (goto-char (point-min))
+ (if (re-search-forward (concat "^" (regexp-quote (car new-prop-value)) "$") nil t)
+ (when remove-values
+ (kill-whole-line 1))
+ (unless remove-values
+ (goto-char (point-max))
+ (when (> (current-column) 0) (insert "\n"))
+ (insert (car new-prop-value))))
+ (setq new-prop-value (cdr new-prop-value)))))
+ (svn-prop-edit-mode)))
+
+(defun svn-status-property-set-property (file-info-list prop-name prop-value)
+ "Set a property on a given file list."
+ (save-excursion
+ (set-buffer (get-buffer-create "*svn-property-edit*"))
+ ;; If the buffer has been narrowed, `svn-prop-edit-do-it' will use
+ ;; only the accessible part. So we need not erase the rest here.
+ (delete-region (point-min) (point-max))
+ (insert prop-value))
+ (setq svn-status-propedit-file-list (svn-status-marked-files))
+ (setq svn-status-propedit-property-name prop-name)
+ (svn-prop-edit-do-it nil)
+ (svn-status-update))
+
+
+(defun svn-status-get-directory (line-info)
+ (let* ((file-name (svn-status-line-info->filename line-info))
+ (file-dir (file-name-directory file-name)))
+ ;;(message "file-dir: %S" file-dir)
+ (if file-dir
+ (substring file-dir 0 (- (length file-dir) 1))
+ ".")))
+
+(defun svn-status-get-file-list-per-directory (files)
+ ;;(message "%S" files)
+ (let ((dir-list nil)
+ (i files)
+ (j)
+ (dir))
+ (while i
+ (setq dir (svn-status-get-directory (car i)))
+ (setq j (assoc dir dir-list))
+ (if j
+ (progn
+ ;;(message "dir already present %S %s" j dir)
+ (setcdr j (append (cdr j) (list (car i)))))
+ (setq dir-list (append dir-list (list (list dir (car i))))))
+ (setq i (cdr i)))
+ ;;(message "svn-status-get-file-list-per-directory: %S" dir-list)
+ dir-list))
+
+(defun svn-status-property-ignore-file ()
+ (interactive)
+ (let ((d-list (svn-status-get-file-list-per-directory (svn-status-marked-files)))
+ (dir)
+ (f-info)
+ (ext-list))
+ (while d-list
+ (setq dir (caar d-list))
+ (setq f-info (cdar d-list))
+ (setq ext-list (mapcar '(lambda (i)
+ (svn-status-line-info->filename-nondirectory i)) f-info))
+ ;;(message "ignore in dir %s: %S" dir f-info)
+ (save-window-excursion
+ (when (y-or-n-p (format "Ignore %S for %s? " ext-list dir))
+ (svn-status-property-edit
+ (list (svn-status-find-info-for-file-name dir)) "svn:ignore" ext-list)
+ (svn-prop-edit-do-it nil))) ; synchronous
+ (setq d-list (cdr d-list)))
+ (svn-status-update)))
+
+(defun svn-status-property-ignore-file-extension ()
+ (interactive)
+ (let ((d-list (svn-status-get-file-list-per-directory (svn-status-marked-files)))
+ (dir)
+ (f-info)
+ (ext-list))
+ (while d-list
+ (setq dir (caar d-list))
+ (setq f-info (cdar d-list))
+ ;;(message "ignore in dir %s: %S" dir f-info)
+ (setq ext-list nil)
+ (while f-info
+ (add-to-list 'ext-list (concat "*."
+ (file-name-extension
+ (svn-status-line-info->filename (car f-info)))))
+ (setq f-info (cdr f-info)))
+ ;;(message "%S" ext-list)
+ (save-window-excursion
+ (when (y-or-n-p (format "Ignore %S for %s? " ext-list dir))
+ (svn-status-property-edit
+ (list (svn-status-find-info-for-file-name dir)) "svn:ignore"
+ ext-list)
+ (svn-prop-edit-do-it nil)))
+ (setq d-list (cdr d-list)))
+ (svn-status-update)))
+
+(defun svn-status-property-edit-svn-ignore ()
+ (interactive)
+ (let* ((line-info (svn-status-get-line-information))
+ (dir (if (svn-status-line-info->directory-p line-info)
+ (svn-status-line-info->filename line-info)
+ (svn-status-get-directory line-info))))
+ (svn-status-property-edit
+ (list (svn-status-find-info-for-file-name dir)) "svn:ignore")
+ (message "Edit svn:ignore on %s" dir)))
+
+
+(defun svn-status-property-set-keyword-list ()
+ "Edit the svn:keywords property on the marked files."
+ (interactive)
+ ;;(message "Set svn:keywords for %S" (svn-status-marked-file-names))
+ (svn-status-property-edit (svn-status-marked-files) "svn:keywords"))
+
+(defun svn-status-property-set-keyword-id (arg)
+ "Set/Remove Id from the svn:keywords property.
+Normally Id is added to the svn:keywords property.
+
+When called with the prefix arg -, remove Id from the svn:keywords property."
+ (interactive "P")
+ (svn-status-property-edit (svn-status-marked-files) "svn:keywords" '("Id") (eq arg '-))
+ (svn-prop-edit-do-it nil))
+
+(defun svn-status-property-set-keyword-date (arg)
+ "Set/Remove Date from the svn:keywords property.
+Normally Date is added to the svn:keywords property.
+
+When called with the prefix arg -, remove Date from the svn:keywords property."
+ (interactive "P")
+ (svn-status-property-edit (svn-status-marked-files) "svn:keywords" '("Date") (eq arg '-))
+ (svn-prop-edit-do-it nil))
+
+
+(defun svn-status-property-set-eol-style ()
+ "Edit the svn:eol-style property on the marked files."
+ (interactive)
+ (svn-status-property-set-property
+ (svn-status-marked-files) "svn:eol-style"
+ (completing-read "Set svn:eol-style for the marked files: "
+ (mapcar 'list '("native" "CRLF" "LF" "CR"))
+ nil t)))
+
+(defun svn-status-property-set-executable (&optional unset)
+ "Set the svn:executable property on the marked files.
+When called with a prefix argument: unset the svn:executable property."
+ (interactive "P")
+ (if unset
+ (progn
+ (svn-run nil t 'propdel (append (list "propdel" "svn:executable") (svn-status-marked-file-names)))
+ (message "Unset the svn:executable property for %s" (svn-status-marked-file-names))
+ (svn-status-update))
+ (svn-status-property-set-property (svn-status-marked-files) "svn:executable" "*")))
+
+(defun svn-status-property-set-mime-type ()
+ "Set the svn:mime-type property on the marked files."
+ (interactive)
+ (require 'mailcap nil t)
+ (let ((completion-ignore-case t)
+ (mime-types (when (fboundp 'mailcap-mime-types)
+ (mailcap-mime-types))))
+ (svn-status-property-set-property
+ (svn-status-marked-files) "svn:mime-type"
+ (funcall svn-status-completing-read-function "Set svn:mime-type for the marked files: "
+ (mapcar (lambda (x) (cons x x)) ; for Emacs 21
+ (sort mime-types 'string<))))))
+
+;; --------------------------------------------------------------------------------
+;; svn-prop-edit-mode:
+;; --------------------------------------------------------------------------------
+
+(defvar svn-prop-edit-mode-map () "Keymap used in `svn-prop-edit-mode' buffers.")
+(put 'svn-prop-edit-mode-map 'risky-local-variable t) ;for Emacs 20.7
+
+(when (not svn-prop-edit-mode-map)
+ (setq svn-prop-edit-mode-map (make-sparse-keymap))
+ (define-key svn-prop-edit-mode-map [(control ?c) (control ?c)] 'svn-prop-edit-done)
+ (define-key svn-prop-edit-mode-map [(control ?c) (control ?d)] 'svn-prop-edit-svn-diff)
+ (define-key svn-prop-edit-mode-map [(control ?c) (control ?s)] 'svn-prop-edit-svn-status)
+ (define-key svn-prop-edit-mode-map [(control ?c) (control ?l)] 'svn-prop-edit-svn-log)
+ (define-key svn-prop-edit-mode-map [(control ?c) (control ?q)] 'svn-prop-edit-abort))
+
+(easy-menu-define svn-prop-edit-mode-menu svn-prop-edit-mode-map
+"'svn-prop-edit-mode' menu"
+ '("SVN-PropEdit"
+ ["Commit" svn-prop-edit-done t]
+ ["Show Diff" svn-prop-edit-svn-diff t]
+ ["Show Status" svn-prop-edit-svn-status t]
+ ["Show Log" svn-prop-edit-svn-log t]
+ ["Abort" svn-prop-edit-abort t]))
+
+(defun svn-prop-edit-mode ()
+ "Major Mode to edit file properties of files under svn control.
+Commands:
+\\{svn-prop-edit-mode-map}"
+ (interactive)
+ (kill-all-local-variables)
+ (use-local-map svn-prop-edit-mode-map)
+ (easy-menu-add svn-prop-edit-mode-menu)
+ (setq major-mode 'svn-prop-edit-mode)
+ (setq mode-name "svn-prop-edit"))
+
+(defun svn-prop-edit-abort ()
+ (interactive)
+ (bury-buffer)
+ (set-window-configuration svn-status-pre-propedit-window-configuration))
+
+(defun svn-prop-edit-done ()
+ (interactive)
+ (svn-prop-edit-do-it t))
+
+(defun svn-prop-edit-do-it (async)
+ "Run svn propset `svn-status-propedit-property-name' with the content of the
+*svn-property-edit* buffer."
+ (message "svn propset %s on %s"
+ svn-status-propedit-property-name
+ (mapcar 'svn-status-line-info->filename svn-status-propedit-file-list))
+ (save-excursion
+ (set-buffer (get-buffer "*svn-property-edit*"))
+ (when (fboundp 'set-buffer-file-coding-system)
+ (set-buffer-file-coding-system svn-status-svn-file-coding-system nil))
+ (setq svn-status-temp-file-to-remove
+ (concat svn-status-temp-dir "svn-prop-edit.txt" svn-temp-suffix))
+ (write-region (point-min) (point-max) svn-status-temp-file-to-remove nil 1))
+ (when svn-status-propedit-file-list ; there are files to change properties
+ (svn-status-create-arg-file svn-status-temp-arg-file ""
+ svn-status-propedit-file-list "")
+ (setq svn-status-propedit-file-list nil)
+ (svn-run async t 'propset "propset"
+ svn-status-propedit-property-name
+ "--targets" svn-status-temp-arg-file
+ (when (eq svn-status-svn-file-coding-system 'utf-8)
+ '("--encoding" "UTF-8"))
+ "-F" (concat svn-status-temp-dir "svn-prop-edit.txt" svn-temp-suffix))
+ (unless async (svn-status-remove-temp-file-maybe)))
+ (when svn-status-pre-propedit-window-configuration
+ (set-window-configuration svn-status-pre-propedit-window-configuration)))
+
+(defun svn-prop-edit-svn-diff (arg)
+ (interactive "P")
+ (set-buffer svn-status-buffer-name)
+ ;; Because propedit is not recursive in our use, neither is this diff.
+ (svn-status-show-svn-diff-internal svn-status-propedit-file-list nil
+ (if arg :ask "BASE")))
+
+(defun svn-prop-edit-svn-log (arg)
+ (interactive "P")
+ (set-buffer svn-status-buffer-name)
+ (svn-status-show-svn-log arg))
+
+(defun svn-prop-edit-svn-status ()
+ (interactive)
+ (pop-to-buffer svn-status-buffer-name)
+ (other-window 1))
+
+;; --------------------------------------------------------------------------------
+;; svn-log-edit-mode:
+;; --------------------------------------------------------------------------------
+
+(defvar svn-log-edit-mode-map () "Keymap used in `svn-log-edit-mode' buffers.")
+(put 'svn-log-edit-mode-map 'risky-local-variable t) ;for Emacs 20.7
+
+(defvar svn-log-edit-mode-menu) ;really defined with `easy-menu-define' below.
+
+(defun svn-log-edit-common-setup ()
+ (set (make-local-variable 'paragraph-start) svn-log-edit-paragraph-start)
+ (set (make-local-variable 'paragraph-separate) svn-log-edit-paragraph-separate))
+
+(if svn-log-edit-use-log-edit-mode
+ (define-derived-mode svn-log-edit-mode log-edit-mode "svn-log-edit"
+ "Wrapper around `log-edit-mode' for psvn.el"
+ (easy-menu-add svn-log-edit-mode-menu)
+ (setq svn-log-edit-update-log-entry nil)
+ (set (make-local-variable 'log-edit-callback) 'svn-log-edit-done)
+ (set (make-local-variable 'log-edit-listfun) 'svn-log-edit-files-to-commit)
+ (set (make-local-variable 'log-edit-initial-files) (log-edit-files))
+ (svn-log-edit-common-setup)
+ (message "Press %s when you are done editing."
+ (substitute-command-keys "\\[log-edit-done]"))
+ )
+ (defun svn-log-edit-mode ()
+ "Major Mode to edit svn log messages.
+Commands:
+\\{svn-log-edit-mode-map}"
+ (interactive)
+ (kill-all-local-variables)
+ (use-local-map svn-log-edit-mode-map)
+ (easy-menu-add svn-log-edit-mode-menu)
+ (setq major-mode 'svn-log-edit-mode)
+ (setq mode-name "svn-log-edit")
+ (setq svn-log-edit-update-log-entry nil)
+ (svn-log-edit-common-setup)
+ (run-hooks 'svn-log-edit-mode-hook)))
+
+(when (not svn-log-edit-mode-map)
+ (setq svn-log-edit-mode-map (make-sparse-keymap))
+ (unless svn-log-edit-use-log-edit-mode
+ (define-key svn-log-edit-mode-map (kbd "C-c C-c") 'svn-log-edit-done))
+ (define-key svn-log-edit-mode-map (kbd "C-c C-d") 'svn-log-edit-svn-diff)
+ (define-key svn-log-edit-mode-map (kbd "C-c C-s") 'svn-log-edit-save-message)
+ (define-key svn-log-edit-mode-map (kbd "C-c C-i") 'svn-log-edit-svn-status)
+ (define-key svn-log-edit-mode-map (kbd "C-c C-l") 'svn-log-edit-svn-log)
+ (define-key svn-log-edit-mode-map (kbd "C-c C-?") 'svn-log-edit-show-files-to-commit)
+ (define-key svn-log-edit-mode-map (kbd "C-c C-z") 'svn-log-edit-erase-edit-buffer)
+ (define-key svn-log-edit-mode-map (kbd "C-c C-q") 'svn-log-edit-abort))
+
+(easy-menu-define svn-log-edit-mode-menu svn-log-edit-mode-map
+"'svn-log-edit-mode' menu"
+ '("SVN-Log"
+ ["Save to disk" svn-log-edit-save-message t]
+ ["Commit" svn-log-edit-done t]
+ ["Show Diff" svn-log-edit-svn-diff t]
+ ["Show Status" svn-log-edit-svn-status t]
+ ["Show Log" svn-log-edit-svn-log t]
+ ["Show files to commit" svn-log-edit-show-files-to-commit t]
+ ["Erase buffer" svn-log-edit-erase-edit-buffer]
+ ["Abort" svn-log-edit-abort t]))
+(put 'svn-log-edit-mode-menu 'risky-local-variable t)
+
+(defun svn-log-edit-abort ()
+ (interactive)
+ (bury-buffer)
+ (set-window-configuration svn-status-pre-commit-window-configuration))
+
+(defun svn-log-edit-done ()
+ "Finish editing the log message and run svn commit."
+ (interactive)
+ (svn-status-save-some-buffers)
+ (save-excursion
+ (set-buffer (get-buffer svn-log-edit-buffer-name))
+ (when svn-log-edit-insert-files-to-commit
+ (svn-log-edit-remove-comment-lines))
+ (when (fboundp 'set-buffer-file-coding-system)
+ (set-buffer-file-coding-system svn-status-svn-file-coding-system nil))
+ (when (or svn-log-edit-update-log-entry svn-status-files-to-commit)
+ (setq svn-status-temp-file-to-remove
+ (concat svn-status-temp-dir "svn-log-edit.txt" svn-temp-suffix))
+ (write-region (point-min) (point-max) svn-status-temp-file-to-remove nil 1))
+ (bury-buffer))
+ (if svn-log-edit-update-log-entry
+ (when (y-or-n-p "Update the log entry? ")
+ ;; svn propset svn:log --revprop -r11672 -F file
+ (svn-run nil t 'propset "propset" "svn:log" "--revprop"
+ (concat "-r" svn-log-edit-update-log-entry)
+ "-F" svn-status-temp-file-to-remove)
+ (save-excursion
+ (set-buffer svn-process-buffer-name)
+ (message "%s" (buffer-substring (point-min) (- (point-max) 1)))))
+ (when svn-status-files-to-commit ; there are files to commit
+ (setq svn-status-operated-on-dot
+ (and (= 1 (length svn-status-files-to-commit))
+ (string= "." (svn-status-line-info->filename (car svn-status-files-to-commit)))))
+ (svn-status-create-arg-file svn-status-temp-arg-file ""
+ svn-status-files-to-commit "")
+ (svn-run t t 'commit "commit"
+ (unless svn-status-recursive-commit "--non-recursive")
+ "--targets" svn-status-temp-arg-file
+ "-F" svn-status-temp-file-to-remove
+ (when (eq svn-status-svn-file-coding-system 'utf-8)
+ '("--encoding" "UTF-8"))
+ svn-status-default-commit-arguments))
+ (set-window-configuration svn-status-pre-commit-window-configuration)
+ (message "svn-log editing done")))
+
+(defun svn-log-edit-svn-diff (arg)
+ "Show the diff we are about to commit.
+If ARG then show diff between some other version of the selected files."
+ (interactive "P")
+ (set-buffer svn-status-buffer-name) ; TODO: is this necessary?
+ ;; This call is very much like `svn-status-show-svn-diff-for-marked-files'
+ ;; but uses commit-specific variables instead of the current marks.
+ (svn-status-show-svn-diff-internal svn-status-files-to-commit
+ svn-status-recursive-commit
+ (if arg :ask "BASE")))
+
+(defun svn-log-edit-svn-log (arg)
+ (interactive "P")
+ (set-buffer svn-status-buffer-name)
+ (svn-status-show-svn-log arg))
+
+(defun svn-log-edit-svn-status ()
+ (interactive)
+ (pop-to-buffer svn-status-buffer-name)
+ (other-window 1))
+
+(defun svn-log-edit-files-to-commit ()
+ (mapcar 'svn-status-line-info->filename svn-status-files-to-commit))
+
+(defun svn-log-edit-show-files-to-commit ()
+ (interactive)
+ (message "Files to commit%s: %S"
+ (if svn-status-recursive-commit " recursively" "")
+ (svn-log-edit-files-to-commit)))
+
+(defun svn-log-edit-save-message ()
+ "Save the current log message to the file `svn-log-edit-file-name'."
+ (interactive)
+ (let ((log-edit-file-name (svn-log-edit-file-name)))
+ (if (string= buffer-file-name log-edit-file-name)
+ (save-buffer)
+ (write-region (point-min) (point-max) log-edit-file-name))))
+
+(defun svn-log-edit-erase-edit-buffer ()
+ "Delete everything in the `svn-log-edit-buffer-name' buffer."
+ (interactive)
+ (set-buffer svn-log-edit-buffer-name)
+ (erase-buffer))
+
+(defun svn-log-edit-insert-files-to-commit ()
+ (interactive)
+ (svn-log-edit-remove-comment-lines)
+ (let ((buf-size (- (point-max) (point-min))))
+ (save-excursion
+ (goto-char (point-min))
+ (insert "## Lines starting with '## ' will be removed from the log message.\n")
+ (insert "## File(s) to commit"
+ (if svn-status-recursive-commit " recursively" "") ":\n")
+ (let ((file-list svn-status-files-to-commit))
+ (while file-list
+ (insert (concat "## " (svn-status-line-info->filename (car file-list)) "\n"))
+ (setq file-list (cdr file-list)))))
+ (when (= 0 buf-size)
+ (goto-char (point-max)))))
+
+(defun svn-log-edit-remove-comment-lines ()
+ (interactive)
+ (save-excursion
+ (goto-char (point-min))
+ (flush-lines "^## .*")))
+
+(defun svn-file-add-to-changelog (prefix-arg)
+ "Create a changelog entry for the function at point.
+The variable `svn-status-changelog-style' allows to select the used changlog style"
+ (interactive "P")
+ (cond ((eq svn-status-changelog-style 'changelog)
+ (svn-file-add-to-log-changelog-style prefix-arg))
+ ((eq svn-status-changelog-style 'svn-dev)
+ (svn-file-add-to-log-svn-dev-style prefix-arg))
+ ((fboundp svn-status-changelog-style)
+ (funcall svn-status-changelog-style prefix-arg))
+ (t
+ (error "Invalid setting for `svn-status-changelog-style'"))))
+
+(defun svn-file-add-to-log-changelog-style (curdir)
+ "Create a changelog entry for the function at point.
+`add-change-log-entry-other-window' creates the header information.
+If CURDIR, save the log file in the current directory, otherwise in the base directory of this working copy."
+ (interactive "P")
+ (add-change-log-entry-other-window nil (svn-log-edit-file-name curdir))
+ (svn-log-edit-mode))
+
+;; taken from svn-dev.el: svn-log-path-derive
+(defun svn-dev-log-path-derive (path)
+ "Derive a relative directory path for absolute PATH, for a log entry."
+ (save-match-data
+ (let ((base (file-name-nondirectory path))
+ (chop-spot (string-match
+ "\\(code/\\)\\|\\(src/\\)\\|\\(projects/\\)"
+ path)))
+ (if chop-spot
+ (progn
+ (setq path (substring path (match-end 0)))
+ ;; Kluge for Subversion developers.
+ (if (string-match "subversion/" path)
+ (substring path (+ (match-beginning 0) 11))
+ path))
+ (string-match (expand-file-name "~/") path)
+ (substring path (match-end 0))))))
+
+;; taken from svn-dev.el: svn-log-message
+(defun svn-file-add-to-log-svn-dev-style (prefix-arg)
+ "Add to an in-progress log message, based on context around point.
+If PREFIX-ARG is negative, then use basenames only in
+log messages, otherwise use full paths. The current defun name is
+always used.
+
+If PREFIX-ARG is a list (e.g. by using C-u), save the log file in
+the current directory, otherwise in the base directory of this
+working copy.
+
+If the log message already contains material about this defun, then put
+point there, so adding to that material is easy.
+
+Else if the log message already contains material about this file, put
+point there, and push onto the kill ring the defun name with log
+message dressing around it, plus the raw defun name, so yank and
+yank-next are both useful.
+
+Else if there is no material about this defun nor file anywhere in the
+log message, then put point at the end of the message and insert a new
+entry for file with defun.
+"
+ (interactive "P")
+ (let* ((short-file-names (and (numberp prefix-arg) (< prefix-arg 0)))
+ (curdir (listp prefix-arg))
+ (this-file (if short-file-names
+ (file-name-nondirectory buffer-file-name)
+ (svn-dev-log-path-derive buffer-file-name)))
+ (this-defun (or (add-log-current-defun)
+ (save-excursion
+ (save-match-data
+ (if (eq major-mode 'c-mode)
+ (progn
+ (if (fboundp 'c-beginning-of-statement-1)
+ (c-beginning-of-statement-1)
+ (c-beginning-of-statement))
+ (search-forward "(" nil t)
+ (forward-char -1)
+ (forward-sexp -1)
+ (buffer-substring
+ (point)
+ (progn (forward-sexp 1) (point)))))))))
+ (log-file (svn-log-edit-file-name curdir)))
+ (find-file log-file)
+ (goto-char (point-min))
+ ;; Strip text properties from strings
+ (set-text-properties 0 (length this-file) nil this-file)
+ (set-text-properties 0 (length this-defun) nil this-defun)
+ ;; If log message for defun already in progress, add to it
+ (if (and
+ this-defun ;; we have a defun to work with
+ (search-forward this-defun nil t) ;; it's in the log msg already
+ (save-excursion ;; and it's about the same file
+ (save-match-data
+ (if (re-search-backward ; Ick, I want a real filename regexp!
+ "^\\*\\s-+\\([a-zA-Z0-9-_.@=+^$/%!?(){}<>]+\\)" nil t)
+ (string-equal (match-string 1) this-file)
+ t))))
+ (if (re-search-forward ":" nil t)
+ (if (looking-at " ") (forward-char 1)))
+ ;; Else no log message for this defun in progress...
+ (goto-char (point-min))
+ ;; But if log message for file already in progress, add to it.
+ (if (search-forward this-file nil t)
+ (progn
+ (if this-defun (progn
+ (kill-new (format "(%s): " this-defun))
+ (kill-new this-defun)))
+ (search-forward ")" nil t)
+ (if (looking-at " ") (forward-char 1)))
+ ;; Found neither defun nor its file, so create new entry.
+ (goto-char (point-max))
+ (if (not (bolp)) (insert "\n"))
+ (insert (format "\n* %s (%s): " this-file (or this-defun "")))
+ ;; Finally, if no derived defun, put point where the user can
+ ;; type it themselves.
+ (if (not this-defun) (forward-char -3))))))
+
+;; --------------------------------------------------------------------------------
+;; svn-log-view-mode:
+;; --------------------------------------------------------------------------------
+
+(defvar svn-log-view-mode-map () "Keymap used in `svn-log-view-mode' buffers.")
+(put 'svn-log-view-mode-map 'risky-local-variable t) ;for Emacs 20.7
+
+(when (not svn-log-view-mode-map)
+ (setq svn-log-view-mode-map (make-sparse-keymap))
+ (suppress-keymap svn-log-view-mode-map)
+ (define-key svn-log-view-mode-map (kbd "p") 'svn-log-view-prev)
+ (define-key svn-log-view-mode-map (kbd "n") 'svn-log-view-next)
+ (define-key svn-log-view-mode-map (kbd "~") 'svn-log-get-specific-revision)
+ (define-key svn-log-view-mode-map (kbd "f") 'svn-log-get-specific-revision)
+ (define-key svn-log-view-mode-map (kbd "E") 'svn-log-ediff-specific-revision)
+ (define-key svn-log-view-mode-map (kbd "=") 'svn-log-view-diff)
+ (define-key svn-log-view-mode-map (kbd "#") 'svn-log-mark-partner-revision)
+ (define-key svn-log-view-mode-map (kbd "x") 'svn-log-exchange-partner-mark-with-point)
+ (define-key svn-log-view-mode-map (kbd "TAB") 'svn-log-next-link)
+ (define-key svn-log-view-mode-map [backtab] 'svn-log-prev-link)
+ (define-key svn-log-view-mode-map (kbd "RET") 'svn-log-find-file-at-point)
+ (define-key svn-log-view-mode-map (kbd "e") 'svn-log-edit-log-entry)
+ (define-key svn-log-view-mode-map (kbd "q") 'bury-buffer))
+
+(defvar svn-log-view-popup-menu-map ()
+ "Keymap used to show popup menu in `svn-log-view-mode' buffers.")
+(put 'svn-log-view-popup-menu-map 'risky-local-variable t) ;for Emacs 20.7
+(when (not svn-log-view-popup-menu-map)
+ (setq svn-log-view-popup-menu-map (make-sparse-keymap))
+ (suppress-keymap svn-log-view-popup-menu-map)
+ (define-key svn-log-view-popup-menu-map [down-mouse-3] 'svn-log-view-popup-menu))
+
+(easy-menu-define svn-log-view-mode-menu svn-log-view-mode-map
+"'svn-log-view-mode' menu"
+ '("SVN-LogView"
+ ["Show Changeset" svn-log-view-diff t]
+ ["Ediff file at point" svn-log-ediff-specific-revision t]
+ ["Find file at point" svn-log-find-file-at-point t]
+ ["Mark as diff against revision" svn-log-mark-partner-revision t]
+ ["Get older revision for file at point" svn-log-get-specific-revision t]
+ ["Edit log message" svn-log-edit-log-entry t]))
+
+(defun svn-log-view-popup-menu (event)
+ (interactive "e")
+ (mouse-set-point event)
+ (let* ((rev (svn-log-revision-at-point)))
+ (when rev
+ (svn-status-face-set-temporary-during-popup
+ 'svn-status-marked-popup-face (svn-point-at-bol) (svn-point-at-eol)
+ svn-log-view-mode-menu))))
+
+(defvar svn-log-view-font-lock-basic-keywords
+ '(("^r[0-9]+ .+" (0 `(face font-lock-keyword-face
+ mouse-face highlight
+ keymap ,svn-log-view-popup-menu-map))))
+ "Basic keywords in `svn-log-view-mode'.")
+(put 'svn-log-view-font-basic-lock-keywords 'risky-local-variable t) ;for Emacs 20.7
+
+(defvar svn-log-view-font-lock-keywords)
+(define-derived-mode svn-log-view-mode fundamental-mode "svn-log-view"
+ "Major Mode to show the output from svn log.
+Commands:
+\\{svn-log-view-mode-map}
+"
+ (use-local-map svn-log-view-mode-map)
+ (easy-menu-add svn-log-view-mode-menu)
+ (set (make-local-variable 'svn-log-view-font-lock-keywords) svn-log-view-font-lock-basic-keywords)
+ (dolist (lh svn-log-link-handlers)
+ (add-to-list 'svn-log-view-font-lock-keywords (gethash lh svn-log-registered-link-handlers)))
+ (set (make-local-variable 'font-lock-defaults) '(svn-log-view-font-lock-keywords t)))
+
+(defun svn-log-view-next ()
+ (interactive)
+ (when (re-search-forward "^r[0-9]+" nil t)
+ (beginning-of-line 2)
+ (unless (looking-at "Changed paths:")
+ (beginning-of-line 1))))
+
+(defun svn-log-view-prev ()
+ (interactive)
+ (when (re-search-backward "^r[0-9]+" nil t 2)
+ (beginning-of-line 2)
+ (unless (looking-at "Changed paths:")
+ (beginning-of-line 1))))
+
+(defun svn-log-mark-partner-revision ()
+ "Mark the revision at point to be used as diff against revision."
+ (interactive)
+ (let ((start-pos)
+ (point-at-partner-rev))
+ (dolist (ov (overlays-in (point-min) (point-max)))
+ (when (overlay-get ov 'svn-log-partner-revision)
+ (setq point-at-partner-rev (and (>= (point) (overlay-start ov))
+ (<= (point) (overlay-end ov))))
+ (delete-overlay ov)))
+ (unless point-at-partner-rev
+ (save-excursion
+ (when (re-search-backward "^r[0-9]+" nil t 1)
+ (setq start-pos (point))
+ (re-search-forward "^---------------")
+ (setq overlay (make-overlay start-pos (line-beginning-position 0)))
+ (overlay-put overlay 'face 'svn-log-partner-highlight-face)
+ (overlay-put overlay 'svn-log-partner-revision t))))))
+
+(defun svn-log-exchange-partner-mark-with-point ()
+ (interactive)
+ (let ((cur-pos (point))
+ (dest-pos))
+ (dolist (ov (overlays-in (point-min) (point-max)))
+ (when (overlay-get ov 'svn-log-partner-revision)
+ (setq dest-pos (overlay-start ov))))
+ (when dest-pos
+ (svn-log-mark-partner-revision)
+ (goto-char dest-pos)
+ (forward-line 3)
+ (svn-log-view-prev)
+ (svn-log-view-next))))
+
+(defun svn-log-revision-for-diff ()
+ (let ((rev))
+ (dolist (ov (overlays-in (point-min) (point-max)))
+ (when (overlay-get ov 'svn-log-partner-revision)
+ (save-excursion
+ (unless (and (>= (point) (overlay-start ov))
+ (<= (point) (overlay-end ov)))
+ (goto-char (overlay-start ov))
+ (setq rev (svn-log-revision-at-point))))))
+ rev))
+
+(defun svn-log-revision-at-point ()
+ (save-excursion
+ (end-of-line)
+ (re-search-backward "^r\\([0-9]+\\)")
+ (svn-match-string-no-properties 1)))
+
+(defun svn-log-file-name-at-point (respect-checkout-prefix-path)
+ (let ((full-file-name)
+ (file-name)
+ (checkout-prefix-path (if respect-checkout-prefix-path
+ (url-unhex-string
+ (svn-status-checkout-prefix-path))
+ "")))
+ (save-excursion
+ (beginning-of-line)
+ (when (looking-at " [MA] /\\(.+\\)$")
+ (setq full-file-name (svn-match-string-no-properties 1))))
+ (when (string= checkout-prefix-path "")
+ (setq checkout-prefix-path "/"))
+ (if (null full-file-name)
+ (progn
+ (message "No file at point")
+ nil)
+ (setq file-name
+ (if (eq (string-match (regexp-quote (substring checkout-prefix-path 1)) full-file-name) 0)
+ (substring full-file-name (- (length checkout-prefix-path) (if (string= checkout-prefix-path "/") 1 0)))
+ full-file-name))
+ ;; (message "svn-log-file-name-at-point %s prefix: '%s', full-file-name: %s" file-name checkout-prefix-path full-file-name)
+ file-name)))
+
+(defun svn-log-find-file-at-point ()
+ (interactive)
+ (let ((file-name (svn-log-file-name-at-point t)))
+ (when file-name
+ (let ((default-directory (svn-status-base-dir)))
+ ;;(message "svn-log-file-name-at-point: %s, default-directory: %s" file-name default-directory)
+ (find-file file-name)))))
+
+(defun svn-log-next-link ()
+ "Jump to the next external link in this buffer"
+ (interactive)
+ (let ((start-pos (if (get-text-property (point) 'link-handler)
+ (next-single-property-change (point) 'link-handler)
+ (point))))
+ (goto-char (or (next-single-property-change start-pos 'link-handler) (point)))))
+
+(defun svn-log-prev-link ()
+ "Jump to the previous external link in this buffer"
+ (interactive)
+ (let ((start-pos (if (get-text-property (point) 'link-handler)
+ (previous-single-property-change (point) 'link-handler)
+ (point))))
+ (goto-char (or (previous-single-property-change (or start-pos (point)) 'link-handler) (point)))))
+
+(defun svn-log-view-diff (arg)
+ "Show the changeset for a given log entry.
+When called with a prefix argument, ask the user for the revision."
+ (interactive "P")
+ (svn-status-diff-show-changeset (svn-log-revision-at-point) arg (svn-log-revision-for-diff)))
+
+(defun svn-log-get-specific-revision ()
+ "Get an older revision of the file at point via svn cat."
+ (interactive)
+ ;; (message "%S" (svn-status-make-line-info (svn-log-file-name-at-point t)))
+ (let ((default-directory (svn-status-base-dir))
+ (file-name (svn-log-file-name-at-point t)))
+ (if file-name
+ (svn-status-get-specific-revision-internal
+ (list (svn-status-make-line-info file-name))
+ (svn-log-revision-at-point)
+ nil)
+ (message "No file at point"))))
+
+(defun svn-log-ediff-specific-revision (&optional user-confirmation)
+ "Call ediff for the file at point to view a changeset.
+When called with a prefix argument, ask the user for the revision."
+ (interactive "P")
+ ;; (message "svn-log-ediff-specific-revision: %s" (svn-log-file-name-at-point t))
+ (let* ((cur-buf (current-buffer))
+ (diff-rev (svn-log-revision-for-diff))
+ (upper-rev (if diff-rev
+ diff-rev
+ (svn-log-revision-at-point)))
+ (lower-rev (if diff-rev
+ (svn-log-revision-at-point)
+ (number-to-string (- (string-to-number upper-rev) 1))))
+ (file-name (svn-log-file-name-at-point t))
+ (default-directory (svn-status-base-dir))
+ (upper-rev-file-name)
+ (lower-rev-file-name)
+ (rev-arg))
+ (when user-confirmation
+ (setq rev-arg (read-string "Revision for changeset: " (concat lower-rev ":" upper-rev)))
+ (setq lower-rev (car (split-string rev-arg ":")))
+ (setq upper-rev (cadr (split-string rev-arg ":"))))
+ ;;(message "lower-rev: %s, upper-rev: %s" lower-rev upper-rev)
+ (setq upper-rev-file-name (when file-name
+ (cdar (svn-status-get-specific-revision-internal
+ (list (svn-status-make-line-info file-name)) upper-rev nil))))
+ (setq lower-rev-file-name (when file-name
+ (cdar (svn-status-get-specific-revision-internal
+ (list (svn-status-make-line-info file-name)) lower-rev nil))))
+ ;;(message "%S %S" upper-rev-file-name lower-rev-file-name)
+ (if file-name
+ (let* ((ediff-after-quit-destination-buffer cur-buf)
+ (newer-buffer (find-file-noselect upper-rev-file-name))
+ (base-buff (find-file-noselect lower-rev-file-name))
+ (svn-transient-buffers (list base-buff newer-buffer))
+ (startup-hook '(svn-ediff-startup-hook)))
+ (ediff-buffers base-buff newer-buffer startup-hook))
+ (message "No file at point"))))
+
+(defun svn-log-edit-log-entry ()
+ "Edit the given log entry."
+ (interactive)
+ (let ((rev (svn-log-revision-at-point))
+ (log-message))
+ (svn-run nil t 'propget-parse "propget" "--revprop" (concat "-r" rev) "svn:log")
+ (save-excursion
+ (set-buffer svn-process-buffer-name)
+ (setq log-message (if (> (point-max) 1)
+ (buffer-substring (point-min) (- (point-max) 1))
+ "")))
+ (svn-status-pop-to-commit-buffer)
+ ;; If the buffer has been narrowed, `svn-log-edit-done' will use
+ ;; only the accessible part. So we need not erase the rest here.
+ (delete-region (point-min) (point-max))
+ (insert log-message)
+ (goto-char (point-min))
+ (setq svn-log-edit-update-log-entry rev)))
+
+
+;; allow additional hyperlinks in log view buffers
+(defvar svn-log-link-keymap ()
+ "Keymap used to resolve links `svn-log-view-mode' buffers.")
+(put 'svn-log-link-keymap 'risky-local-variable t) ;for Emacs 20.7
+(when (not svn-log-link-keymap)
+ (setq svn-log-link-keymap (make-sparse-keymap))
+ (suppress-keymap svn-log-link-keymap)
+ (define-key svn-log-link-keymap [mouse-2] 'svn-log-resolve-mouse-link)
+ (define-key svn-log-link-keymap (kbd "RET") 'svn-log-resolve-link))
+
+(defun svn-log-resolve-mouse-link (event)
+ (interactive "e")
+ (mouse-set-point event)
+ (svn-log-resolve-link))
+
+(defun svn-log-resolve-link ()
+ (interactive)
+ (let* ((point-adjustment (if (not (get-text-property (- (point) 1) 'link-handler)) 1
+ (if (not (get-text-property (+ (point) 1) 'link-handler)) -1 0)))
+ (link-name (buffer-substring-no-properties (previous-single-property-change (+ (point) point-adjustment) 'link-handler)
+ (next-single-property-change (+ (point) point-adjustment) 'link-handler))))
+ ;; (message "svn-log-resolve-link '%s'" link-name)
+ (funcall (get-text-property (point) 'link-handler) link-name)))
+
+(defun svn-log-register-link-handler (handler-id link-regexp handler-function)
+ "Register a link handler for external links in *svn-log* buffers
+HANDLER-ID is a symbolic name for this handler. The link handler is active when HANDLER-ID
+is registered in `svn-log-link-handlers'.
+LINK-REGEXP specifies a regular expression that matches the external link.
+HANDLER-FUNCTION is called with the match of LINK-REGEXP when the user clicks at the external link."
+ (let ((font-lock-desc (list link-regexp '(0 `(face font-lock-function-name-face
+ mouse-face highlight
+ link-handler invalid-handler-function
+ keymap ,svn-log-link-keymap)))))
+ ;; no idea, how to use handler-function in invalid-handler-function above, so set it here
+ (setcar (nthcdr 5 (nth 1 (nth 1 (nth 1 font-lock-desc)))) handler-function)
+ (svn-puthash handler-id font-lock-desc svn-log-registered-link-handlers)))
+
+;; example: add support for ditrack links and handle them via svn-log-resolve-ditrack
+;;(svn-log-register-link-handler 'ditrack-issue "i#[0-9]+" 'svn-log-resolve-ditrack)
+;;(defun svn-log-resolve-ditrack (link-name)
+;; (interactive)
+;; (message "svn-log-resolve-ditrack %s" link-name))
+
+
+(defun svn-log-resolve-trac-ticket-short (link-name)
+ "Show the trac ticket specified by LINK-NAME via `svn-trac-browse-ticket'."
+ (interactive)
+ (let ((ticket-nr (string-to-number (svn-substring-no-properties link-name 1))))
+ (svn-trac-browse-ticket ticket-nr)))
+
+;; register the out of the box provided link handlers
+(svn-log-register-link-handler 'trac-ticket-short "#[0-9]+" 'svn-log-resolve-trac-ticket-short)
+
+;; the actually used link handlers are specified in svn-log-link-handlers
+
+;; --------------------------------------------------------------------------------
+;; svn-info-mode
+;; --------------------------------------------------------------------------------
+(defvar svn-info-mode-map () "Keymap used in `svn-info-mode' buffers.")
+(put 'svn-info-mode-map 'risky-local-variable t) ;for Emacs 20.7
+
+(when (not svn-info-mode-map)
+ (setq svn-info-mode-map (make-sparse-keymap))
+ (define-key svn-info-mode-map [?s] 'svn-status-pop-to-status-buffer)
+ (define-key svn-info-mode-map (kbd "h") 'svn-status-pop-to-partner-buffer)
+ (define-key svn-info-mode-map (kbd "n") 'next-line)
+ (define-key svn-info-mode-map (kbd "p") 'previous-line)
+ (define-key svn-info-mode-map (kbd "RET") 'svn-info-show-context)
+ (define-key svn-info-mode-map [?q] 'bury-buffer))
+
+(defun svn-info-mode ()
+ "Major Mode to view informative output from svn."
+ (interactive)
+ (kill-all-local-variables)
+ (use-local-map svn-info-mode-map)
+ (setq major-mode 'svn-info-mode)
+ (setq mode-name "svn-info")
+ (toggle-read-only 1))
+
+(defun svn-info-show-context ()
+ "Show the context for a line in the info buffer.
+Currently is the output from the svn update command known."
+ (interactive)
+ (cond ((save-excursion
+ (goto-char (point-max))
+ (forward-line -1)
+ (beginning-of-line)
+ (looking-at "Updated to revision"))
+ ;; svn-info contains info from an svn update
+ (let ((cur-pos (point))
+ (file-name (buffer-substring-no-properties
+ (progn (beginning-of-line) (re-search-forward ".. +") (point))
+ (line-end-position)))
+ (pos))
+ (when (eq system-type 'windows-nt)
+ (setq file-name (replace-regexp-in-string "\\\\" "/" file-name)))
+ (goto-char cur-pos)
+ (with-current-buffer svn-status-buffer-name
+ (setq pos (svn-status-get-file-name-buffer-position file-name)))
+ (when pos
+ (svn-status-pop-to-new-partner-buffer svn-status-buffer-name)
+ (goto-char pos))))))
+
+;; --------------------------------------------------------------------------------
+;; svn blame minor mode
+;; --------------------------------------------------------------------------------
+
+(unless (assq 'svn-blame-mode minor-mode-alist)
+ (setq minor-mode-alist
+ (cons (list 'svn-blame-mode " SvnBlame")
+ minor-mode-alist)))
+
+(defvar svn-blame-mode-map () "Keymap used in `svn-blame-mode' buffers.")
+(put 'svn-blame-mode-map 'risky-local-variable t) ;for Emacs 20.7
+
+(when (not svn-blame-mode-map)
+ (setq svn-blame-mode-map (make-sparse-keymap))
+ (define-key svn-blame-mode-map [?s] 'svn-status-pop-to-status-buffer)
+ (define-key svn-blame-mode-map (kbd "n") 'next-line)
+ (define-key svn-blame-mode-map (kbd "p") 'previous-line)
+ (define-key svn-blame-mode-map (kbd "RET") 'svn-blame-open-source-file)
+ (define-key svn-blame-mode-map (kbd "a") 'svn-blame-highlight-author)
+ (define-key svn-blame-mode-map (kbd "r") 'svn-blame-highlight-revision)
+ (define-key svn-blame-mode-map (kbd "=") 'svn-blame-show-changeset)
+ (define-key svn-blame-mode-map (kbd "l") 'svn-blame-show-log)
+ (define-key svn-blame-mode-map (kbd "b") 'svn-blame-blame-again)
+ (define-key svn-blame-mode-map (kbd "s") 'svn-blame-show-statistics)
+ (define-key svn-blame-mode-map [?q] 'bury-buffer))
+
+(easy-menu-define svn-blame-mode-menu svn-blame-mode-map
+"svn blame minor mode menu"
+ '("SvnBlame"
+ ["Jump to source location" svn-blame-open-source-file t]
+ ["Show changeset" svn-blame-show-changeset t]
+ ["Show log" svn-blame-show-log t]
+ ["Show blame again" svn-blame-blame-again t]
+ ["Show statistics" svn-blame-show-statistics t]
+ ["Highlight by author" svn-blame-highlight-author t]
+ ["Highlight by revision" svn-blame-highlight-revision t]))
+
+(or (assq 'svn-blame-mode minor-mode-map-alist)
+ (setq minor-mode-map-alist
+ (cons (cons 'svn-blame-mode svn-blame-mode-map) minor-mode-map-alist)))
+
+(make-variable-buffer-local 'svn-blame-mode)
+
+(defun svn-blame-mode (&optional arg)
+ "Toggle svn blame minor mode.
+With ARG, turn svn blame minor mode on if ARG is positive, off otherwise.
+
+Note: This mode does not yet work on XEmacs...
+It is probably because the revisions are in 'before-string properties of overlays
+
+Key bindings:
+\\{svn-blame-mode-map}"
+ (interactive "P")
+ (setq svn-blame-mode (if (null arg)
+ (not svn-blame-mode)
+ (> (prefix-numeric-value arg) 0)))
+ (if svn-blame-mode
+ (progn
+ (easy-menu-add svn-blame-mode-menu)
+ (toggle-read-only 1))
+ (easy-menu-remove svn-blame-mode-menu))
+ (force-mode-line-update))
+
+(defun svn-status-activate-blame-mode ()
+ "Activate the svn blame minor in the current buffer.
+The current buffer must contain a valid output from svn blame"
+ (save-excursion
+ (goto-char (point-min))
+ (let ((buffer-read-only nil)
+ (line (svn-line-number-at-pos))
+ (limit (point-max))
+ (info-end-col (save-excursion (forward-word 2) (+ (current-column) 1)))
+ (s)
+ ov)
+ ;; remove the old overlays (only for testing)
+ ;; (dolist (ov (overlays-in (point) limit))
+ ;; (when (overlay-get ov 'svn-blame-line-info)
+ ;; (delete-overlay ov)))
+ (while (and (not (eobp)) (< (point) limit))
+ (setq ov (make-overlay (point) (point)))
+ (overlay-put ov 'svn-blame-line-info t)
+ (setq s (buffer-substring-no-properties (svn-point-at-bol) (+ (svn-point-at-bol) info-end-col)))
+ (overlay-put ov 'before-string (propertize s 'face 'svn-status-blame-rev-number-face))
+ (overlay-put ov 'rev-info (delete "" (split-string s " ")))
+ (delete-region (svn-point-at-bol) (+ (svn-point-at-bol) info-end-col))
+ (forward-line)
+ (setq line (1+ line)))))
+ (let* ((buf-name (format "*svn-blame: %s <%s>*"
+ (file-relative-name svn-status-blame-file-name)
+ svn-status-blame-revision))
+ (buffer (get-buffer buf-name)))
+ (when buffer
+ (kill-buffer buffer))
+ (rename-buffer buf-name))
+ ;; use the correct mode for the displayed blame output
+ (let ((buffer-file-name svn-status-blame-file-name))
+ (normal-mode)
+ (set (make-local-variable 'svn-status-blame-file-name) svn-status-blame-file-name))
+ (font-lock-fontify-buffer)
+ (svn-blame-mode 1))
+
+(defun svn-blame-open-source-file ()
+ "Jump to the source file location for the current position in the svn blame buffer"
+ (interactive)
+ (let ((src-line-number (svn-line-number-at-pos))
+ (src-line-col (current-column)))
+ (find-file-other-window svn-status-blame-file-name)
+ (goto-line src-line-number)
+ (forward-char src-line-col)))
+
+(defun svn-blame-rev-at-point ()
+ (let ((rev))
+ (dolist (ov (overlays-in (svn-point-at-bol) (line-end-position)))
+ (when (overlay-get ov 'svn-blame-line-info)
+ (setq rev (car (overlay-get ov 'rev-info)))))
+ rev))
+
+(defun svn-blame-show-changeset (arg)
+ "Show a diff for the revision at point.
+When called with a prefix argument, allow the user to edit the revision."
+ (interactive "P")
+ (svn-status-diff-show-changeset (svn-blame-rev-at-point) arg))
+
+(defun svn-blame-show-log (arg)
+ "Show the log for the revision at point.
+The output is put into the *svn-log* buffer
+The optional prefix argument ARG determines which switches are passed to `svn log':
+ no prefix --- use whatever is in the list `svn-status-default-log-arguments'
+ prefix argument of -1: --- use the -q switch (quiet)
+ prefix argument of 0 --- use no arguments
+ other prefix arguments: --- use the -v switch (verbose)"
+ (interactive "P")
+ (let ((switches (svn-status-svn-log-switches arg))
+ (rev (svn-blame-rev-at-point)))
+ (svn-run t t 'log "log" "--revision" rev switches)))
+
+(defun svn-blame-highlight-line-maybe (compare-func)
+ (let ((reference-value)
+ (is-highlighted)
+ (consider-this-line)
+ (hl-ov))
+ (dolist (ov (overlays-in (svn-point-at-bol) (line-end-position)))
+ (when (overlay-get ov 'svn-blame-line-info)
+ (setq reference-value (funcall compare-func ov)))
+ (when (overlay-get ov 'svn-blame-highlighted)
+ (setq is-highlighted t)))
+ (save-excursion
+ (goto-char (point-min))
+ (while (not (eobp))
+ (setq consider-this-line nil)
+ (dolist (ov (overlays-in (svn-point-at-bol) (line-end-position)))
+ (when (overlay-get ov 'svn-blame-line-info)
+ (when (string= reference-value (funcall compare-func ov))
+ (setq consider-this-line t))))
+ (when consider-this-line
+ (dolist (ov (overlays-in (svn-point-at-bol) (line-end-position)))
+ (when (and (overlay-get ov 'svn-blame-highlighted) is-highlighted)
+ (delete-overlay ov))
+ (unless is-highlighted
+ (setq hl-ov (make-overlay (svn-point-at-bol) (line-end-position)))
+ (overlay-put hl-ov 'svn-blame-highlighted t)
+ (overlay-put hl-ov 'face 'svn-status-blame-highlight-face))))
+ (forward-line)))))
+
+(defun svn-blame-show-statistics ()
+ "Show statistics for the current blame buffer."
+ (interactive)
+ (let ((author-map (make-hash-table :test 'equal))
+ (author-list)
+ (author))
+ (save-excursion
+ (goto-char (point-min))
+ (while (not (eobp))
+ (dolist (ov (overlays-in (svn-point-at-bol) (line-end-position)))
+ (when (overlay-get ov 'svn-blame-line-info)
+ (setq author (cadr (overlay-get ov 'rev-info)))
+ (svn-puthash author
+ (+ (gethash author author-map 0) 1)
+ author-map)))
+ (forward-line))
+ (maphash '(lambda (key value) (add-to-list 'author-list (list key value))) author-map)
+ (pop-to-buffer (get-buffer-create (replace-regexp-in-string "svn-blame:" "svn-blame-statistics:" (buffer-name))))
+ (erase-buffer)
+ (dolist (line (sort author-list '(lambda (v1 v2) (> (cadr v1) (cadr v2)))))
+ (insert (format "%s: %s line%s\n" (car line) (cadr line) (if (eq (cadr line) 1) "" "s"))))
+ (goto-char (point-min)))))
+
+(defun svn-blame-highlight-author-field (ov)
+ (cadr (overlay-get ov 'rev-info)))
+
+(defun svn-blame-highlight-author ()
+ "(Un)Highlight all lines with the same author."
+ (interactive)
+ (svn-blame-highlight-line-maybe 'svn-blame-highlight-author-field))
+
+(defun svn-blame-highlight-revision-field (ov)
+ (car (overlay-get ov 'rev-info)))
+
+(defun svn-blame-highlight-revision ()
+ "(Un)Highlight all lines with the same revision."
+ (interactive)
+ (svn-blame-highlight-line-maybe 'svn-blame-highlight-revision-field))
+
+;; --------------------------------------------------------------------------------
+;; svn-process-mode
+;; --------------------------------------------------------------------------------
+(defvar svn-process-mode-map () "Keymap used in `svn-process-mode' buffers.")
+(put 'svn-process-mode-map 'risky-local-variable t) ;for Emacs 20.7
+
+(when (not svn-process-mode-map)
+ (setq svn-process-mode-map (make-sparse-keymap))
+ (define-key svn-process-mode-map (kbd "RET") 'svn-process-send-string-and-newline)
+ (define-key svn-process-mode-map [?s] 'svn-process-send-string)
+ (define-key svn-process-mode-map [?q] 'bury-buffer))
+
+(easy-menu-define svn-process-mode-menu svn-process-mode-map
+"'svn-process-mode' menu"
+ '("SvnProcess"
+ ["Send line to process" svn-process-send-string-and-newline t]
+ ["Send raw string to process" svn-process-send-string t]
+ ["Bury process buffer" bury-buffer t]))
+
+(defun svn-process-mode ()
+ "Major Mode to view process output from svn.
+
+You can send a new line terminated string to the process via \\[svn-process-send-string-and-newline]
+You can send raw data to the process via \\[svn-process-send-string]."
+ (interactive)
+ (kill-all-local-variables)
+ (use-local-map svn-process-mode-map)
+ (easy-menu-add svn-log-view-mode-menu)
+ (setq major-mode 'svn-process-mode)
+ (setq mode-name "svn-process"))
+
+;; --------------------------------------------------------------------------------
+;; svn status persistent options
+;; --------------------------------------------------------------------------------
+
+(defun svn-status-repo-for-path (directory)
+ "Find the repository root for DIRECTORY."
+ (let ((old-process-default-dir))
+ (with-current-buffer (get-buffer-create svn-process-buffer-name)
+ (setq old-process-default-dir default-directory)
+ (setq default-directory directory)) ;; update the default-directory for the *svn-process* buffer
+ (svn-run nil t 'parse-info "info" ".")
+ (with-current-buffer svn-process-buffer-name
+ ;; (message "svn-status-repo-for-path: %s: default-directory: %s directory: %s old-process-default-dir: %s" svn-process-buffer-name default-directory directory old-process-default-dir)
+ (setq default-directory old-process-default-dir)
+ (goto-char (point-min))
+ (let ((case-fold-search t))
+ (if (search-forward "repository root: " nil t)
+ (buffer-substring-no-properties (point) (svn-point-at-eol))
+ (when (search-forward "repository uuid: " nil t)
+ (message "psvn.el: Detected an old svn working copy in '%s'. Please check it out again to get a 'Repository Root' entry in the svn info output."
+ default-directory)
+ (concat "Svn Repo UUID: " (buffer-substring-no-properties (point) (svn-point-at-eol)))))))))
+
+(defun svn-status-base-dir (&optional start-directory)
+ "Find the svn root directory for the current working copy.
+Return nil, if not in a svn working copy."
+ (let* ((start-dir (expand-file-name (or start-directory default-directory)))
+ (base-dir (gethash start-dir svn-status-base-dir-cache 'not-found)))
+ ;;(message "svn-status-base-dir: %S %S" start-dir base-dir)
+ (if (not (eq base-dir 'not-found))
+ base-dir
+ ;; (message "calculating base-dir for %s" start-dir)
+ (unless svn-client-version
+ (svn-status-version))
+ (let* ((base-dir start-dir)
+ (repository-root (svn-status-repo-for-path base-dir))
+ (dot-svn-dir (concat base-dir (svn-wc-adm-dir-name)))
+ (in-tree (and repository-root (file-exists-p dot-svn-dir)))
+ (dir-below (expand-file-name base-dir)))
+ ;; (message "repository-root: %s start-dir: %s" repository-root start-dir)
+ (if (and (<= (car svn-client-version) 1) (< (cadr svn-client-version) 3))
+ (setq base-dir (svn-status-base-dir-for-ancient-svn-client start-dir)) ;; svn version < 1.3
+ (while (when (and dir-below (file-exists-p dot-svn-dir))
+ (setq base-dir (file-name-directory dot-svn-dir))
+ (string-match "\\(.+/\\).+/" dir-below)
+ (setq dir-below
+ (and (string-match "\\(.*/\\)[^/]+/" dir-below)
+ (match-string 1 dir-below)))
+ ;; (message "base-dir: %s, dir-below: %s, dot-svn-dir: %s in-tree: %s" base-dir dir-below dot-svn-dir in-tree)
+ (when dir-below
+ (if (string= (svn-status-repo-for-path dir-below) repository-root)
+ (setq dot-svn-dir (concat dir-below (svn-wc-adm-dir-name)))
+ (setq dir-below nil)))))
+ (setq base-dir (and in-tree base-dir)))
+ (svn-puthash start-dir base-dir svn-status-base-dir-cache)
+ (svn-status-message 7 "svn-status-base-dir %s => %s" start-dir base-dir)
+ base-dir))))
+
+(defun svn-status-base-dir-for-ancient-svn-client (&optional start-directory)
+ "Find the svn root directory for the current working copy.
+Return nil, if not in a svn working copy.
+This function is used for svn clients version 1.2 and below."
+ (let* ((base-dir (expand-file-name (or start-directory default-directory)))
+ (dot-svn-dir (concat base-dir (svn-wc-adm-dir-name)))
+ (in-tree (file-exists-p dot-svn-dir))
+ (dir-below (expand-file-name default-directory)))
+ (while (when (and dir-below (file-exists-p dot-svn-dir))
+ (setq base-dir (file-name-directory dot-svn-dir))
+ (string-match "\\(.+/\\).+/" dir-below)
+ (setq dir-below
+ (and (string-match "\\(.*/\\)[^/]+/" dir-below)
+ (match-string 1 dir-below)))
+ (setq dot-svn-dir (concat dir-below (svn-wc-adm-dir-name)))))
+ (and in-tree base-dir)))
+
+(defun svn-status-save-state ()
+ "Save psvn persistent options for this working copy to a file."
+ (interactive)
+ (let ((buf (find-file (concat (svn-status-base-dir) "++psvn.state"))))
+ (erase-buffer) ;Widen, because we'll save the whole buffer.
+ ;; TO CHECK: why is svn-status-options a global variable??
+ (setq svn-status-options
+ (list
+ (list "svn-trac-project-root" svn-trac-project-root)
+ (list "sort-status-buffer" svn-status-sort-status-buffer)
+ (list "elide-list" svn-status-elided-list)
+ (list "module-name" svn-status-module-name)
+ (list "branch-list" svn-status-branch-list)
+ (list "changelog-style" svn-status-changelog-style)
+ ))
+ (insert (pp-to-string svn-status-options))
+ (save-buffer)
+ (kill-buffer buf)))
+
+(defun svn-status-load-state (&optional no-error)
+ "Load psvn persistent options for this working copy from a file."
+ (interactive)
+ (let ((file (concat (svn-status-base-dir) "++psvn.state")))
+ (if (file-readable-p file)
+ (with-temp-buffer
+ (insert-file-contents file)
+ (setq svn-status-options (read (current-buffer)))
+ (setq svn-status-sort-status-buffer
+ (nth 1 (assoc "sort-status-buffer" svn-status-options)))
+ (setq svn-trac-project-root
+ (nth 1 (assoc "svn-trac-project-root" svn-status-options)))
+ (setq svn-status-elided-list
+ (nth 1 (assoc "elide-list" svn-status-options)))
+ (setq svn-status-module-name
+ (nth 1 (assoc "module-name" svn-status-options)))
+ (setq svn-status-branch-list
+ (nth 1 (assoc "branch-list" svn-status-options)))
+ (setq svn-status-changelog-style
+ (nth 1 (assoc "changelog-style" svn-status-options)))
+ (when (and (interactive-p) svn-status-elided-list (svn-status-apply-elide-list)))
+ (message "psvn.el: loaded %s" file))
+ (if no-error
+ (setq svn-trac-project-root nil
+ svn-status-elided-list nil
+ svn-status-module-name nil
+ svn-status-branch-list nil
+ svn-status-changelog-style 'changelog)
+ (error "psvn.el: %s is not readable." file)))))
+
+(defun svn-status-toggle-sort-status-buffer ()
+ "Toggle sorting of the *svn-status* buffer.
+
+If you turn off sorting, you can speed up \\[svn-status]. However,
+the buffer is not correctly sorted then. This function will be
+removed again, when a faster parsing and display routine for
+`svn-status' is available."
+ (interactive)
+ (setq svn-status-sort-status-buffer (not svn-status-sort-status-buffer))
+ (message "The %s buffer will %sbe sorted." svn-status-buffer-name
+ (if svn-status-sort-status-buffer "" "not ")))
+
+(defun svn-status-toggle-svn-verbose-flag ()
+ "Toggle `svn-status-verbose'. "
+ (interactive)
+ (setq svn-status-verbose (not svn-status-verbose))
+ (message "svn status calls will %suse the -v flag." (if svn-status-verbose "" "not ")))
+
+(defun svn-status-toggle-display-full-path ()
+ "Toggle displaying the full path in the `svn-status-buffer-name' buffer"
+ (interactive)
+ (setq svn-status-display-full-path (not svn-status-display-full-path))
+ (message "The %s buffer will%s use full path names." svn-status-buffer-name
+ (if svn-status-display-full-path "" " not"))
+ (svn-status-update-buffer))
+
+(defun svn-status-set-trac-project-root ()
+ (interactive)
+ (setq svn-trac-project-root
+ (read-string "Trac project root (e.g.: http://projects.edgewall.com/trac/): "
+ svn-trac-project-root))
+ (when (yes-or-no-p "Save the new setting for svn-trac-project-root to disk? ")
+ (svn-status-save-state)))
+
+(defun svn-status-set-module-name ()
+ "Interactively set `svn-status-module-name'."
+ (interactive)
+ (setq svn-status-module-name
+ (read-string "Short Unit Name (e.g.: MyProject): "
+ svn-status-module-name))
+ (when (yes-or-no-p "Save the new setting for svn-status-module-name to disk? ")
+ (svn-status-save-state)))
+
+(defun svn-status-set-changelog-style ()
+ "Interactively set `svn-status-changelog-style'."
+ (interactive)
+ (setq svn-status-changelog-style
+ (intern (funcall svn-status-completing-read-function "svn-status on directory: " '("changelog" "svn-dev" "other"))))
+ (when (string= svn-status-changelog-style 'other)
+ (setq svn-status-changelog-style (car (find-function-read))))
+ (when (yes-or-no-p "Save the new setting for svn-status-changelog-style to disk? ")
+ (svn-status-save-state)))
+
+(defun svn-status-set-branch-list ()
+ "Interactively set `svn-status-branch-list'."
+ (interactive)
+ (setq svn-status-branch-list
+ (split-string (read-string "Branch list: "
+ (mapconcat 'identity svn-status-branch-list " "))))
+ (when (yes-or-no-p "Save the new setting for svn-status-branch-list to disk? ")
+ (svn-status-save-state)))
+
+(defun svn-browse-url (url)
+ "Call `browse-url', using `svn-browse-url-function'."
+ (let ((browse-url-browser-function (or svn-browse-url-function
+ browse-url-browser-function)))
+ (browse-url url)))
+
+;; --------------------------------------------------------------------------------
+;; svn status trac integration
+;; --------------------------------------------------------------------------------
+(defun svn-trac-browse-wiki ()
+ "Open the trac wiki view for the current svn repository."
+ (interactive)
+ (unless svn-trac-project-root
+ (svn-status-set-trac-project-root))
+ (svn-browse-url (concat svn-trac-project-root "wiki")))
+
+(defun svn-trac-browse-timeline ()
+ "Open the trac timeline view for the current svn repository."
+ (interactive)
+ (unless svn-trac-project-root
+ (svn-status-set-trac-project-root))
+ (svn-browse-url (concat svn-trac-project-root "timeline")))
+
+(defun svn-trac-browse-roadmap ()
+ "Open the trac roadmap view for the current svn repository."
+ (interactive)
+ (unless svn-trac-project-root
+ (svn-status-set-trac-project-root))
+ (svn-browse-url (concat svn-trac-project-root "roadmap")))
+
+(defun svn-trac-browse-source ()
+ "Open the trac source browser for the current svn repository."
+ (interactive)
+ (unless svn-trac-project-root
+ (svn-status-set-trac-project-root))
+ (svn-browse-url (concat svn-trac-project-root "browser")))
+
+(defun svn-trac-browse-report (arg)
+ "Open the trac report view for the current svn repository.
+When called with a prefix argument, display the given report number."
+ (interactive "P")
+ (unless svn-trac-project-root
+ (svn-status-set-trac-project-root))
+ (svn-browse-url (concat svn-trac-project-root "report" (if (numberp arg) (format "/%s" arg) ""))))
+
+(defun svn-trac-browse-changeset (changeset-nr)
+ "Show a changeset in the trac issue tracker."
+ (interactive (list (read-number "Browse changeset number: " (number-at-point))))
+ (unless svn-trac-project-root
+ (svn-status-set-trac-project-root))
+ (svn-browse-url (concat svn-trac-project-root "changeset/" (number-to-string changeset-nr))))
+
+(defun svn-trac-browse-ticket (ticket-nr)
+ "Show a ticket in the trac issue tracker."
+ (interactive (list (read-number "Browse ticket number: " (number-at-point))))
+ (unless svn-trac-project-root
+ (svn-status-set-trac-project-root))
+ (svn-browse-url (concat svn-trac-project-root "ticket/" (number-to-string ticket-nr))))
+
+;;;------------------------------------------------------------
+;;; resolve conflicts using ediff
+;;;------------------------------------------------------------
+(defun svn-resolve-conflicts-ediff (&optional name-A name-B)
+ "Invoke ediff to resolve conflicts in the current buffer.
+The conflicts must be marked with rcsmerge conflict markers."
+ (interactive)
+ (let* ((found nil)
+ (file-name (file-name-nondirectory buffer-file-name))
+ (your-buffer (generate-new-buffer
+ (concat "*" file-name
+ " " (or name-A "WORKFILE") "*")))
+ (other-buffer (generate-new-buffer
+ (concat "*" file-name
+ " " (or name-B "CHECKED-IN") "*")))
+ (result-buffer (current-buffer)))
+ (save-excursion
+ (set-buffer your-buffer)
+ (erase-buffer)
+ (insert-buffer-substring result-buffer)
+ (goto-char (point-min))
+ (while (re-search-forward "^<<<<<<< .\\(mine\\|working\\)\n" nil t)
+ (setq found t)
+ (replace-match "")
+ (if (not (re-search-forward "^=======\n" nil t))
+ (error "Malformed conflict marker"))
+ (replace-match "")
+ (let ((start (point)))
+ (if (not (re-search-forward "^>>>>>>> .\\(r[0-9]+\\|merge.*\\)\n" nil t))
+ (error "Malformed conflict marker"))
+ (delete-region start (point))))
+ (if (not found)
+ (progn
+ (kill-buffer your-buffer)
+ (kill-buffer other-buffer)
+ (error "No conflict markers found")))
+ (set-buffer other-buffer)
+ (erase-buffer)
+ (insert-buffer-substring result-buffer)
+ (goto-char (point-min))
+ (while (re-search-forward "^<<<<<<< .\\(mine\\|working\\)\n" nil t)
+ (let ((start (match-beginning 0)))
+ (if (not (re-search-forward "^=======\n" nil t))
+ (error "Malformed conflict marker"))
+ (delete-region start (point))
+ (if (not (re-search-forward "^>>>>>>> .\\(r[0-9]+\\|merge.*\\)\n" nil t))
+ (error "Malformed conflict marker"))
+ (replace-match "")))
+ (let ((config (current-window-configuration))
+ (ediff-default-variant 'default-B))
+
+ ;; Fire up ediff.
+
+ (set-buffer (ediff-merge-buffers your-buffer other-buffer))
+
+ ;; Ediff is now set up, and we are in the control buffer.
+ ;; Do a few further adjustments and take precautions for exit.
+
+ (make-local-variable 'svn-ediff-windows)
+ (setq svn-ediff-windows config)
+ (make-local-variable 'svn-ediff-result)
+ (setq svn-ediff-result result-buffer)
+ (make-local-variable 'ediff-quit-hook)
+ (setq ediff-quit-hook
+ (lambda ()
+ (let ((buffer-A ediff-buffer-A)
+ (buffer-B ediff-buffer-B)
+ (buffer-C ediff-buffer-C)
+ (result svn-ediff-result)
+ (windows svn-ediff-windows))
+ (ediff-cleanup-mess)
+ (set-buffer result)
+ (erase-buffer)
+ (insert-buffer-substring buffer-C)
+ (kill-buffer buffer-A)
+ (kill-buffer buffer-B)
+ (kill-buffer buffer-C)
+ (set-window-configuration windows)
+ (message "Conflict resolution finished; you may save the buffer"))))
+ (message "Please resolve conflicts now; exit ediff when done")
+ nil))))
+
+(defun svn-resolve-conflicts (filename)
+ (let ((buff (find-file-noselect filename)))
+ (if buff
+ (progn (switch-to-buffer buff)
+ (svn-resolve-conflicts-ediff))
+ (error "can not open file %s" filename))))
+
+(defun svn-status-resolve-conflicts ()
+ "Resolve conflict in the selected file"
+ (interactive)
+ (let ((file-info (svn-status-get-line-information)))
+ (or (and file-info
+ (= ?C (svn-status-line-info->filemark file-info))
+ (svn-resolve-conflicts
+ (svn-status-line-info->full-path file-info)))
+ (error "can not resolve conflicts at this point"))))
+
+
+;; --------------------------------------------------------------------------------
+;; Working with branches
+;; --------------------------------------------------------------------------------
+
+(defun svn-branch-select (&optional prompt)
+ "Select a branch interactively from `svn-status-branch-list'"
+ (interactive)
+ (unless prompt
+ (setq prompt "Select branch: "))
+ (let* ((branch (funcall svn-status-completing-read-function prompt svn-status-branch-list))
+ (directory)
+ (base-url))
+ (when (string-match "#\\(1#\\)?\\(.+\\)" branch)
+ (setq directory (match-string 2 branch))
+ (setq base-url (concat (svn-status-base-info->repository-root) "/" directory))
+ (save-match-data
+ (svn-status-parse-info t))
+ (if (eq (length (match-string 1 branch)) 0)
+ (setq branch base-url)
+ (let ((svn-status-branch-list (svn-status-ls base-url t)))
+ (setq branch (concat (svn-status-base-info->repository-root) "/"
+ directory "/"
+ (svn-branch-select (format "Select branch from '%s': " directory)))))))
+ branch))
+
+(defun svn-branch-diff (branch1 branch2)
+ "Show the diff between two svn repository urls.
+When called interactively, use `svn-branch-select' to choose two branches from `svn-status-branch-list'."
+ (interactive
+ (let* ((branch1 (svn-branch-select "svn diff branch1: "))
+ (branch2 (svn-branch-select (format "svn diff %s against: " branch1))))
+ (list branch1 branch2)))
+ (svn-run t t 'diff "diff" svn-status-default-diff-arguments branch1 branch2))
+
+;; --------------------------------------------------------------------------------
+;; svnadmin interface
+;; --------------------------------------------------------------------------------
+(defun svn-admin-create (dir)
+ "Run svnadmin create DIR."
+ (interactive (list (expand-file-name
+ (svn-read-directory-name "Create a svn repository at: "
+ svn-admin-default-create-directory nil nil))))
+ (shell-command-to-string (concat "svnadmin create " dir))
+ (setq svn-admin-last-repository-dir (concat "file://" dir))
+ (message "Svn repository created at %s" dir)
+ (run-hooks 'svn-admin-create-hook))
+
+;; - Import an empty directory
+;; cd to an empty directory
+;; svn import -m "Initial import" . file:///home/stefan/svn_repos/WaldiConfig/trunk
+(defun svn-admin-create-trunk-directory ()
+ "Import an empty trunk directory to `svn-admin-last-repository-dir'.
+Set `svn-admin-last-repository-dir' to the new created trunk url."
+ (interactive)
+ (let ((empty-temp-dir-name (make-temp-name svn-status-temp-dir)))
+ (make-directory empty-temp-dir-name t)
+ (setq svn-admin-last-repository-dir (concat svn-admin-last-repository-dir "/trunk"))
+ (svn-run nil t 'import "import" "-m" "Created trunk directory"
+ empty-temp-dir-name svn-admin-last-repository-dir)
+ (delete-directory empty-temp-dir-name)))
+
+(defun svn-admin-start-import ()
+ "Start to import the current working directory in a subversion repository.
+The user is asked to perform the following two steps:
+1. Create a local repository
+2. Add a trunk directory to that repository
+
+After that step the empty base directory (either the root directory or
+the trunk directory of the selected repository) is checked out in the current
+working directory."
+ (interactive)
+ (if (y-or-n-p "Create local repository? ")
+ (progn
+ (call-interactively 'svn-admin-create)
+ (when (y-or-n-p "Add a trunk directory? ")
+ (svn-admin-create-trunk-directory)))
+ (setq svn-admin-last-repository-dir (read-string "Repository Url: ")))
+ (svn-checkout svn-admin-last-repository-dir "."))
+
+;; --------------------------------------------------------------------------------
+;; svn status profiling
+;; --------------------------------------------------------------------------------
+;;; Note about profiling psvn:
+;; (load-library "elp")
+;; M-x elp-reset-all
+;; (elp-instrument-package "svn-")
+;; M-x svn-status
+;; M-x elp-results
+
+(defun svn-status-elp-init ()
+ (interactive)
+ (require 'elp)
+ (elp-reset-all)
+ (elp-instrument-package "svn-")
+ (message "Run the desired svn command (e.g. M-x svn-status), then use M-x elp-results."))
+
+(defun svn-status-last-commands (&optional string-prefix)
+ "Return a string with the last executed svn commands"
+ (interactive)
+ (unless string-prefix
+ (setq string-prefix ""))
+ (with-output-to-string
+ (dolist (e (ring-elements svn-last-cmd-ring))
+ (princ (format "%s%s: svn %s <%s>\n" string-prefix (nth 0 e) (mapconcat 'concat (nth 1 e) " ") (nth 2 e))))))
+
+;; --------------------------------------------------------------------------------
+;; reporting bugs
+;; --------------------------------------------------------------------------------
+(defun svn-insert-indented-lines (text)
+ "Helper function to insert TEXT, indented by two characters."
+ (dolist (line (split-string text "\n"))
+ (insert (format " %s\n" line))))
+
+(defun svn-prepare-bug-report ()
+ "Create the buffer *psvn-bug-report*. This buffer can be useful to debug problems with psvn.el"
+ (interactive)
+ (let* ((last-output-buffer-name (or svn-status-last-output-buffer-name svn-process-buffer-name))
+ (last-svn-cmd-output (with-current-buffer last-output-buffer-name
+ (buffer-substring-no-properties (point-min) (point-max)))))
+ (switch-to-buffer "*psvn-bug-report*")
+ (delete-region (point-min) (point-max))
+ (insert "This buffer holds some debug informations for psvn.el\n")
+ (insert "Please enter a description of the observed and the wanted behaviour\n")
+ (insert "and send it to the author (stefan@xsteve.at) to allow easier debugging\n\n")
+ (insert "Revisions:\n")
+ (svn-insert-indented-lines (svn-status-version))
+ (insert "Language environment:\n")
+ (dolist (elem (svn-process-environment))
+ (when (member (car (split-string elem "=")) '("LC_MESSAGES" "LC_ALL" "LANG"))
+ (insert (format " %s\n" elem))))
+ (insert "\nLast svn commands:\n")
+ (svn-insert-indented-lines (svn-status-last-commands))
+ (insert (format "\nContent of the <%s> buffer:\n" last-output-buffer-name))
+ (svn-insert-indented-lines last-svn-cmd-output)
+ (goto-char (point-min))))
+
+;; --------------------------------------------------------------------------------
+;; Make it easier to reload psvn, if a distribution has an older version
+;; Just add the following to your .emacs:
+;; (svn-prepare-for-reload)
+;; (load "/path/to/psvn.el")
+
+;; Note the above will only work, if the loaded psvn.el has already the
+;; function svn-prepare-for-reload
+;; If this is not the case, do the following:
+;; (load "/path/to/psvn.el");;make svn-prepare-for-reload available
+;; (svn-prepare-for-reload)
+;; (load "/path/to/psvn.el");; update the keybindings
+;; --------------------------------------------------------------------------------
+
+(defvar svn-prepare-for-reload-dont-touch-list '() "A list of variables that should not be touched by `svn-prepare-for-reload'")
+(defvar svn-prepare-for-reload-variables-list '(svn-global-keymap svn-status-diff-mode-map svn-global-trac-map svn-status-mode-map
+ svn-status-mode-property-map svn-status-mode-extension-map
+ svn-status-mode-options-map svn-status-mode-trac-map svn-status-mode-branch-map
+ svn-log-edit-mode-map svn-log-view-mode-map
+ svn-log-view-popup-menu-map svn-info-mode-map svn-blame-mode-map svn-process-mode-map)
+ "A list of variables that should be set to nil via M-x `svn-prepare-for-reload'")
+(defun svn-prepare-for-reload ()
+ "This function resets some psvn.el variables to nil.
+It makes reloading a newer version of psvn.el easier, if for example the used
+GNU/Linux distribution uses an older version.
+
+The variables specified in `svn-prepare-for-reload-variables-list' will be reseted by this function.
+
+A variable will keep its value, if it is specified in `svn-prepare-for-reload-dont-touch-list'."
+ (interactive)
+ (dolist (var svn-prepare-for-reload-variables-list)
+ (unless (member var svn-prepare-for-reload-dont-touch-list)
+ (message (format "Resetting value of %s to nil" var)))
+ (set var nil)))
+
+(provide 'psvn)
+
+;; Local Variables:
+;; indent-tabs-mode: nil
+;; End:
+;;; psvn.el ends here
--- /dev/null
+;;; quack.el --- enhanced support for editing and running Scheme code
+
+(defconst quack-copyright "Copyright (C) 2002-2008 Neil Van Dyke")
+(defconst quack-copyright-2 "Portions Copyright (C) Free Software Foundation")
+;; Emacs-style font-lock specs adapted from GNU Emacs 21.2 scheme.el.
+;; Scheme Mode menu adapted from GNU Emacs 21.2 cmuscheme.el.
+
+(defconst quack-version "0.33")
+(defconst quack-author-name "Neil Van Dyke")
+(defconst quack-author-email "neil@neilvandyke.org")
+(defconst quack-web-page "http://www.neilvandyke.org/quack/")
+
+(defconst quack-legal-notice
+ "This is free software; you can redistribute it and/or modify it under the
+terms of the GNU General Public License as published by the Free Software
+Foundation; either version 2, or (at your option) any later version. This 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 Emacs;
+see the file `COPYING'. If not, write to the Free Software Foundation, Inc.,
+59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.")
+
+(defconst quack-cvsid "$Id: quack.el,v 1.445 2008-08-01 02:11:34 neil Exp $")
+
+;;; Commentary:
+
+;; INTRODUCTION:
+;;
+;; Quack enhances Emacs support for Scheme programming. Quack is layered
+;; atop the standard packages `cmuscheme.el', by Olin Shivers, and
+;; `scheme.el', by Bill Rozas and Dave Love. Added features include:
+;;
+;; * Menu and commands for viewing popular Scheme-related manuals or
+;; books. Uses local copies of PLT manuals when available, and remote
+;; Web copies when necessary. Command for keyword lookup in PLT
+;; manual, with keyword defaulting to symbol at point.
+;;
+;; * Menus and command for viewing SRFIs. SRFI index information is
+;; automatically downloaded from SRFI Web site. Prompt defaults to
+;; SRFI number referenced at point.
+;;
+;; * A `find-file' alternative that defaults to the file corresponding to
+;; the PLT `require' form at point. (Other module systems will be
+;; supported in future versions of Quack.)
+;;
+;; * Two new sets of font-lock rules for Scheme: "PLT Style," which is
+;; similar to that used by DrScheme 200 Check Syntax; and "Extended GNU
+;; Emacs Style," which is an extended version of the standard Scheme
+;; font-lock rules under GNU Emacs.
+;;
+;; * Pretty-lambda fontification. (GNU Emacs 21 only.)
+;;
+;; * Enhanced `run-scheme' behavior.
+;;
+;; * Enhanced `switch-to-scheme' behavior.
+;;
+;; * Scheme Mode indentation rules for extensions of PLT, Guile, and
+;; other dialects.
+;;
+;; * Command to toggle a `define' form between `(define (<name> <args>)
+;; <body>)' and `(define <name> (lambda (<args>) <body>))' syntax.
+;;
+;; * Command for tidying the formatting in a Scheme Mode buffer.
+;;
+;; * The `)' and `]' keys insert the character that agrees with the
+;; s-expression's opening character.
+;;
+;; * Automatic indenting options for Return key.
+;;
+;; * Mode for inspecting contents of PLT `.plt' package files, before
+;; releasing or installing the packages, or if one does not have PLT
+;; available.
+;;
+;; * Command to open a Dired on a specified PLT collection.
+;;
+;; * `compile' mode can navigate from PLT `setup-plt' errors.
+;;
+;; The name "Quack" was a play on "DrScheme".
+;;
+;; Quack is dedicated to Yosh, naturally.
+
+;; COMPATIBILITY:
+;;
+;; GNU Emacs 21 -- Yes. Quack is developed under GNU Emacs 22 on a
+;; GNU/Linux system, which is the preferred platform for Quacksmokers.
+;; Quack should work under GNU Emacs 22 on any Un*x-like OS. Reportedly,
+;; Quack also works with GNU Emacs 22 on Apple Mac OS X and Microsoft
+;; Windows (NT, 2000, XP), but the author has no means of testing on those
+;; platforms.
+;;
+;; GNU Emacs 21 -- Probably, but no longer tested.
+;;
+;; GNU Emacs 20 -- Probably mostly. When last tested. Some of the menus do
+;; not work properly, due to a bug in easymenu.el (which the FSF will not
+;; fix, since they no longer support Emacs 20). Nested block comments are
+;; not fontified correctly. Pretty-lambda does not work. Quack runs less
+;; efficiently in 20 than 21, due to the lack of standard hash tables.
+;;
+;; XEmacs 21 -- Probably mostly, but no longer tested. Block comment
+;; fontification is not yet supported under XEmacs 21, due to what appears
+;; to be a bug in 21.4 font-lock. Pretty-lambda does not work. XEmacs
+;; Quacksmokers who always want the latest and greatest Quack should
+;; consider GNU Emacs 21 -- Quack treats XEmacs like a high-maintenance
+;; redheaded stepchild.
+
+;; INSTALLATION:
+;;
+;; To install, put this file (`quack.el') somewhere in your Emacs load
+;; path, and add the following line to your `.emacs' file:
+;;
+;; (require 'quack)
+;;
+;; If you don't know what your Emacs load path is, try invoking the command
+;; "C-h v load-path RET" or consulting the Emacs manual.
+;;
+;; Note to advanced Emacsers: Byte-compiled `quack.elc' files generally are
+;; *not* portable between Emacs implementations, nor between different
+;; versions of the same implementation.
+;;
+;; You will also need the GNU `wget' program, which Quack uses for
+;; downloading SRFI indexes. This popular program is included in most
+;; GNU/Linux distributions and is available for most other platforms.
+;;
+;; Note to PLT Scheme users: If you do not already have the PLT manuals
+;; installed, they can be downloaded from
+;; `http://download.plt-scheme.org/doc/' and installed in your PLT `doc'
+;; collection. If Quack is not finding installed PLT manuals, then be sure
+;; that the `quack-pltcollect-dirs' variable contains the appropriate
+;; collection directory (if it does not, then either set the `PLTHOME'
+;; and/or `PLTCOLLECTS' environment variables appropriately, or set
+;; `quack-pltcollect-dirs').
+
+;; KEY BINDINGS:
+;;
+;; The key bindings that Quack adds to `scheme-mode' include:
+;;
+;; C-c C-q m View a manual in your Web browser.
+;; C-c C-q k View the manual documentation for a keyword
+;; (currently only works for PLT manuals).
+;; C-c C-q s View an SRFI.
+;; C-c C-q r Run an inferior Scheme process.
+;; C-c C-q f Find a file using context of point for default.
+;; C-c C-q l Toggle `lambda' syntax of `define'-like form.
+;; C-c C-q t Tidy the formatting of the buffer.
+;;
+;; One additional command that does not currently have a standard binding
+;; is `quack-dired-pltcollect', which prompts for a PLT collection name and
+;; creates a Dired buffer on the collection's directory. (A future version
+;; of Quack may integrate this functionality into a more generalized
+;; documentation navigation interface.)
+
+;; RELEASE ANNOUNCEMENTS EMAIL:
+;;
+;; To receive email notification when a new Quack version is released, ask
+;; neil@neilvandyke.org to add you to the moderated `quack-announce' list.
+
+;; HISTORY:
+;;
+;; Version 0.33 (2008-07-31)
+;; * Added handlers for some PLT 4.0.1 "setup-plt" messages.
+;;
+;; Version 0.32 (2008-06-19)
+;; * Added to `quack-programs'.
+;; * Updated compatibility comments.
+;; * Added indent rule for `for/fold'.
+;;
+;; Version 0.31 (2008-05-03)
+;; * Added `defvar' for `quack-pltish-font-lock-keywords', so that the
+;; GNU Emacs 22.1 compiler doesn't complain about assignment to a free
+;; variable.
+;; * Changed banner regexp for MzScheme for v3.99.x.
+;; * Set `dynamic-wind' `scheme-indent-function to 0, when the default
+;; is 3. It was just taking up too much space. DrScheme's
+;; indentation seems to be equivalent -1, so there is precedent for
+;; something different. We generally respect Emacs indentation
+;; convention.
+;; * Added fontifying and indent for PLT `define-for-syntax',
+;; `define-values-for-syntax', `quasisyntax', `quasisyntax/loc',
+;; `syntax', `syntax/loc', `define-parameters'.
+;; * Advise `scheme-interactively-start-process' for GNU Emacs 22.
+;; * Removed TODO comment that mentioned using `(current-eventspace
+;; (make-eventspace))' under `mred', as Robby Findler has indicated
+;; that is not good advice.
+;;
+;; Version 0.30 (2007-06-27)
+;; * Emacs 22 compatibility change: `string-to-number' instead of
+;; `string-to-int'. Thanks to Charles Comstock.
+;;
+;; Version 0.29 (2006-11-12)
+;; * Fixed `quack-bar-syntax-string', which caused vertical bar
+;; characters to be treated as whitespace. Thanks to Eric Hanchrow
+;; for reporting.
+;;
+;; Version 0.28 (2005-05-14)
+;; * Added `quack-smart-open-paren-p'.
+;; * Changed `scheme-indent-function' for `parameterize' from `defun'
+;; to `1'.
+;; * In `quack-pltish-keywords-to-fontify': added `quasiquote',
+;; `unquote', and `unquote-splicing'.
+;; * Added ".mzschemerc" to `auto-mode-alist'.
+;; * Added a little extra threesemi fontification for Funcelit and
+;; similar Texinfo markup formats.
+;;
+;; Version 0.27 (2004-12-19)
+;; * For Gambit-C, added REPL banner fontifying, `quack-manuals' entry,
+;; and "gsi ~~/syntax-case.scm -" `quack-programs' entry.
+;; * Changed "[PLT]" prefix on PLT manuals to "PLT", to make it easier
+;; to type.
+;; * Minor changes to reflect "MIT Scheme" becoming "MIT/GNU Scheme".
+;;
+;; Version 0.26 (2004-07-14)
+;; * Added fontifying of a bunch of "define-"* syntax from Chicken.
+;;
+;; Version 0.25 (2004-07-09)
+;; * Added `define-record-type' to `quack-pltish-keywords-to-fontify'.
+;; * Added "csi -hygienic" to `quack-programs'.
+;; * In `quack-manuals', replaced PLT-specific `r5rs' and `t-y-scheme'
+;; with generic ones.
+;; * Updated URL in `quack-manuals' for 3rd ed. of `tspl'.
+;; * `quack-view-manual' completions no longer include symbols.
+;; * `quack-view-manual' completion default is now "R5RS".
+;;
+;; Version 0.24 (2004-05-09)
+;; * Made `quack-pltish-keywords-to-fontify' and
+;; `quack-emacs-keywords-to-fontify' custom changes update
+;; immediately. Bug reported by Taylor Campbell.
+;; * Removed some non-syntax names from
+;; `quack-pltish-keywords-to-fontify'.
+;; * Documentation changes.
+;;
+;; Version 0.23 (2003-11-11)
+;; * `quack-local-keywords-for-remote-manuals-p' can now have the value
+;; of the symbol `always', to work around a defect in some versions
+;; of Microsoft Windows. Thanks to Bill Clementson.
+;; * `quack-w3m-browse-url-other-window' no longer splits a `*w3m*'
+;; buffer.
+;; * Added indent and `quack-pltish-keywords-to-fontify' rules for
+;; `c-lambda' and `c-declare'.
+;;
+;; Version 0.22 (2003-07-03)
+;; * `quack-newline-behavior' controls the RET key behavior in Scheme
+;; buffers.
+;; * In `quack-manuals', added Chez Scheme, and updated Chicken.
+;; * Added error message navigation to `compile' for PLT `setup-plt'.
+;; * Partial fix for Quack global menu disappearing from the main menu
+;; bar in XEmacs. Thought it used to work, but it doesn't in XEmacs
+;; 21.4.12.
+;;
+;; Version 0.21 (2003-05-28)
+;; * `quack-find-file' is faster in many cases due to fix to
+;; `quack-backward-sexp'.
+;; * Added auto-mode-alist for `.ccl', `.stk', and `.stklos' files.
+;; * Indent rule additions/changes for `chicken-setup' and `unit/sig'.
+;;
+;; Version 0.20 (2003-05-04)
+;; * Added indent and fontify for SRFI-8 "receive".
+;; * Added indent and fontify for additional PLT syntax.
+;; * Added `quack-fontify-threesemi-p'.
+;; * `quack-tidy-buffer' sets `fill-prefix' to nil when running.
+;; * Added messages to `run-scheme', if only to get rid of annoying
+;; "Mark set" message.
+;; * Added "mzscheme -M errortrace" to `quack-programs'.
+;; * `quack-dired-pltcollect' prompt defaults to `mzlib'.
+;; * "Update SRFI Index" menu item has moved to top of menu, mainly to
+;; avoid usability issue in a particular Emacs menu implementation.
+;; * Several code quality improvements sent by Stefan Monnier will be
+;; in the next release.
+;;
+;; Version 0.19 (2003-03-04)
+;; * Commands such as `scheme-load-file' now start a Scheme process if
+;; none is found.
+;; * Bugfix for using `match-string-no-properties' when we meant
+;; `quack-match-string-no-properties'. (Thanks to Noel Welsh.)
+;;
+;; Version 0.18 (2003-05-02)
+;; * Removed uses of `(regexp-opt LIST t)', since XEmacs21 does not
+;; create match data. (Thanks to Garrett Mitchener for debugging.)
+;; * Added to `quack-programs' and `quack-manuals'.
+;; * Added pretty-case-lambda.
+;; * Changed PLT documentation URL function.
+;;
+;; Version 0.17 (2003-01-03)
+;; * Pretty-lambda is supported well under GNU Emacs 21, when using PLT
+;; Style fontification. Enable via the Options menu. (Based on
+;; approach by Stefan Monnier; suggested by Ray Racine.)
+;; * Various faces now have separate defaults for `light' and `dark'
+;; backgrounds, so may now look better on dark backgrounds.
+;; (Suggested by Eli Barzilay.)
+;; * `quack-find-file' now respects `insert-default-directory' when
+;; there is no default file. (Thanks to Eli Barzilay.)
+;; * Most of the special w3m support has been moved to a separate
+;; package, `w3mnav' (`http://www.neilvandyke.org/w3mnav/').
+;; `quack-w3m-browse-url-other-window' has been added.
+;;
+;; Version 0.16 (2002-12-16)
+;; * `quack-insert-closing' now calls `blink-paren-function'. (Thanks
+;; to Guillaume Marceau and Steve Elkins for reporting this.)
+;; * Now uses PLT 202 manuals. Added "PLT Framework" manual.
+;; * Added `quack-pltish-module-defn-face'.
+;; * Added some PLTish font-lock keywords.
+;;
+;; Version 0.15 (2002-11-21)
+;; * "Keywords" are now fontified in PLT Style fontification mode.
+;; * Definition names are now blue by default in PLT Style.
+;; * Symbol literals with vertical bars are now fontified in PLT Style.
+;; * New `quack-manuals-webjump-sites' function for people who prefer
+;; to use the `webjump' package for invoking manuals.
+;; * New `quack-quiet-warnings-p' option.
+;; * New `quack-pltish-class-defn-face' face.
+;;
+;; Version 0.14 (2002-10-18)
+;; * Fix for `quack-view-manual' interactive prompting (thanks to Marko
+;; Slyz for reporting this).
+;; * `quack-emacsw3m-go-next' and `quack-emacsw3m-go-prev' now work
+;; with GTK reference documentation (not that this has anything to do
+;; with Scheme).
+;; * Added SLIB to `quack-manuals'.
+;; * Added comment about installing PLT manuals (thanks to Marko).
+;; * We now call the canonical version of Emacs "GNU Emacs," instead of
+;; "FSF Emacs".
+;;
+;; Version 0.13 (2002-09-21)
+;; * Bugfix: No longer drop SRFI index entries on the floor.
+;;
+;; Version 0.12 (2002-09-20)
+;; * New "View SRFI" menu. Select "Update SRFI Index" if the submenus
+;; "Draft", "Final", and "Withdrawn" are disabled.
+;; * Most options are now settable via "Options" menu.
+;; * PLT collections are no longer scanned when building "View Manuals"
+;; menu.
+;; * "View Keyword Docs..." back on Scheme Mode menu in addition to
+;; Quack menu.
+;; * Various `defcustom' variables have been made to dynamically update
+;; relevant program state when changed.
+;; * Under GNU Emacs 20, dynamic menus still do not work -- they now
+;; display, but do not perform the selected action. Will do more
+;; debugging after this release.
+;; * '[' and ']' keys work in emacs-w3m of MIT Scheme manuals.
+;;
+;; Version 0.11 (2002-09-17)
+;; * Menus now work under XEmacs. Also now partly broken for Emacs 20.
+;; * New global "Quack" menu. Disable with `quack-global-menu-p'.
+;; * New "View Manual" submenu under GNU Emacs 21 and XEmacs (GNU Emacs
+;; 20 is stuck with the old "View Manual..." menu item).
+;; * Fix for `quack-pltcollects-alist' to include PLT `doc' collection,
+;; which was preventing local manuals from being used.
+;; * `quack-manuals' now includes `t-y-scheme'.
+;; * `quack-view-in-different-browser' command that spawns alternative
+;; Web browser from the special emacs-w3m support, bound to `B'. For
+;; when you normally view manuals in an Emacs window, but
+;; occasionally want to view a particular page in normal Web browser.
+;; * More `scheme-indent-function' properties set.
+;; * `quack-about' command.
+;; * Fix to `quack-keyword-at-point'.
+;;
+;; Version 0.10 (2002-09-11)
+;; * `quack-view-srfi' now prompts with completion, including titles
+;; for all SRFIs. The SRFI titles are fetched from the official SRFI
+;; Web site using the GNU Wget program, and cached locally.
+;; * `quack-view-srfi' also now defaults to the SRFI number at or near
+;; the point.
+;; * `quack-dir' variable specifies a directory where Quack should
+;; store its persistent data files (e.g., cached SRFI indexes), and
+;; defaults to "~/.quack/".
+;; * New `quack-tidy-buffer' command. [C-c C-q t] is now bound to
+;; this; [C-c C-q l] ("l" as in "lambda) is now the official binding
+;; for `quack-toggle-lambda'.
+;; * `quack-find-file' now recognizes PLT `dynamic-require' form.
+;; * Fix to make `quack-looking-at-backward' preserve match data.
+;; * Fix for benign bug in `quack-parent-sexp-search'.
+;;
+;; Version 0.9 (2002-09-04)
+;; * Quack now works under XEmacs 21, except no menus are currently
+;; defined (that will come in a later version) and block comments
+;; aren't fontified.
+;; * `quack-toggle-lambda' command toggles a `define' form between
+;; explicit and implicit `lambda' syntax.
+;; * `quack-dired-pltcollect' feature prompts for a PLT collection name
+;; and creates a Dired on the collection.
+;; * `)' and `]' keys are bound to insert a closing character that
+;; agrees with the opening character of the sexp.
+;; * Nested `#|' comment blocks are now fontified mostly correctly
+;; under GNU Emacs 21.
+;; * Fix to `quack-parent-sexp-search'.
+;; * Fix for PLT manual keywords lookup under Emacs 20.
+;; * `quack-manuals' URLs for assorted implementation manuals now point
+;; to canonical Web copies.
+;; * No longer warns about PLT manual keywords file found without HTML.
+;; * `find-file' key bindings are automatically remapped to
+;; `quack-find-file' in Scheme buffers.
+;; * Both PLT-style and Emacs-style fontification now work with the
+;; `noweb-mode' package. Tested under GNU Emacs 21 with
+;; Debian `nowebm' package version 2.10c-1.
+;; * Added to `quack-emacsish-keywords-to-fontify'.
+;; * Disabled fontification of named `let'.
+;; * Renamed "collect" in PLT identifiers to "pltcollect".
+;; * `auto-mode-alist' set more aggressively.
+;;
+;; Version 0.8 (2002-08-25)
+;; * PLT package file viewing mode. This is mainly used to easily
+;; inspect a ".plt" package before installing it via DrScheme or
+;; "setup-plt".
+;; * No longer warns about `font-lock-keywords' when `noweb-mode'
+;; package is installed.
+;;
+;; Version 0.7 (2002-08-22)
+;; * Now works on GNU Emacs 20 (though people are still encouraged to
+;; upgrade to GNU Emacs 21 if they are able).
+;; * `quack-manuals' now includes MIT Scheme and Chicken manuals
+;; (currently where Debian GNU/Linux puts them).
+;; * `quack-view-srfi' command.
+;; * Named-`let' name is fontified like a PLTish definition name.
+;; * `define-record' and `define-opt' fontified.
+;; * Scheme Mode is forced in `auto-mode-alist' for ".sch" files.
+;; * Fix to `quack-backward-sexp'.
+;; * `quack-warning' messages get your attention.
+;; * `quack-pltrequire-at-point-data-1' search depth limited.
+;;
+;; Version 0.6 (2002-08-20)
+;; * `quack-find-file' now supports multi-line PLT `require' forms.
+;; * When `emacs-w3m' is used, the keys "[", "]", and "t" are bound to
+;; navigate through PLT manuals like in Info mode.
+;; * Names highlighted in PLT-style fontification of `defmacro',
+;; `defmacro-public', `defsyntax'.
+;; * Advised `run-scheme' no longer prompts when there is already a
+;; running Scheme.
+;; * "csi" (Chicken interpreter) added to `quack-programs' default.
+;; * Forces `auto-mode-alist' for ".scm" files to `scheme-mode'
+;; (two can play at that game, `bee-mode'!).
+;; * To-do comments moved from the top of the file to throughout code.
+;;
+;; Version 0.5 (2002-08-15)
+;; * New `quack-find-file' permits quick navigation to files indicated
+;; by a PLT Scheme `require' form under the point. Currently only
+;; works when the "(require" string is on the same line as point.
+;; * Improved PLT-style fontification. Most noticeable difference is
+;; that names in many definition forms are boldfaced. See
+;; `quack-pltish-fontify-definition-names-p' option.
+;; * `quack-collects-alist' added.
+;; * "~/plt/" has been removed from `quack-collect-dirs' default.
+;; * Unnecessary syntax table settings have been removed.
+;; * Reduced memory usage in some cases, via explicit GC calls.
+;;
+;; Version 0.4 (2002-08-07)
+;; * Functionality adapted from author's `giguile.el' package:
+;; - Enhanced `run-scheme' behavior. `quack-run-mzscheme',
+;; `quack-run-mred', and `quack-remove-run-scheme-menu-item-p'
+;; are obsolete.
+;; - Enhanced `switch-to-scheme' behavior.
+;; - Options menu.
+;; - Indent rules for a few Guile-isms.
+;; * Inferior Scheme Mode now uses the preferred fontification method.
+;; * Now uses the PLT-bundled version of R5RS manual, which permits
+;; keyword searching.
+;; * `quack-banner-face' for the MzScheme/MrEd banner in REPL buffer.
+;; * This code includes a start on toolbars and XEmacs21 portability,
+;; but neither feature is yet functional.
+;;
+;; Version 0.3 (2002-08-01)
+;; * PLT-style fontification added, except for quoted lists. Emacs-
+;; style fontification still available; see `quack-fontify-style'.
+;; * `emacs-w3m' package support for lightweight viewing of PLT manuals
+;; in Emacs window. If you install the `emacs-w3m' package, then you
+;; can change the new `quack-browse-url-browser-function' option to
+;; use it.
+;; * Quack menu items added to Scheme Mode menu. "Run Scheme" item
+;; is removed by default; see `quack-remove-run-scheme-menu-item-p'.
+;; * MrEd REPL supported with `quack-run-mred'.
+;; * Better default for `quack-collect-dirs'.
+;; * More `scheme-indent-function' settings.
+;; * Bugfix for `quack-prompt-for-kwmatch-choice'.
+;; * Bugfix for font-lock keywords getting set too early.
+;; * Now byte-compiles without warnings/errors.
+;;
+;; Version 0.2 (2002-07-28)
+;; * Manual keywords lookup.
+;; * Other minor changes.
+;;
+;; Version 0.1 (2002-07-18)
+;; * Initial release.
+
+;; ADMONISHMENT TO IMPRESSIONABLE YOUNG SCHEME STUDENTS:
+;;
+;; Quack should by no means be construed as a model of good programming,
+;; much less of good software engineering. Emacs is by nature a complex
+;; system of interacting kludges. To get Emacs to do useful new things is
+;; to artfully weave one's extensions into a rich tapestry of sticky duct
+;; tape. Also, Quack usually only got hacked on when I was stuck in a busy
+;; lobby for an hour with a laptop and unable to do real work.
+
+;;; Code:
+
+;; Dependencies:
+
+(require 'advice)
+(require 'cmuscheme)
+(require 'compile)
+(require 'custom)
+(require 'easymenu)
+(require 'font-lock)
+(require 'scheme)
+(require 'thingatpt)
+
+(unless (fboundp 'customize-save-variable)
+ (autoload 'customize-save-variable "cus-edit"))
+
+;; Custom Variables:
+
+(defgroup quack nil
+ "Enhanced support for editing and running Scheme code."
+ :group 'scheme
+ :prefix "quack-"
+ :link '(url-link "http://www.neilvandyke.org/quack/"))
+
+(defcustom quack-dir "~/.quack"
+ "*Directory where Quack stores various persistent data in file format."
+ :type 'string
+ :group 'quack)
+
+(defcustom quack-scheme-mode-keymap-prefix "\C-c\C-q"
+ "*Keymap prefix string for `quack-scheme-mode-keymap'.
+
+One of the nice things about having C-q in the prefix is that it is unlikely to
+be already be in use, due to the historical reality of software flow control
+\(and the fact that it is hard to type). If your C-q doesn't seem to be going
+through, then you have several options: disable flow control (if it is safe to
+do so), change the value of this variable, or see the Emacs documentation for
+`enable-flow-control-on'."
+ :type 'string
+ :group 'quack)
+
+(defcustom quack-remap-find-file-bindings-p t
+ "Whether to remap `find-file' key bindings to `quack-find-file'.
+The local map in Scheme Mode and Inferior Scheme Mode buffers is used."
+ :type 'boolean
+ :group 'quack)
+
+(defcustom quack-global-menu-p t
+ "*Whether to have a \"Quack\" menu always on the menu bar."
+ :type 'boolean :group 'quack)
+
+(defcustom quack-tabs-are-evil-p t
+ "*Whether Quack should avoid use of Tab characters in indentation."
+ :type 'boolean
+ :group 'quack)
+
+(defcustom quack-browse-url-browser-function nil
+ "*Optional override for `browse-url-browser-function'.
+
+If non-nil, overrides that variable for URLs viewed by `quack-browse-url'."
+ :type '(choice (const :tag "Do Not Override" nil)
+ (function :tag "Function")
+ (alist :tag "Regexp/Function Association List"
+ :key-type regexp :value-type function))
+ :group 'quack)
+
+(defcustom quack-manuals ; TODO: Options menu.
+
+ ;; TODO: If we make this so users are likely to want to override parts of it,
+ ;; then introduce `quack-manuals-defaults' variable with this in it,
+ ;; and let users edit `quack-manuals-overrides' which are keyed on the
+ ;; ID symbol.
+
+ ;; TODO: Have a way for finding docs on the local filesystem, and/or
+ ;; permitting a user to easily specify location.
+
+ ;; TODO: Provide a way of specifying alternative access means so that, for
+ ;; example, we can look for R5RS first in locally-installed PLT
+ ;; collection, then in one of various non-PLT directories it might be
+ ;; mirrored, then remote PLT copy using local PLT keywords file, then
+ ;; the canonical HTML copy on the Web... Maybe even permit Info
+ ;; format. Let's just reinvent the Web, while we're at it.
+
+ '(
+
+ (r5rs "R5RS"
+ "http://www.schemers.org/Documents/Standards/R5RS/HTML/"
+ nil)
+
+ (bigloo
+ "Bigloo"
+ "http://www-sop.inria.fr/mimosa/fp/Bigloo/doc/bigloo.html"
+ ;;"file:///usr/share/doc/bigloo/manuals/bigloo.html"
+ nil)
+
+ (chez
+ "Chez Scheme User's Guide"
+ "http://www.scheme.com/csug/index.html"
+ nil)
+
+ (chicken
+ "Chicken User's Manual"
+ "http://www.call-with-current-continuation.org/manual/manual.html"
+ ;;"file:///usr/share/doc/chicken/manual.html"
+ nil)
+
+ (gambit
+ "Gambit-C home page"
+ "http://www.iro.umontreal.ca/~gambit/")
+
+ (gauche
+ "Gauche Reference Manual"
+ "http://www.shiro.dreamhost.com/scheme/gauche/man/gauche-refe.html"
+ nil)
+
+ (mitgnu-ref
+ "MIT/GNU Scheme Reference"
+ "http://www.gnu.org/software/mit-scheme/documentation/scheme.html"
+ ;;"http://www.swiss.ai.mit.edu/projects/scheme/documentation/scheme.html"
+
+ ;;"file:///usr/share/doc/mit-scheme/html/scheme.html"
+ nil)
+
+ (mitgnu-user
+ "MIT/GNU Scheme User's Manual"
+ "http://www.gnu.org/software/mit-scheme/documentation/user.html"
+ ;;"http://www.swiss.ai.mit.edu/projects/scheme/documentation/user.html"
+ ;;"file:///usr/share/doc/mit-scheme/html/user.html"
+ nil)
+
+ (mitgnu-sos
+ "MIT/GNU Scheme SOS Reference Manual"
+ "http://www.gnu.org/software/mit-scheme/documentation/sos.html"
+ ;;"http://www.swiss.ai.mit.edu/projects/scheme/documentation/sos.html"
+ ;;"file:///usr/share/doc/mit-scheme/html/sos.html"
+ nil)
+
+ (plt-mzscheme "PLT MzScheme: Language Manual" plt t)
+ (plt-mzlib "PLT MzLib: Libraries Manual" plt t)
+ (plt-mred "PLT MrEd: Graphical Toolbox Manual" plt t)
+ (plt-framework "PLT Framework: GUI Application Framework" plt t)
+ (plt-drscheme "PLT DrScheme: Programming Environment Manual" plt nil)
+ (plt-insidemz "PLT Inside PLT MzScheme" plt nil)
+ (plt-tools "PLT Tools: DrScheme Extension Manual" plt nil)
+ (plt-mzc "PLT mzc: MzScheme Compiler Manual" plt t)
+ (plt-r5rs "PLT R5RS" plt t)
+
+ (scsh
+ "Scsh Reference Manual"
+ "http://www.scsh.net/docu/html/man-Z-H-1.html"
+ ;;"file:///usr/share/doc/scsh-doc/scsh-manual/man-Z-H-1.html"
+ nil)
+
+ (sisc
+ "SISC for Seasoned Schemers"
+ "http://sisc.sourceforge.net/manual/html/"
+ nil)
+
+ (htdp "How to Design Programs"
+ "http://www.htdp.org/"
+ nil)
+ (htus "How to Use Scheme"
+ "http://www.htus.org/"
+ nil)
+ (t-y-scheme "Teach Yourself Scheme in Fixnum Days"
+ "http://www.ccs.neu.edu/home/dorai/t-y-scheme/t-y-scheme.html"
+ nil)
+ (tspl "Scheme Programming Language (Dybvig)"
+ "http://www.scheme.com/tspl/"
+ nil)
+ (sicp "Structure and Interpretation of Computer Programs"
+ "http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-4.html"
+ nil)
+ (slib "SLIB"
+ "http://swissnet.ai.mit.edu/~jaffer/SLIB.html"
+ nil)
+ (faq "Scheme Frequently Asked Questions"
+ "http://www.schemers.org/Documents/FAQ/"
+ nil))
+ "*List of specifications of manuals that can be viewed.
+
+Each manual specification is a list of four elements:
+
+ (SYMBOL TITLE LOCATION USE-KEYWORDS-P)
+
+where SYMBOL is a short symbol that identifies the manual, TITLE is a string,
+LOCATION is either a string with the URL of the manual or the symbol `plt',
+and USE-KEYWORDS-P is `t' or `nil'.
+
+If LOCATION is `plt', then Quack treats it as a PLT bundled manual, looking for
+the HTML and keyword files in `quack-pltcollect-dirs', and optionally providing
+keyword lookup if USE-KEYWORDS-P is `t'. Remote canonical copies of the
+manuals will be used if local copies cannot be found.
+
+If LOCATION is a URL, then USE-KEYWORDS-P must be `nil'."
+ :type '(repeat (list (symbol :tag "Identifying Symbol")
+ (string :tag "Title String")
+ (choice :tag "Location"
+ (string :tag "URL")
+ (const :tag "PLT Bundled Manual" plt))
+ (boolean :tag "Use Keywords?")))
+ :group 'quack)
+
+(defcustom quack-local-keywords-for-remote-manuals-p t
+ "*If non-nil, Quack will use canonical remote Web URLs when there is a local
+keyword file for a PLT manual but no local HTML files. (This feature was
+prompted by the Debian 200.2-3 package for MzScheme, which includes keyword
+files but not HTML files.) If the symbol `always', then Quack will always use
+remote Web manuals for keywords lookup, even if local HTML files exist, as a
+workaround for how some versions of Emacs interact with some versions of
+Microsoft Windows \(inexplicably discarding the fragment identifier from `file'
+scheme URI\)."
+ :type '(choice (const :tag "Permit" t)
+ (const :tag "Forbid" nil)
+ (const :tag "Always" always))
+ :group 'quack
+ :set 'quack-custom-set
+ :initialize 'custom-initialize-default)
+
+(defcustom quack-srfi-master-base-url "http://srfi.schemers.org/"
+ ;; Note: Intentionally not letting user change this through the options menu.
+ "*The base URL for the master SRFI Web pages.
+The SRFI index files should be immediately beneath this."
+ :type 'string
+ :group 'quack)
+
+(defcustom quack-pltcollect-dirs
+ (let ((good '()))
+ (mapcar (function (lambda (dir)
+ (and dir
+ (not (assoc dir good))
+ (file-directory-p dir)
+ (setq good (nconc good (list dir))))))
+ `(,@(let ((v (getenv "PLTCOLLECTS")))
+ (and v (split-string v ":")))
+ ,(let ((v (getenv "PLTHOME")))
+ (and v (expand-file-name "collects" v)))
+ ,@(mapcar 'expand-file-name
+ '("/usr/lib/plt/collects"
+ "/usr/local/lib/plt/collects"))))
+ good)
+ "*PLT collection directories.
+Listed in order of priority."
+ :type '(repeat directory)
+ :group 'quack
+ :set 'quack-custom-set
+ :initialize 'custom-initialize-default)
+
+(defcustom quack-fontify-style 'plt
+ "*Which font-lock fontification style to use.
+
+If symbol `plt', an approximation of PLT DrScheme 200 Check Syntax
+fontification will be used. If symbol `emacs', then fontification in the style
+of GNU Emacs' Scheme Mode with extensions will be used. If nil, then Quack
+will not override the default Scheme Mode fontification."
+ :type '(choice (const :tag "PLT Style" plt)
+ (const :tag "Extended GNU Emacs Style" emacs)
+ (const :tag "Emacs Default" nil))
+ :group 'quack
+ :set 'quack-custom-set
+ :initialize 'custom-initialize-default)
+
+(defcustom quack-pltish-fontify-definition-names-p t
+ "*If non-nil, fontify names in definition forms for PLT-style fontification.
+
+This only has effect when `quack-fontify-style' is `plt'."
+ :type 'boolean
+ :group 'quack
+ :set 'quack-custom-set
+ :initialize 'custom-initialize-default)
+
+(defcustom quack-pltish-fontify-keywords-p t
+ "*If non-nil, fontify keywords in PLT-style fontification.
+
+This only has effect when `quack-fontify-style' is `plt'."
+ :type 'boolean
+ :group 'quack
+ :set 'quack-custom-set
+ :initialize 'custom-initialize-default)
+
+(defcustom quack-pltish-keywords-to-fontify
+ ;; TODO: These are currently R5RS and some SRFI special syntax plus a bunch
+ ;; of PLT, especially PLT 200 class.ss, and some "define-"* variants from
+ ;; various dialects. The dumbness of this kind of highlighting without
+ ;; regard to context is not really satisfactory.
+ '(
+
+ "and" "begin" "begin0" "c-declare" "c-lambda" "case" "case-lambda" "class"
+ "class*" "class*/names" "class100" "class100*" "compound-unit/sig" "cond"
+ "cond-expand" "define" "define-class" "define-const-structure"
+ "define-constant" "define-embedded" "define-entry-point" "define-external"
+ "define-for-syntax" "define-foreign-record" "define-foreign-type"
+ "define-foreign-variable" "define-generic" "define-generic-procedure"
+ "define-inline" "define-location" "define-macro" "define-method"
+ "define-module" "define-opt" "define-public" "define-reader-ctor"
+ "define-record" "define-record-printer" "define-record-type"
+ "define-signature" "define-struct" "define-structure" "define-syntax"
+ "define-syntax-set" "define-values" "define-values-for-syntax"
+ "define-values/invoke-unit/sig" "define/contract" "define/override"
+ "define/private" "define/public" "delay" "do" "else" "exit-handler" "field"
+ "if" "import" "inherit" "inherit-field" "init" "init-field" "init-rest"
+ "instantiate" "interface" "lambda" "let" "let*" "let*-values" "let+"
+ "let-syntax" "let-values" "let/ec" "letrec" "letrec-values" "letrec-syntax"
+ "match-lambda" "match-lambda*" "match-let" "match-let*" "match-letrec"
+ "match-define" "mixin" "module" "opt-lambda" "or" "override" "override*"
+ "namespace-variable-bind/invoke-unit/sig" "parameterize" "private"
+ "private*" "protect" "provide" "provide-signature-elements"
+ "provide/contract" "public" "public*" "quasiquote"
+ "quasisyntax" "quasisyntax/loc" "quote" "receive"
+ "rename" "require" "require-for-syntax" "send" "send*" "set!" "set!-values"
+ "signature->symbols" "super-instantiate" "syntax" "syntax/loc"
+ "syntax-case" "syntax-case*" "syntax-error" "syntax-rules" "unit/sig"
+ "unless" "unquote" "unquote-splicing" "when" "with-handlers" "with-method"
+ "with-syntax"
+
+ )
+ "*Scheme keywords to fontify when `quack-fontify-style' is `plt'."
+ :type '(repeat string)
+ :group 'quack
+ :set 'quack-custom-set
+ :initialize 'custom-initialize-default)
+
+(defcustom quack-emacsish-keywords-to-fontify
+ '("and" "begin" "begin0" "call-with-current-continuation"
+ "call-with-input-file" "call-with-output-file" "call/cc" "case"
+ "case-lambda" "class" "cond" "delay" "do" "else" "exit-handler" "field"
+ "for-each" "if" "import" "inherit" "init-field" "interface" "lambda" "let"
+ "let*" "let*-values" "let-values" "let-syntax" "let/ec" "letrec"
+ "letrec-syntax" "map" "mixin" "opt-lambda" "or" "override" "protect"
+ "provide" "public" "rename" "require" "require-for-syntax" "syntax"
+ "syntax-case" "syntax-error" "syntax-rules" "unit/sig" "unless" "when"
+ "with-syntax")
+ "*Scheme keywords to fontify when `quack-fontify-style' is `emacs'."
+ :type '(repeat string)
+ :group 'quack
+ :set 'quack-custom-set
+ :initialize 'custom-initialize-default)
+
+(defcustom quack-fontify-threesemi-p t
+ "*Whether three-semicolon comments should be fontified differently."
+ :type 'boolean
+ :group 'quack
+ :set 'quack-custom-set
+ :initialize 'custom-initialize-default)
+
+(defcustom quack-pretty-lambda-p nil
+ "*Whether Quack should display \"lambda\" as the lambda character.
+
+`quack-fontify-style' must be `plt'. Only supported under GNU Emacs version
+21\; not under XEmacs or older GNU Emacs.
+
+Note: Pretty lambda requires that suitable iso8859-7 fonts be available. Under
+Debian/GNU Linux, for example, these can be downloaded and installed with the
+shell command \"apt-get install 'xfonts-greek-*'\". If iso8859-7 fonts are
+unavailable for your system, please notify the Quack author."
+ :type 'boolean
+ :group 'quack
+ :set 'quack-custom-set
+ :initialize 'custom-initialize-default)
+
+(defcustom quack-programs
+ '("bigloo" "csi" "csi -hygienic" "gosh" "gsi" "gsi ~~/syntax-case.scm -"
+ "guile" "kawa" "mit-scheme" "mred -z" "mzscheme" "mzscheme -M
+ errortrace" "mzscheme3m" "mzschemecgc" "rs" "scheme" "scheme48" "scsh"
+ "sisc" "stklos" "sxi")
+ "List of Scheme interpreter programs that can be used with `run-scheme'.
+
+These names will be accessible via completion when `run-scheme' prompts for
+which program to run."
+ :group 'quack
+ :type '(repeat string)
+ :set 'quack-custom-set
+ :initialize 'custom-initialize-default)
+
+(defcustom quack-default-program "mzscheme"
+ "Default Scheme interpreter program to use with `run-scheme'."
+ :group 'quack
+ :type 'string)
+
+(defcustom quack-run-scheme-always-prompts-p t
+ "`run-scheme' should always prompt for which program to run.
+
+If nil, `run-scheme' will always use `quack-default-program' when invoked
+interactively without a prefix argument; this is closest to the behavior of the
+`cmuscheme' package."
+ :group 'quack
+ :type 'boolean)
+
+(defcustom quack-run-scheme-prompt-defaults-to-last-p t
+ "If non-nil, `run-scheme' prompt should default to the last program run."
+ :group 'quack
+ :type 'boolean)
+
+(defcustom quack-remember-new-programs-p t
+ "Programs are added to `quack-programs' automatically."
+ :group 'gigule
+ :type 'boolean)
+
+(defcustom quack-switch-to-scheme-method 'other-window
+ "Method to use for choosing a window and frame for the process buffer.
+
+One of three symbols:
+`other-window' will split display in a different window in the current frame,
+splitting the current window if necessary.
+`own-frame' will display the process buffer in its own frame.
+`cmuscheme' will use the normal behavior of the `cmuscheme' package."
+ :group 'quack
+ :type '(choice (const :tag "Other Window" other-window)
+ (const :tag "Own Frame" own-frame)
+ (const :tag "Cmuscheme Behavior" cmuscheme)))
+
+(defcustom quack-warp-pointer-to-frame-p t
+ "Warp mouse pointer to frame with Scheme process buffer.
+
+When `quack-switch-to-scheme-method' is `own-frame', `switch-to-scheme' will
+warp the mouse pointer to the frame displaying the Scheme process buffer."
+ :group 'quack
+ :type 'boolean)
+
+(defcustom quack-newline-behavior 'newline-indent
+ "*Behavior of the RET key in Scheme-Mode buffers. The value is one of three
+symbols: `newline' inserts a normal newline, `newline-indent' \(the default\)
+inserts a newline and leaves the point properly indented on the new line, and
+`indent-newline-indent' indents the current line before inserting a newline and
+indenting the new one."
+ :type '(choice (const 'newline)
+ (const 'newline-indent)
+ (const 'indent-newline-indent))
+ :group 'quack)
+
+(defcustom quack-smart-open-paren-p nil
+ "The `[' can be used to insert `(' characters.
+Actually, this just makes the `(' and '[' keys both insert `(', unless given a
+prefix argument. This makes typing parens easier on typical keyboards for
+which `(' requires a shift modifier but `[' does not. A later version of Quack
+might add actual \"smart\" support for automatic PLT-esque insertion of `['
+instead of `(' in some syntactic contexts."
+ :group 'quack
+ :type 'boolean)
+
+(defcustom quack-options-persist-p t
+ "Option menu settings and programs persist using the `custom' facility.
+
+Note that the value of this option itself cannot be set persistently via the
+option menu -- you must use the `customize' interface or set it manually in an
+Emacs startup file. This is by design, to avoid the risk of users accidentally
+disabling their ability to set persistent options via the option menu."
+ :group 'quack
+ :type 'boolean)
+
+(defcustom quack-quiet-warnings-p t ; TODO: Options menu.
+ "Warning messages are quiet and subtle."
+ :group 'quack
+ :type 'boolean)
+
+(defconst quack-pltish-comment-face 'quack-pltish-comment-face)
+(defface quack-pltish-comment-face
+ '((((class color) (background light)) (:foreground "cyan4"))
+ (((class color) (background dark)) (:foreground "cyan1"))
+ (t (:slant italic)))
+ "Face used for comments when `quack-fontify-style' is `plt'."
+ :group 'quack)
+
+(defconst quack-pltish-selfeval-face 'quack-pltish-selfeval-face)
+(defface quack-pltish-selfeval-face
+ '((((class color) (background light)) (:foreground "green4"))
+ (((class color) (background dark)) (:foreground "green2"))
+ (t ()))
+ "Face used for self-evaluating forms when `quack-fontify-style' is `plt'."
+ :group 'quack)
+
+(defconst quack-pltish-paren-face 'quack-pltish-paren-face)
+(defface quack-pltish-paren-face
+ '((((class color) (background light)) (:foreground "red3"))
+ (((class color) (background dark)) (:foreground "red1"))
+ (((class grayscale)) (:foreground "gray"))
+ (t ()))
+ "Face used for parentheses when `quack-fontify-style' is `plt'."
+ :group 'quack)
+
+(defconst quack-banner-face 'quack-banner-face)
+(defface quack-banner-face
+ '((t (:family "Helvetica")))
+ "Face used in the inferior process buffer for the MzScheme banner.
+
+Currently only takes effect when `quack-fontify-style' is `plt'."
+ :group 'quack)
+
+(defconst quack-pltish-defn-face 'quack-pltish-defn-face)
+(defface quack-pltish-defn-face
+ '((((class color) (background light)) (:bold t :foreground "blue3"))
+ (((class color) (background dark)) (:bold t :foreground "blue1"))
+ (t (:bold t :underline t)))
+ "Face used for names in toplevel definitions.
+
+For PLT-style when `quack-pltish-fontify-definition-names-p' is non-nil."
+ :group 'quack)
+
+(defconst quack-pltish-class-defn-face 'quack-pltish-class-defn-face)
+(defface quack-pltish-class-defn-face
+ '((((class color) (background light))
+ (:foreground "purple3" :inherit quack-pltish-defn-face))
+ (((class color) (background dark))
+ (:foreground "purple1" :inherit quack-pltish-defn-face))
+ (t (:inherit quack-pltish-defn-face)))
+ "Face used for class names in toplevel definitions.
+
+For PLT-style when `quack-pltish-fontify-definition-names-p' is non-nil."
+ :group 'quack)
+
+(defconst quack-pltish-module-defn-face 'quack-pltish-module-defn-face)
+(defface quack-pltish-module-defn-face
+ '((((class color) (background light))
+ (:foreground "purple3" :inherit quack-pltish-defn-face))
+ (((class color) (background dark))
+ (:foreground "purple1" :inherit quack-pltish-defn-face))
+ (t (:inherit quack-pltish-defn-face)))
+ "Face used for module names in toplevel definitions.
+
+For PLT-style when `quack-pltish-fontify-definition-names-p' is non-nil."
+ :group 'quack)
+
+(defconst quack-pltish-keyword-face 'quack-pltish-keyword-face)
+(defface quack-pltish-keyword-face
+ '((t (:bold t)))
+ "Face used for keywords in PLT Style fontification.
+
+For PLT-style when `quack-pltish-fontify-keywords-p' is non-nil."
+ :group 'quack)
+
+(defconst quack-threesemi-semi-face 'quack-threesemi-semi-face)
+(defface quack-threesemi-semi-face
+ '((((class color) (background light))
+ (:foreground "#a0ffff":background "#c0ffff"))
+ (((class color) (background dark))
+ (:foreground "cyan2" :background "cyan4"))
+ (t (:slant italic)))
+ "Face used for `;;;' semicolons when `quack-fontify-threesemi-p' is non-nil."
+ :group 'quack)
+
+(defconst quack-threesemi-text-face 'quack-threesemi-text-face)
+(defface quack-threesemi-text-face
+ '((((class color) (background light))
+ (:foreground "cyan4" :background "#c0ffff"))
+ (((class color) (background dark))
+ (:foreground "white" :background "cyan4"))
+ (t (:slant italic)))
+ "Face used for `;;;' text when `quack-fontify-threesemi-p' is non-nil."
+ :group 'quack)
+
+(defconst quack-threesemi-h1-face 'quack-threesemi-h1-face)
+(defface quack-threesemi-h1-face
+ '((t (:bold t :family "Helvetica" :height 1.4 :size "20pt")))
+ "Face used for H1 headings in `;;;' text."
+ :group 'quack)
+
+(defconst quack-threesemi-h2-face 'quack-threesemi-h2-face)
+(defface quack-threesemi-h2-face
+ '((t (:bold t :family "Helvetica" :height 1.2 :size "16pt")))
+ "Face used for H2 headings in `;;;' text."
+ :group 'quack)
+
+(defconst quack-threesemi-h3-face 'quack-threesemi-h3-face)
+(defface quack-threesemi-h3-face
+ '((t (:bold t :family "Helvetica")))
+ "Face used for H3 headings in `;;;' text."
+ :group 'quack)
+
+(defconst quack-pltfile-prologue-face 'quack-pltfile-prologue-face)
+(defface quack-pltfile-prologue-face
+ '((((class color)) (:foreground "black" :background "gray66"))
+ (((class grayscale)) (:foreground "black" :background "gray66"))
+ (t ()))
+ "Face used for the prologue in a decoded PLT package buffer."
+ :group 'quack)
+
+(defconst quack-pltfile-dir-face 'quack-pltfile-dir-face)
+(defface quack-pltfile-dir-face
+ '((((class color)) (:bold t :foreground "white" :background "gray33"
+ :family "Helvetica" :height 1.2 :size "20pt"))
+ (((class grayscale)) (:bold t :foreground "white" :background "gray33"
+ :family "Helvetica" :height 1.2 :size "20pt"))
+ (t (:bold t :inverse-video t)))
+ "Face used for directory headers in a decoded PLT package buffer."
+ :group 'quack)
+
+(defconst quack-pltfile-file-face 'quack-pltfile-file-face)
+(defface quack-pltfile-file-face
+ '((((class color)) (:bold t :foreground "black" :background "gray66"
+ :family "Helvetica" :height 1.2 :size "20pt"))
+ (((class grayscale)) (:bold t :foreground "black" :background "gray66"
+ :family "Helvetica" :height 1.2 :size "20pt"))
+ (t (:bold t :inverse-video t)))
+ "Face used for file headers in a decoded PLT package buffer."
+ :group 'quack)
+
+(defconst quack-about-title-face 'quack-about-title-face)
+(defface quack-about-title-face
+ '((((class color) (background light))
+ (:bold t :family "Helvetica" :foreground "#008000"
+ :height 240 :size "24pt"))
+ (((class color) (background dark))
+ (:bold t :family "Helvetica" :foreground "#00f000"
+ :height 240 :size "24pt"))
+ (t (:bold t :family "Helvetica"
+ :height 240 :size "24pt")))
+ "Face used for Quack name in About Quack."
+ :group 'quack)
+
+(defconst quack-about-face 'quack-about-face)
+(defface quack-about-face
+ '((t (:family "Helvetica")))
+ "Face used for the body text in About Quack."
+ :group 'quack)
+
+(defconst quack-smallprint-face 'quack-smallprint-face)
+(defface quack-smallprint-face
+ '((t (:family "Courier" :height 80 :size "8pt")))
+ "Face used for the \"small print\" in About Quack."
+ :group 'quack)
+
+;; Compatibility/Portability Misc. Kludges:
+
+;; Note: Some compatibility gotchas found while porting Quack that aren't
+;; addressed by macros and functions:
+;;
+;; * `defface' in Emacs 21 supports ":weight bold", but this is silently
+;; ignored under older Emacsen, so ":bold t" must be used instead.
+;;
+;; * Third argument of `detect-coding-region' is different in Emacs 21 and
+;; XEmacs 21, so only use the first two args.
+;;
+;; * Under XEmacs 21, characters are `equal' but not `eq' to their integer
+;; ASCII values
+;;
+;; * GNU Emacs 21 faces have `:height' property that is either absolute
+;; decipoints or relative scaling factor. XEmacs 21 faces instead have
+;; `:size' property, which appears to be absolute point or mm size.
+;;
+;; * XEmacs 21 text properties appear to be front-sticky, and there did not
+;; seem to be any documentation references to stickiness.
+;;
+;; * XEmacs 21 `local-variable-p' has second argument mandatory.
+;;
+;; * XEmacs 21 does not display submenu labels at all unless the submenu has
+;; content. For inactive submenus, an empty string suffices for content.
+;;
+;; * XEmacs 21 doesn't support composite characters (which we use for very
+;; nice pretty lambda under GNU Emacs).
+
+(eval-and-compile
+ (defvar quack-xemacs-p (eval '(and (boundp 'running-xemacs) running-xemacs)))
+ (defvar quack-gnuemacs-p (not quack-xemacs-p)))
+
+(defmacro quack-when-xemacs (&rest args)
+ (if quack-xemacs-p (cons 'progn args) 'nil))
+
+(defmacro quack-when-gnuemacs (&rest args)
+ (if quack-gnuemacs-p (cons 'progn args) 'nil))
+
+(defmacro quack-define-key-after (keymap key definition &optional after)
+ (if quack-gnuemacs-p
+ `(define-key-after ,keymap ,key ,definition ,after)
+ `(define-key ,keymap ,key (prog1 ,definition ,after))))
+
+(defmacro quack-delete-horizontal-space (&rest args)
+ (if (and quack-gnuemacs-p (>= emacs-major-version 21))
+ `(delete-horizontal-space ,@args)
+ `(delete-horizontal-space)))
+
+(defmacro quack-match-string-no-properties (&rest args)
+ `(,(if quack-xemacs-p 'match-string 'match-string-no-properties) ,@args))
+
+(defmacro quack-menufilter-return (name form)
+ (if (= emacs-major-version 20)
+ ;; Note: This isn't working in Emacs 20. Menu displays now but actions
+ ;; are not executed. No answer to test case posted to comp.emacs
+ ;; and then to gnu.emacs.help. In response to my subsequent bug
+ ;; report against Emacs, RMS says that, if this is indeed a bug,
+ ;; then nothing will be done, since 20 is no longer supported. I'm
+ ;; going to let this quietly not work unless someone emails me that
+ ;; they're actually using Emacs 20.
+ `(easy-menu-filter-return (easy-menu-create-menu ,name ,form))
+ form))
+
+(defmacro quack-propertize (obj &rest props)
+ (if (and quack-gnuemacs-p (>= emacs-major-version 21))
+ `(propertize ,obj ,@props)
+ (let ((obj-var 'quack-propertize-G-obj))
+ `(let ((,obj-var ,obj))
+ (add-text-properties 0 (length ,obj-var) (list ,@props) ,obj-var)
+ ,obj-var))))
+
+(eval-when-compile
+ (when quack-xemacs-p
+ (defvar inhibit-eol-conversion)
+ (defvar minibuffer-allow-text-properties)))
+
+;; Compatibility/Portability Hash Table:
+
+(eval-and-compile
+ (defmacro quack-make-hash-table (&rest args)
+ `(,(if (>= emacs-major-version 21)
+ 'make-hash-table
+ 'quack-fake-make-hash-table)
+ ,@args)))
+
+(defmacro quack-puthash (key value table)
+ (list (if (>= emacs-major-version 21) 'puthash 'quack-fake-puthash)
+ key value table))
+
+(defmacro quack-gethash (key table &optional dflt)
+ (list (if (>= emacs-major-version 21) 'gethash 'quack-fake-gethash)
+ key table dflt))
+
+(defun quack-fake-make-hash-table (&rest args)
+ ;; TODO: Parse the keyword args and make this do 'assoc or 'assq, as
+ ;; appropriate. Currently, this package only needs 'assoc.
+ (vector 'assoc '()))
+
+(defun quack-fake-puthash (key value table)
+ (let ((pair (funcall (aref table 0) key (aref table 1))))
+ (if pair
+ (setcdr pair value)
+ (aset table 1 (cons (cons key value) (aref table 1))))))
+
+(defun quack-fake-gethash (key table &optional dflt)
+ (let ((pair (funcall (aref table 0) key (aref table 1))))
+ (if pair (cdr pair) dflt)))
+
+;; Compatibility/Portability Overlays/Extents:
+
+;; TODO: Maybe get rid of overlays (and the XEmacs extent kludge), and just use
+;; text properties instead.
+
+(defmacro quack-make-face-ovlext (beg end face)
+ (if quack-xemacs-p
+ `(set-extent-property (make-extent ,beg ,end) 'face ,face)
+ `(overlay-put (make-overlay ,beg ,end) 'face ,face)))
+
+(defmacro quack-make-hiding-ovlext (beg end)
+ (if quack-xemacs-p
+ `(set-extent-property (make-extent ,beg ,end) 'invisible t)
+ `(overlay-put (make-overlay ,beg ,end) 'category 'quack-hiding-ovlcat)))
+
+;; Messages, Errors, Warnings:
+
+(defmacro quack-activity (what &rest body)
+ (let ((var-what (make-symbol "quack-activity-G-what")))
+ `(let ((,var-what ,what))
+ (message (concat ,var-what "..."))
+ (prog1 (progn ,@body)
+ (message (concat ,var-what "...done"))))))
+
+(defun quack-internal-error (&optional format &rest args)
+ (if format
+ (apply 'error (concat "Quack Internal Error: " format) args)
+ (error "Quack Internal Error.")))
+
+(defun quack-warning (format &rest args)
+ (apply 'message (concat "Quack Warning: " format) args)
+ (unless quack-quiet-warnings-p
+ (beep)
+ (sleep-for 1)))
+
+;; Regular Expressions:
+
+(defun quack-re-alt (&rest regexps)
+ (concat "\\(" (mapconcat 'identity regexps "\\|") "\\)"))
+
+(defun quack-re-optional (&rest regexps)
+ (concat "\\("
+ (apply 'concat regexps)
+ "\\)?"))
+
+;; Misc.:
+
+;; (defun quack-abbreviate-file-name (file-name)
+;; (let ((directory-abbrev-alist '()))
+;; (abbreviate-file-name file-name)))
+
+(defun quack-delete-file-if-can (file)
+ (condition-case nil (delete-file file) (error nil)))
+
+(defun quack-expand-file-name (name-or-names &optional directory)
+ ;; Note: This only works for systems with Unix-like filenames.
+ (expand-file-name (if (listp name-or-names)
+ (mapconcat 'identity name-or-names "/")
+ name-or-names)
+ directory))
+
+(defun quack-kill-current-buffer ()
+ (interactive)
+ (kill-buffer (current-buffer)))
+
+(defun quack-line-at-point ()
+ (save-excursion
+ (buffer-substring-no-properties
+ (progn (beginning-of-line) (point))
+ (progn (end-of-line) (point)))))
+
+(defun quack-looking-at-backward (re &optional limit)
+ (save-excursion
+ (save-restriction
+ (let ((start-pt (point)))
+ (narrow-to-region (point-min) (point))
+ (and (re-search-backward re limit t)
+ (= (match-end 0) start-pt)
+ (match-beginning 0))))))
+
+(defun quack-looking-at-close-paren-backward ()
+ (save-match-data
+ (quack-looking-at-backward "[])][ \t\r\n\f]*")))
+
+(defun quack-looking-at-open-paren-backward ()
+ (save-match-data
+ (quack-looking-at-backward "[[(][ \t\r\n\f]*")))
+
+(defun quack-make-directory (dir)
+ (setq dir (file-name-as-directory dir))
+ (unless (file-directory-p dir)
+ (make-directory dir t)))
+
+(defun quack-make-directory-for-file (file)
+ (let ((dir (file-name-directory file)))
+ (when dir (quack-make-directory dir))))
+
+(defun quack-propertize-bold (str)
+ (quack-propertize str 'face 'bold))
+
+(defun quack-propertize-face (str face)
+ (quack-propertize str 'face face))
+
+(defun quack-propertize-italic (str)
+ (quack-propertize str 'face 'italic))
+
+(defun quack-sort-string-list-copy (lst)
+ (sort (copy-sequence lst) 'string<))
+
+(defun quack-uncomment-region (beg end)
+ ;; TODO: Make a quack-toggle-commentout-region.
+ (interactive "r")
+ (comment-region beg end '(4)))
+
+(defun quack-without-side-whitespace (str)
+ ;; Copied from `padr-str-trim-ws' by author.
+ ;;
+ ;; TODO: Don't make an intermediate string. Use regexp match start position.
+ (save-match-data
+ (if (string-match "^[ \t\n\r]+" str)
+ (setq str (substring str (match-end 0))))
+ (if (string-match "[ \t\n\r]+$" str)
+ (setq str (substring str 0 (match-beginning 0))))
+ str))
+
+;; Kludgey Sexp Buffer Operations:
+
+(defconst quack-backward-sexp-re
+ (concat "\\`"
+ (quack-re-alt "[^\";\\\\]"
+ "\\\\\\."
+ (concat "\""
+ (quack-re-alt "[^\"\\\\]"
+ "\\\\\\.")
+ "*\""))
+ "*\\([\"\\\\]\\)?"))
+
+(defun quack-backward-sexp ()
+ ;; Returns non-nil iff point was in a string literal or comment.
+ (interactive)
+ (when (bobp)
+ (error "beginning of buffer"))
+ (save-match-data
+ (let* ((orig (point))
+ (bol (progn (beginning-of-line) (point))))
+ (if (string-match quack-backward-sexp-re
+ (buffer-substring-no-properties bol orig))
+ (if (match-beginning 3)
+ ;; We're in what appears to be a comment or unterminated string
+ ;; literal (though might not be, due to multi-line string
+ ;; literals and block comments), so move point to the beginning.
+ (progn (goto-char (+ bol (match-beginning 3)))
+ t)
+ ;; We don't appear to be in a comment or string literal, so just
+ ;; let `backward-sexp' do its thing.
+ (goto-char orig)
+ (backward-sexp)
+ nil)))))
+
+(defun quack-parent-sexp-search (name-regexp &optional max-depth max-breadth)
+ (save-match-data
+ (save-excursion
+ (let ((max-depth (or max-depth 100))
+ (max-breadth (or max-breadth 100))
+ (orig-point (point))
+ (found 'looking)
+ (depth 0)
+ (child-start nil))
+ (while (and (eq found 'looking) (< depth max-depth))
+ (condition-case nil
+ (let ((breadth 0))
+ ;; Loop until we hit max breadth or error.
+ (while (< breadth max-breadth)
+ (when (and (quack-backward-sexp) (not child-start))
+ (setq child-start (point)))
+ (setq breadth (1+ breadth)))
+ ;; We hit our max breadth without erroring, so set the found
+ ;; flag to indicate failure and then fall out of our loop.
+ (setq found nil))
+ (error ; scan-error
+ ;; We probably hit the beginning of the enclosing sexp, and point
+ ;; should be on the first sexp, which will most often be the form
+ ;; name, so first check that there really is an open paren to our
+ ;; left, and then check if it matches our regexp.
+ (let ((paren-start (quack-looking-at-open-paren-backward)))
+ (if paren-start
+ ;; There is a paren, so check the name of the form.
+ (if (and (looking-at name-regexp)
+ (quack-not-symbol-char-at-point-p (match-end 0)))
+ ;; Found it, so set the result to a list (lexeme, lexeme
+ ;; end point, last nested child sexp start point, parent
+ ;; paren start point) and then fall out of our loop.
+ ;; Note that we return the original point if no child
+ ;; point was found, on the assumption that point was at
+ ;; the beginning of the child sexp (unless it was within
+ ;; the found form name, in which case child sexp start
+ ;; is nil).
+ (setq found (list (quack-match-string-no-properties 0)
+ (match-end 0)
+ (or child-start
+ (if (> orig-point (match-end 0))
+ orig-point))
+ paren-start))
+ ;; This form name didn't match, so try to move up in the
+ ;; paren syntax (which will usually mean moving left one
+ ;; character).
+ (condition-case nil
+ (progn (up-list -1)
+ (setq child-start (point))
+ (setq depth (1+ depth)))
+ (error ; scan-error
+ ;; We can't go up here, so set found flag to indicate
+ ;; failure and then fall out of the loop.
+ (setq found nil))))
+ ;; There wasn't a paren, which means we hit a scan error for
+ ;; some reason other than being at the beginning of the sexp,
+ ;; so consider the search a failure
+ (setq found nil))))))
+ (if (eq found 'looking)
+ nil
+ found)))))
+
+;; TODO: We really need a global definition of what are Scheme symbol
+;; constituent characters (or a whole-symbol regexp)!
+
+(defun quack-not-symbol-char-at-point-p (pt)
+ ;; This is used to check for a symbol boundary point.
+ (save-match-data
+ (or (= pt (point-max))
+ (if (string-match "[^-a-zA-Z0-9!+<=>$%&*./:@^_~]"
+ (buffer-substring-no-properties pt (1+ pt)))
+ t))))
+
+;; String Constant Hashtable:
+
+(eval-and-compile
+ (if (< emacs-major-version 21)
+
+ (defun quack-strconst (str) str)
+
+ (defvar quack-strconst-hashtable
+ (if (>= emacs-major-version 21)
+ (quack-make-hash-table :test 'equal :size 1000)))
+
+ (defun quack-strconst (str)
+ (unless (stringp str)
+ (error "Non-string object passed to quack-strconst: %s" str))
+ (or (quack-gethash str quack-strconst-hashtable nil)
+ (quack-puthash str str quack-strconst-hashtable)
+ str))))
+
+;; Web URLs:
+
+(defun quack-quote-url-substring (str &optional quote-slash-p always-new-p)
+ (save-match-data
+ (let ((regexp (if quote-slash-p "[^-_.A-Za-z0-9]" "[^-_.A-Za-z0-9/]"))
+ (subs '())
+ (len (length str))
+ (start 0))
+ (while (and (> len start)
+ (string-match regexp str start))
+ (let ((beg (match-beginning 0))
+ (end (match-end 0)))
+ (when (> beg start)
+ (setq subs (cons (substring str start beg) subs)))
+ (setq subs (cons (format "%%%X" (aref str beg)) subs))
+ (setq start end)))
+ (if subs
+ (apply 'concat (reverse (if (> len start)
+ (cons (substring str start len) subs)
+ subs)))
+ (if always-new-p (copy-sequence str) str)))))
+
+(defun quack-file-url (dir file)
+ ;; TODO: This is Unix-centric and a little fragile. Rewrite eventually.
+ (concat "file:"
+ (quack-quote-url-substring dir)
+ "/"
+ (or (quack-quote-url-substring file) "")))
+
+(defun quack-build-url (base path)
+ (let ((base-slash-p (= (aref base (1- (length base))) ?\/)))
+ (if path
+ (mapconcat 'identity
+ (cons (if base-slash-p
+ (substring base 0 -1)
+ base)
+ path)
+ "/")
+ (if base-slash-p
+ base
+ (concat base "/")))))
+
+;; Web Browsing:
+
+(defun quack-browse-url (url)
+ (require 'browse-url)
+ (message "Quack viewing URL: %s" url)
+ (let ((browse-url-browser-function (or quack-browse-url-browser-function
+ browse-url-browser-function)))
+ (browse-url url)))
+
+(defun quack-browse-quack-web-page ()
+ (interactive)
+ (quack-browse-url quack-web-page))
+
+(defun quack-w3m-browse-url-other-window (url &optional new-window)
+ (interactive (eval '(browse-url-interactive-arg "URL: ")))
+ (unless (string= (buffer-name) "*w3m*")
+ (switch-to-buffer-other-window (current-buffer)))
+ ;; TODO: If `*w3m*' buffer is visible in current frame or other frame,
+ ;; switch to that, for Emacsen that don't do that by default.
+ (eval '(w3m-browse-url url nil)))
+
+;; Web Getting:
+
+(defconst quack-web-get-log-buffer-name "*quack-web-get*")
+
+(defun quack-web-get-to-file (url out-file)
+ ;; TODO: Support other getting tools, such as "lynx -source", "links
+ ;; -source", "w3m -dump_source", and the Emacs w3 package. Most of
+ ;; these send the Web content to stdout, so, unlike for wget, it will
+ ;; be easier to insert directly to a buffer and send stderr to a temp
+ ;; file. We should have *-to-file-* and *-insert-via-* functions for
+ ;; each external downloader program anyway.
+ (quack-make-directory-for-file out-file)
+ (quack-web-get-to-file-via-wget url out-file))
+
+;;(defun quack-web-get-to-temp-file (url)
+;; (let ((temp-file (quack-make-temp-file "web-get")))
+;; (quack-web-get-to-file url temp-file)
+;; temp-file))
+
+(defun quack-web-get-to-file-via-wget (url out-file)
+ ;; TODO: Make this initially download to a temp file; replace any
+ ;; pre-existing out-file after successful download. Do this for any
+ ;; external downloader programs that write to the specified output file
+ ;; before the download is complete.
+ (let ((window (selected-window))
+ (saved-buf (current-buffer))
+ (log-buf (get-buffer-create quack-web-get-log-buffer-name)))
+ (unwind-protect
+ (progn
+ ;; Prepare the log buffer.
+ (set-buffer log-buf)
+ (widen)
+ (buffer-disable-undo)
+ (goto-char (point-min))
+ (delete-region (point-min) (point-max))
+ (set-window-buffer window log-buf)
+ ;; Do the wget.
+ (quack-activity
+ (format "Getting %S via wget" url)
+ (let ((status (call-process "wget" nil t t
+ "-O" out-file "-t" "1" "--" url)))
+ (unless (= status 0)
+ (quack-delete-file-if-can out-file)
+ (error "Could not get %S via wget." url))
+ (kill-buffer log-buf)
+ out-file)))
+ ;; unwind-protect cleanup
+ (set-window-buffer window saved-buf)
+ (set-buffer saved-buf))))
+
+;; HTML Kludges:
+
+(defun quack-strip-limited-html-tags (str)
+ (save-match-data
+ (let ((case-fold-search t)
+ (str-len (length str))
+ (frags '())
+ (start 0))
+ (while (string-match "</?[a-z]+[ \r\n]*>" str start)
+ (when (> (match-beginning 0) start)
+ (setq frags (cons (substring str start (match-beginning 0)) frags)))
+ (setq start (match-end 0)))
+ (if frags
+ (progn (when (< start str-len)
+ (setq frags (cons (substring str start) frags)))
+ (apply 'concat (reverse frags)))
+ str))))
+
+;; Temp Files:
+
+(defun quack-temp-dir ()
+ (file-name-as-directory (expand-file-name "tmp" quack-dir)))
+
+;; TODO: Make sure this gets executed in load phase even if byte-compiled.
+
+(random t)
+
+(defun quack-make-temp-file (purpose-str)
+ ;; Note: There is an obvious race condition here. But we're trying to do
+ ;; this in portable Elisp, and if user's `quack-dir' is writable by
+ ;; someone other than user, then user has bigger problems.
+ (save-excursion
+ (let* ((buf (generate-new-buffer "*quack-make-temp-file*"))
+ (dir (quack-temp-dir))
+ file)
+ (set-buffer buf)
+ (quack-make-directory dir)
+ (while (progn (setq file (expand-file-name (format "%d-%s-%d"
+ (emacs-pid)
+ purpose-str
+ (random 10000))
+ dir))
+ (file-exists-p file)))
+ (set-visited-file-name file)
+ (save-buffer 0)
+ (kill-buffer buf)
+ file)))
+
+;; About:
+
+(defun quack-about ()
+ (interactive)
+ (let* ((buf-name "*About Quack*")
+ (buf (get-buffer buf-name)))
+ (when buf (kill-buffer buf))
+ (setq buf (get-buffer-create buf-name))
+ (switch-to-buffer buf)
+ (setq buffer-read-only nil)
+ (widen)
+ (fundamental-mode)
+ (when font-lock-mode
+ ;;(quack-warning "Font-lock mode mysteriously on in fundamental-mode.")
+ (font-lock-mode -1))
+ (buffer-disable-undo)
+ ;;(delete-region (point-min) (point-max))
+ (erase-buffer)
+ (insert
+ "\n"
+ (quack-propertize-face (copy-sequence "Quack") 'quack-about-title-face)
+ " Version "
+ (quack-propertize-bold (copy-sequence quack-version))
+ "\n"
+ (quack-propertize-italic
+ (copy-sequence "Enhanced Emacs support for Scheme programming"))
+ "\n\n"
+ "You can email bug reports and feature requests to the author,\n"
+ quack-author-name
+ " <"
+ quack-author-email
+ ">. Mention that\n"
+ "you are using "
+ (quack-propertize-bold
+ (copy-sequence
+ (cond (quack-gnuemacs-p "GNU Emacs")
+ (quack-xemacs-p "XEmacs")
+ (t "*an unrecognized Emacs kind*"))))
+ " "
+ (quack-propertize-bold
+ (format "%d.%d" emacs-major-version emacs-minor-version))
+ " on "
+ (quack-propertize-bold (copy-sequence system-configuration))
+ ".\n\n"
+ "To be notified via email when new Quack versions are released,\n"
+ "ask Neil to add you to the moderated "
+ (quack-propertize-bold "quack-announce")
+ " list.\n\n"
+ "Visit the Web page: "
+ quack-web-page
+ "\n")
+ (insert "\n\n"
+ (quack-propertize-face (copy-sequence quack-copyright)
+ 'quack-smallprint-face)
+ "\n"
+ (quack-propertize-face (copy-sequence quack-copyright-2)
+ 'quack-smallprint-face)
+ "\n\n"
+ (quack-propertize-face (concat quack-legal-notice "\n")
+ 'quack-smallprint-face))
+ (goto-char (point-min))
+ (set-buffer-modified-p nil)
+ (setq buffer-read-only t)
+ (local-set-key "q" 'quack-kill-current-buffer)
+ (local-set-key "w" 'quack-browse-quack-web-page)
+ (message
+ "Press `q' to quit *About Quack*, `w' to visit the Quack Web page.")))
+
+;; PLT Collections:
+
+(defvar quack-pltcollects-alist-cache nil)
+
+(defun quack-invalidate-pltcollects-caches ()
+ (setq quack-pltcollects-alist-cache nil)
+ (quack-invalidate-manuals-caches))
+
+(defun quack-pltcollects-alist ()
+ (or quack-pltcollects-alist-cache
+ (quack-activity
+ "Scanning PLT collection directories"
+ (let ((result '()))
+ (mapcar (function
+ (lambda (dir)
+ (mapcar (function
+ (lambda (subdir)
+ (unless (member subdir '("." ".." "CVS" "RCS"))
+ (let ((subdir-path (expand-file-name subdir
+ dir)))
+ (when (file-directory-p subdir-path)
+ (setq result
+ (cons (cons subdir subdir-path)
+ result)))))))
+ (condition-case nil
+ (directory-files dir)
+ (file-error nil)))))
+ quack-pltcollect-dirs)
+ (setq quack-pltcollects-alist-cache (reverse result))))))
+
+(defun quack-dir-for-pltcollect (name)
+ (cdr (assoc name (quack-pltcollects-alist))))
+
+(defun quack-dired-pltcollect ()
+ (interactive)
+ (let* ((alist (quack-pltcollects-alist))
+ (default (if (assoc "mzlib" alist) "mzlib" nil))
+ (dir (cdr (assoc
+ (completing-read
+ (if default
+ (format "Dired for PLT collection (default %S): "
+ default)
+ "Dired for PLT collection: ")
+ alist nil t nil nil default)
+ alist))))
+ (and dir (dired dir))))
+
+;; Find File:
+
+(defun quack-shorter-file-relative-name (filename &optional directory)
+ (let ((absolute (expand-file-name filename directory))
+ (relative (file-relative-name filename directory)))
+ (if (< (length relative) (length absolute))
+ relative
+ absolute)))
+
+;; TODO: Also write `quack-find-file-other-window' and
+;; `quack-find-file-other-frame' and steal appropriate key bindings.
+
+(defun quack-find-file ()
+ ;; TODO: Hangup/delay problems in mega-huge files.
+ ;;
+ ;; TODO: Handle `(load <filename>)'
+ (interactive)
+ (let* ((default (quack-find-file-default))
+ (entry (let ((insert-default-directory (if default
+ nil
+ insert-default-directory)))
+ (read-file-name
+ (if default
+ (format "Quack find file (default %S): "
+ (quack-shorter-file-relative-name
+ default
+ default-directory))
+ "Quack find file: ")
+ default-directory
+ default))))
+ (find-file (if (string= entry "")
+ (or default "")
+ entry))))
+
+(defun quack-find-file-default ()
+ (or (quack-pltrequire-at-point-filename)
+ ;; TODO: Add support for syntax from Guile, SLIB, Chicken, etc.
+ ))
+
+;; TODO: Guile `:use-module' support. Forget about 1.4, and do 1.6.
+;;
+;; (defun quack-guilecolonusemodule-at-point-data ()
+;; (save-match-data
+;; (when (thing-at-point-looking-at
+;; ":use-module[ \t]+\\(([^][()\"#'`,]+)\\)")
+;; (condition-case nil
+;; (car (read-from-string (buffer-substring-no-properties
+;; (match-beginning 1) (match-end 1))))
+;; (error nil)))))
+;;
+;; ;; (define-module (ice-9 expect) :use-module (ice-9 regex))
+
+;; TODO: Guile 1.6 `use-modules' and `use-syntax' support.
+;;
+;; (use-modules (ice-9 regex))
+;;
+;; (use-modules ((ice-9 popen)
+;; :select ((open-pipe . pipe-open) close-pipe)
+;; :renamer (symbol-prefix-proc 'unixy:)))
+;;
+;; (use-modules { SPEC }+ )
+;;
+;; SPEC ::= MODULE-NAME | (MODULE-NAME [:select SELECTION] [:renamer RENAMER])
+;;
+;; (use-syntax MODULE-NAME)
+
+;; TODO: Support SLIB-style `require' forms:
+;;
+;; (require 'foo)
+
+;; TODO: Bigloo `import' and maybe `extern' support.
+;;
+;; ;; /usr/share/doc/bigloo-examples/examples/Foreign/
+;; (module example
+;; (import (bis foreign2 "foreign2.scm"))
+;; ...)
+;;
+;; ;; /usr/share/doc/bigloo-examples/examples/Fork/
+;; (module sys-example
+;; (extern (include "sys/types.h")
+;; (include "wait.h")
+;; (include "unistd.h")
+;; ...))
+
+;; TODO: PLT module language syntax: (module info (lib "infotab.ss" "setup")
+
+(defconst quack-pltrequire-at-point-data-re
+ (quack-re-alt "dynamic-require"
+ (concat "require"
+ (quack-re-alt "-for-syntax"
+ ""))))
+
+(defconst quack-pltrequire-at-point-data-1-re
+ (concat quack-pltrequire-at-point-data-re
+ "\\>"))
+
+(defconst quack-pltrequire-at-point-data-2-re
+ (concat "[^\r\n]*[[(]"
+ quack-pltrequire-at-point-data-re
+ "[ \t]+\\([^\r\n]+\\)"))
+
+(defun quack-pltrequire-at-point-data-1 ()
+ (save-match-data
+ (let ((qpss (quack-parent-sexp-search quack-pltrequire-at-point-data-1-re
+ 4)))
+ (when qpss
+ (let ((child-start (nth 2 qpss)))
+ (when child-start
+ (save-excursion
+ (goto-char child-start)
+ (condition-case nil
+ ;; Note: It is normally OK to use the Elisp reader here.
+ (read (current-buffer))
+ (error nil)))))))))
+
+(defun quack-pltrequire-at-point-data-2 ()
+ (save-match-data
+ (when (thing-at-point-looking-at quack-pltrequire-at-point-data-2-re)
+ (let* ((read-start (match-beginning 2))
+ (parts-pt (- (point) read-start))
+ (parts (buffer-substring-no-properties read-start
+ (match-end 2)))
+ (parts-len (length parts))
+ (start 0)
+ (result '()))
+ (condition-case nil
+ (while (< start parts-len)
+ ;; Note: It is normally OK to use the Elisp reader here.
+ (let ((r (read-from-string parts start)))
+ (when (or (not result) (> parts-pt start))
+ (setq result (car r)))
+ (setq start (cdr r))))
+ (error nil))
+ result))))
+
+(defun quack-pltrequire-at-point-filename (&optional silent)
+ (let* ((d (or (quack-pltrequire-at-point-data-1)
+ (quack-pltrequire-at-point-data-2)))
+ (m (cond
+ ((not d) nil)
+ ((stringp d) d)
+ ((listp d)
+ (let ((f (car d)))
+ (when (symbolp f)
+ (cond ((memq f '(file lib)) d)
+ ((memq f '(all-except rename)) (nth 1 d))
+ ((memq f '(prefix prefix-all-except)) (nth 2 d)))))))))
+ (cond
+ ((stringp m) m)
+ ((listp m)
+ (let ((f (car m)))
+ (when (symbolp f)
+ (cond ((eq f 'file) (nth 1 f))
+ ((eq f 'lib)
+ (let* ((file (nth 1 m))
+ (collect (or (nth 2 m) "mzlib"))
+ (collect-dir (quack-dir-for-pltcollect collect))
+ (subs (nthcdr 3 m)))
+ (when file
+ (if collect-dir
+ (quack-expand-file-name (nconc subs (list file))
+ collect-dir)
+ (unless silent
+ (quack-warning "Cannot find collection %S" collect))
+ nil)))))))))))
+
+;; Indenting Newline:
+
+(defun quack-newline (&optional arg)
+ (interactive "*P")
+ (if (eq quack-newline-behavior 'newline)
+ (newline arg)
+ (if (eq quack-newline-behavior 'indent-newline-indent)
+ (lisp-indent-line)
+ (unless (eq quack-newline-behavior 'newline-indent)
+ (error "invalid quack-newline-behavior value: %s"
+ quack-newline-behavior)))
+ (let ((n (prefix-numeric-value arg)))
+ (when (> n 0)
+ (while (> n 0)
+ (setq n (1- n))
+ (quack-delete-horizontal-space t)
+ (newline))
+ (lisp-indent-line)))))
+
+;; Agreeing-Paren Insert:
+
+;; TODO: Make paren-matching within comments limit seaching to within comments,
+;; not skip back and try to match code. One workaround is to prefix
+;; parents/brackets in comments with backslash.
+
+(defun quack-insert-closing (prefix default-close other-open other-close)
+ (insert default-close)
+ (unless prefix
+ (let ((open-pt (condition-case nil
+ (scan-sexps (point) -1)
+ (error (beep) nil))))
+ (when open-pt
+ (let ((open-char (aref (buffer-substring-no-properties
+ open-pt (1+ open-pt))
+ 0)))
+ (when (= open-char other-open)
+ (delete-backward-char 1)
+ (insert other-close))))))
+ (when blink-paren-function (funcall blink-paren-function)))
+
+(defun quack-insert-closing-paren (&optional prefix)
+ (interactive "P")
+ (quack-insert-closing prefix ?\) ?\[ ?\]))
+
+(defun quack-insert-closing-bracket (&optional prefix)
+ (interactive "P")
+ (quack-insert-closing prefix ?\] ?\( ?\)))
+
+;; Opening-Paren Insert:
+
+(defun quack-insert-opening (prefix char)
+ (insert (if (or prefix (not quack-smart-open-paren-p)) char ?\())
+ (when blink-paren-function (funcall blink-paren-function)))
+
+(defun quack-insert-opening-paren (&optional prefix)
+ (interactive "P")
+ (quack-insert-opening prefix ?\())
+
+(defun quack-insert-opening-bracket (&optional prefix)
+ (interactive "P")
+ (quack-insert-opening prefix ?\[))
+
+;; Definition Lambda Syntax Toggling:
+
+(defconst quack-toggle-lambda-re-1
+ (concat "define\\*?"
+ (quack-re-alt "-for-syntax"
+ "-public"
+ "/override"
+ "/private"
+ "/public"
+ "")))
+
+(defconst quack-toggle-lambda-re-2
+ (let ((ws-opt "[ \t\r\n\f]*")
+ (symbol "[^][() \t\r\n\f]+")
+ (open-paren "[[(]")
+ (close-paren "[])]"))
+ (concat ws-opt
+ (quack-re-alt ; #=1
+ (concat "\\(" ; #<2 `NAME (lambda ('
+ "\\(" ; #<3 name
+ symbol
+ "\\)" ; #>3
+ ws-opt
+ open-paren
+ ws-opt
+ "lambda"
+ ws-opt
+ open-paren
+ ws-opt
+ "\\)")
+ (concat "\\(" ; #<4 `(NAME'
+ open-paren
+ ws-opt
+ "\\(" ; #<5 name
+ symbol
+ "\\)" ; #>5
+ ws-opt
+ "\\)"))
+ "\\(" ; #<6 optional close paren
+ close-paren
+ "\\)?" ; #>6
+ )))
+
+(defun quack-toggle-lambda ()
+ (interactive)
+ (save-match-data
+ (let ((found (quack-parent-sexp-search quack-toggle-lambda-re-1))
+ last-paren-marker
+ leave-point-marker)
+ (unless found
+ (error "Sorry, this does not appear to be a definition form."))
+ (unwind-protect
+ (let ((lexeme-end (nth 1 found))
+ (define-beg (nth 3 found)))
+
+ ;; Make the markers.
+ (setq last-paren-marker (make-marker))
+ (setq leave-point-marker (point-marker))
+
+ ;; Move to right after the define form keyword, and match the
+ ;; pattern of the two possible syntaxes. Error if no match.
+ (goto-char lexeme-end)
+ (unless (looking-at quack-toggle-lambda-re-2)
+ (error "Sorry, we can't grok this definition syntax."))
+
+ ;; Pattern matched, so find the closing paren of the define form.
+ (let ((pt (condition-case nil
+ (scan-sexps define-beg 1)
+ (error ; scan-error
+ nil))))
+ (if pt
+ (set-marker last-paren-marker (1- pt))
+ (quack-warning
+ "This definition form sexp is unclosed. Consider undo.")))
+
+ ;; Now act based on which syntax we saw.
+ (cond
+
+ ((match-beginning 2)
+ ;; We saw the syntax `NAME (lambda ('.
+ (let ((name (quack-match-string-no-properties 3)))
+ (when (marker-position last-paren-marker)
+ (goto-char last-paren-marker)
+ (let ((victim-beg (quack-looking-at-close-paren-backward)))
+ (unless victim-beg
+ (error "This definition form should end with `))'."))
+ (delete-region victim-beg (point))))
+ (goto-char lexeme-end)
+ (delete-region lexeme-end (match-end 2))
+ (insert " (" name (if (match-beginning 6) "" " "))))
+
+ ((match-beginning 4)
+ ;; We saw the syntax `(NAME'.
+ (let ((name (quack-match-string-no-properties 5)))
+ (when (marker-position last-paren-marker)
+ (goto-char last-paren-marker)
+ (insert ")"))
+ (goto-char lexeme-end)
+ (delete-region lexeme-end (match-end 4))
+ (insert " " name "\n")
+ (set-marker leave-point-marker (point))
+ (insert "(lambda (")
+ (set-marker-insertion-type leave-point-marker t)))
+
+ (t (quack-internal-error)))
+
+ ;; Reindent, which also takes care of font-lock updating of deleted
+ ;; and inserted text.
+ (indent-region define-beg
+ (or (marker-position last-paren-marker)
+ (max (marker-position leave-point-marker)
+ (point)))
+ nil))
+
+ ;; unwind-protect cleanup
+ (goto-char (marker-position leave-point-marker))
+ (set-marker leave-point-marker nil)))))
+
+;; Buffer Tidying:
+
+;; TODO: Maybe have an option to automatically tidy the buffer on save. Make
+;; default off. This can be slow for larger buffers on older computers,
+;; especially if font-lock is activated. It can also annoy people who
+;; have a CM system full of improperly formatted files, or who like
+;; things like formfeed characters in their files.
+
+(defun quack-delete-all-in-buffer (regexp &optional subexp)
+ (unless subexp (setq subexp 0))
+ ;; Note: This moves the point and changes the match data.
+ (goto-char (point-min))
+ (while (re-search-forward regexp nil t)
+ (goto-char (match-end subexp))
+ (delete-region (match-beginning subexp) (point))))
+
+(defun quack-tidy-buffer ()
+
+ ;; TODO: Make sure this works with odd eol conventions and the various
+ ;; codeset representations in various versions of Emacs.
+
+ ;; TODO: Maybe detect DrScheme ASCII-art "big letters" and protect them from
+ ;; reindenting.
+
+ "Tidy the formatting of the current Scheme buffer.
+
+This reindents, converts tabs to spaces, removes trailing whitespace on lines,
+removes formfeed characters, removes extraneous blank lines, and makes sure
+the buffer ends with a newline.
+
+This can conceivably corrupt multi-line string literals, but not in any way
+they wouldn't be corrupted by Usenet, various mailers, typesetting for print,
+etc.
+
+This may also result in large diffs when the tidied file is commited back to a
+version control or configuration management system. Consider making a VC or CM
+delta that consists only of changes made by `quack-tidy-buffer'."
+ (interactive)
+ (if (= (point-min) (point-max))
+ (message "Buffer is empty; no tidying necessary.")
+ (let ((marker (point-marker))
+ (fill-prefix nil))
+ (unwind-protect
+ (save-excursion
+ (save-match-data
+ (quack-activity
+ "Tidying buffer"
+
+ ;; Make sure last character is a newline.
+ (unless (string= "\n" (buffer-substring-no-properties
+ (1- (point-max))
+ (point-max)))
+ (goto-char (point-max))
+ (insert "\n"))
+
+ ;; Remove form-feed characters.
+ (quack-delete-all-in-buffer "\f")
+
+ ;; Reindent buffer (without inserting any new tabs).
+ ;; Note: This is the time-consuming pass.
+ (let ((saved-indent-tabs-mode indent-tabs-mode))
+ (unwind-protect
+ (progn (setq indent-tabs-mode nil)
+ (indent-region (point-min) (point-max) nil))
+ ;; unwind-protect cleanup
+ (setq indent-tabs-mode saved-indent-tabs-mode)))
+
+ ;; Expand any remaining tabs.
+ (untabify (point-min) (point-max))
+
+ ;; Remove trailing whitespace on each line.
+ (quack-delete-all-in-buffer "\\([ \t\r]+\\)\n" 1)
+
+ ;; Remove blank lines from top.
+ (goto-char (point-min))
+ (when (looking-at "[ \t\r\n]+")
+ (delete-region (match-beginning 0) (match-end 0)))
+
+ ;; Remove excess adjacent blank lines.
+ (quack-delete-all-in-buffer "\n\n\\(\n+\\)" 1)
+
+ ;; Remove blank lines from bottom.
+ (goto-char (point-max))
+ (when (quack-looking-at-backward
+ "\n\\(\n\\)"
+ (max (point-min) (- (point-max) 3)))
+ (delete-region (match-beginning 1) (match-end 1))))))
+
+ ;; unwind-protect cleanup
+ (goto-char (marker-position marker))
+ (set-marker marker nil)))))
+
+;; SRFIs:
+
+;; TODO: Archive local copies of SRFIs? Have to update them when modified, but
+;; without unnecessarily downloading from the master site. This is
+;; doable with wget mirroring, but not with things like "lynx -source".
+
+(defconst quack-srfi-subindex-kinds '(draft final withdrawn)
+ "List of symbols representing the three possible states of an SRFI (`draft',
+`final', and `withdrawn'), in order of increasing precedence (e.g., final
+follows draft,since a final version supercedes a draft version).")
+
+(defvar quack-srfi-completes-cache 'invalid)
+(defvar quack-srfi-menu-cache 'invalid)
+
+(defun quack-srfi-completes ()
+ (when (eq quack-srfi-completes-cache 'invalid)
+ (quack-process-srfi-subindex-files))
+ quack-srfi-completes-cache)
+
+(defun quack-srfi-menu (&optional noninteractive)
+ (when (eq quack-srfi-menu-cache 'invalid)
+ (quack-process-srfi-subindex-files noninteractive))
+ quack-srfi-menu-cache)
+
+(defun quack-srfi-master-url (path)
+ (quack-build-url quack-srfi-master-base-url path))
+
+(defun quack-srfi-subindex-master-url (kind)
+ (quack-srfi-master-url (list (quack-srfi-subindex-basename kind))))
+
+(defun quack-srfi-dir ()
+ (file-name-as-directory (expand-file-name "srfi" quack-dir)))
+
+(defun quack-srfi-subindex-file (kind)
+ (expand-file-name (quack-srfi-subindex-basename kind) (quack-srfi-dir)))
+
+(defun quack-srfi-subindex-basename (kind)
+ (format "%S-srfis.html" kind))
+
+(defun quack-invalidate-srfi-index-caches ()
+ (setq quack-srfi-completes-cache 'invalid)
+ (setq quack-srfi-menu-cache 'invalid))
+
+(defun quack-update-srfi-index ()
+ (interactive)
+ (quack-activity
+ "Updating SRFI index"
+ (quack-download-srfi-subindex-files)))
+
+(defun quack-download-srfi-subindex-files ()
+ (quack-invalidate-srfi-index-caches)
+ (mapcar (function
+ (lambda (kind)
+ (quack-activity
+ (format "Downloading %s SRFI subindex" kind)
+ (quack-web-get-to-file (quack-srfi-subindex-master-url kind)
+ (quack-srfi-subindex-file kind)))))
+ quack-srfi-subindex-kinds))
+
+(defun quack-download-srfi-subindex-files-if-missing ()
+ (let ((missing '()))
+ (mapcar (function
+ (lambda (kind)
+ (unless (file-exists-p (quack-srfi-subindex-file kind))
+ (setq missing (nconc missing (list kind))))))
+ quack-srfi-subindex-kinds)
+ (when (and missing
+ (y-or-n-p "Some cached SRFI subindexes are missing. Update? "))
+ (quack-update-srfi-index))))
+
+(defun quack-process-srfi-subindex-files (&optional noninteractive)
+ (let ((index '())
+ (completes '())
+ (menu (mapcar (function (lambda (kind) (cons kind nil)))
+ quack-srfi-subindex-kinds)))
+
+ ;; Invalidate dependent caches.
+ (quack-invalidate-srfi-index-caches)
+
+ ;; Give user a chance to download any missing cache files all at once,
+ ;; instead of prompting individually later.
+ (unless noninteractive
+ (quack-download-srfi-subindex-files-if-missing))
+
+ ;; Parse the index files, letting entries for successive states supercede.
+ (mapcar (function
+ (lambda (kind)
+ (mapcar (function
+ (lambda (new)
+ (let (old)
+ (if (setq old (assq (car new) index))
+ (setcdr old (cdr new))
+ (setq index (cons new index))))))
+ (quack-parse-srfi-subindex-file kind noninteractive))))
+ quack-srfi-subindex-kinds)
+
+ ;; Sort the parse form in reverse order, since the cache-building functions
+ ;; will reverse this.
+ (setq index (sort index (function (lambda (a b) (>= (car a) (car b))))))
+
+ ;; Build the completions and menu caches.
+ (let ((fmt (concat "%"
+ (if index
+ (number-to-string
+ (length (number-to-string (car (car index)))))
+ "")
+ "d %s")))
+ (mapcar (function
+ (lambda (n)
+ (let ((num (nth 0 n))
+ (kind (nth 1 n))
+ (title (nth 2 n)))
+ (unless kind (quack-internal-error))
+ (setq completes
+ (cons (cons (if (eq kind 'final)
+ (format "%d %s" num title)
+ (format "%d [%s] %s" num kind title))
+ num)
+ completes))
+ (let ((pair (or (assq kind menu)
+ (quack-internal-error))))
+ (setcdr pair (cons `[,(format fmt num title)
+ (quack-view-srfi ,num)]
+ (cdr pair)))))))
+ index))
+
+ ;; Finish the menu.
+ (mapcar (function (lambda (n)
+ (setcar n (cdr (assoc (car n)
+ '((draft . "Draft")
+ (final . "Final")
+ (withdrawn . "Withdrawn")))))
+ ;; Add dummy content so that XEmacs 21 will display
+ ;; the submenu label.
+ (unless (cdr n)
+ (setcdr n (cons "(None)" nil)))))
+ menu)
+ (setq menu `(["Update SRFI Index" quack-update-srfi-index]
+ "---"
+ ,@menu
+ ["Other SRFI..." quack-view-srfi]))
+
+ ;; Store the results.
+ (setq quack-srfi-menu-cache menu)
+ (setq quack-srfi-completes-cache completes)))
+
+(defun quack-parse-srfi-subindex-file (kind &optional noninteractive)
+ (save-excursion
+ (let ((file (quack-srfi-subindex-file kind)))
+ (unless (file-exists-p file)
+ (error "No SRFI index file %S" file))
+ (let* ((buf (get-file-buffer file))
+ (already-visiting-p buf))
+ (unless buf
+ (setq buf (find-file-noselect file t t)))
+ (unwind-protect
+ (progn (set-buffer buf)
+ (quack-parse-srfi-subindex-buffer kind))
+ ;; unwind-protect-cleanup
+ (unless already-visiting-p
+ (kill-buffer buf)))))))
+
+(defconst quack-parse-srfi-index-buffer-re-1
+ (concat
+ "<LI><A HREF=\"?srfi-[0-9]+/?\"?>SRFI[ \t]+"
+ "\\([0-9]+\\)" ; #=1 srfi number
+ "</A>:?[ \t]*"
+ "\\(" ; #<2 srfi title
+ ; #=3
+ (quack-re-alt "[^\r\n<>]" "</?[a-z]+>")
+ "+"
+ "\\)"))
+
+(defun quack-parse-srfi-subindex-buffer (kind)
+ (save-excursion
+ (let ((case-fold-search t)
+ (alist '()))
+ (goto-char (point-min))
+ (while (re-search-forward quack-parse-srfi-index-buffer-re-1 nil t)
+ (let ((number (string-to-number (quack-match-string-no-properties 1)))
+ (title (quack-without-side-whitespace
+ (quack-strip-limited-html-tags
+ (quack-match-string-no-properties 2)))))
+ (setq alist (cons
+
+ ;;(cons number
+ ;; (if (and kind (not (eq kind 'final)))
+ ;; (format "[%s] %s" kind title)
+ ;; title))
+ (list number kind title)
+
+ alist))))
+ (setq alist (reverse alist)))))
+
+(defun quack-srfi-num-url (num)
+ (quack-srfi-master-url (list (format "srfi-%d" num)
+ (format "srfi-%d.html" num))))
+
+(defconst quack-srfi-num-at-point-re-1
+ "srfi[-: \t]*\\([0-9]+\\)")
+
+(defconst quack-srfi-num-at-point-re-2
+ ;; Note: We can't have "[^\r\n]*" as a prefix, since it's too slow.
+ (concat quack-srfi-num-at-point-re-1 "[^\r\n]*"))
+
+(defun quack-srfi-num-at-point ()
+ ;; TODO: Make this get the nearest SRFI number in all cases.
+ (save-match-data
+ (let ((case-fold-search t))
+ (cond ((thing-at-point-looking-at quack-srfi-num-at-point-re-1)
+ (string-to-number (quack-match-string-no-properties 1)))
+ ((thing-at-point-looking-at "[0-9]+")
+ (string-to-number (quack-match-string-no-properties 0)))
+ ((thing-at-point-looking-at quack-srfi-num-at-point-re-2)
+ (string-to-number (quack-match-string-no-properties 1)))
+ ((let ((str (quack-line-at-point)))
+ (when (string-match quack-srfi-num-at-point-re-1 str)
+ (string-to-number
+ (quack-match-string-no-properties 1 str)))))))))
+
+(defun quack-view-srfi (num)
+ (interactive (list (quack-srfi-num-prompt "View SRFI number")))
+ (when num
+ (unless (and (integerp num) (>= num 0))
+ (error "Not a valid SRFI number: %S" num))
+ (quack-browse-url (quack-srfi-num-url num))))
+
+(defun quack-srfi-num-prompt (prompt)
+ (let* ((completes (quack-srfi-completes))
+ (default (quack-srfi-num-at-point))
+ (input (quack-without-side-whitespace
+ (completing-read
+ (if default
+ (format "%s (default %d): " prompt default)
+ (concat prompt ": "))
+ completes)))
+ v)
+ (cond ((or (not input) (string= "" input)) default)
+ ((setq v (assoc input completes)) (cdr v))
+ ((and (setq v (condition-case nil
+ (string-to-number input)
+ (error nil)))
+ (integerp v)
+ (>= v 0))
+ v)
+ (t (error "Invalid SRFI number: %s" input)))))
+
+;; Doc Keyword Value Object:
+
+(defmacro quack-kw-get-syntax (o) `(aref ,o 0))
+(defmacro quack-kw-get-file (o) `(aref ,o 1))
+(defmacro quack-kw-get-fragment (o) `(aref ,o 2))
+
+(defmacro quack-kw-set-syntax (o v) `(aset ,o 0 ,v))
+(defmacro quack-kw-set-file (o v) `(aset ,o 1 ,v))
+(defmacro quack-kw-set-fragment (o v) `(aset ,o 2 ,v))
+
+;; Documentation Object:
+
+;; TODO: Rework these document representations once we know the different kinds
+;; of documents with which we'll be dealing.
+
+(defmacro quack-doc-get-type (o) `(aref ,o 0))
+(defmacro quack-doc-get-sym (o) `(aref ,o 1))
+(defmacro quack-doc-get-title (o) `(aref ,o 2))
+(defmacro quack-doc-get-loc (o) `(aref ,o 3))
+(defmacro quack-doc-get-kw-p (o) `(aref ,o 4))
+(defmacro quack-doc-get-start-url (o) `(aref ,o 5))
+(defmacro quack-doc-get-kw-base-url (o) `(aref ,o 6))
+(defmacro quack-doc-get-kw-file (o) `(aref ,o 7))
+(defmacro quack-doc-get-kw-hashtable (o) `(aref ,o 8))
+
+(defmacro quack-doc-set-type (o v) `(aset ,o 0 ,v))
+(defmacro quack-doc-set-sym (o v) `(aset ,o 1 ,v))
+(defmacro quack-doc-set-title (o v) `(aset ,o 2 ,v))
+(defmacro quack-doc-set-loc (o v) `(aset ,o 3 ,v))
+(defmacro quack-doc-set-kw-p (o v) `(aset ,o 4 ,v))
+(defmacro quack-doc-set-start-url (o v) `(aset ,o 5 ,v))
+(defmacro quack-doc-set-kw-base-url (o v) `(aset ,o 6 ,v))
+(defmacro quack-doc-set-kw-file (o v) `(aset ,o 7 ,v))
+(defmacro quack-doc-set-kw-hashtable (o v) `(aset ,o 8 ,v))
+
+(defun quack-manual-to-doc (manual)
+ ;; Accepts a user's manual preference object of the list form:
+ ;;
+ ;; (SYM TITLE LOC KW-P)
+ ;;
+ ;; and creates a manual doc object of the vector form:
+ ;;
+ ;; [manual SYM TITLE LOC KW-P START-URL KW-BASE-URL KW-FILE KW-P
+ ;; KEYWORDS]
+ ;;
+ ;; KEYWORDS is not populated here -- keywords importing for a manual happens
+ ;; the first time keyword searching is done for the manual."
+ (let ((sym (nth 0 manual))
+ (title (nth 1 manual))
+ (loc (nth 2 manual))
+ (kw-p (nth 3 manual))
+ (start-url nil)
+ (kw-file nil)
+ (kw-base nil))
+ (cond
+ ;; If the location is a string, then handle manual as simple URL.
+ ((stringp loc)
+ (setq start-url loc)
+ (when kw-p
+ (quack-warning "Quack can only use keywords for PLT manuals.")
+ (setq kw-p nil)))
+ ;; If the location is a symbol, handle manual as special.
+ ((symbolp loc)
+ (cond
+ ;; If the location is symbol `plt', handle manual as PLT bundled.
+ ((eq loc 'plt)
+ (let* ((plt-name (let ((s (symbol-name sym)))
+ (if (string-match "\\`plt-\\(.+\\)\\'" s)
+ (match-string 1 s)
+ s)))
+ (web-base (concat
+ "http://download.plt-scheme.org/doc/"
+ plt-name
+ "/"))
+ (index-name "index.htm")
+ (col-dirs quack-pltcollect-dirs))
+ ;; Search from the collection directories for keywords and index
+ ;; files. Note that we currently look for keywords files even if
+ ;; `kw-p' is false since we want to allow the user to dynamically
+ ;; enable and disable keywords searching for a particular manual
+ ;; without us having to change `quack-docs'.
+ (while (and col-dirs (not (and kw-file kw-base start-url)))
+ (let ((dir (expand-file-name plt-name
+ (expand-file-name "doc"
+ (car col-dirs)))))
+ (setq col-dirs (cdr col-dirs))
+ (when (file-directory-p dir)
+ (let* ((k-f (expand-file-name "keywords" dir))
+ (i-f (expand-file-name index-name dir))
+ (i-r (file-readable-p i-f)))
+ (if (file-readable-p k-f)
+ ;; Keywords file.
+ (if i-r
+ ;; Keywords file and index file. So, unless we
+ ;; already found a keywords base URL, set everything
+ ;; based on this directory. Note that we override
+ ;; any existing start URL because we prefer to use
+ ;; the same manual version for both keywords and
+ ;; non-keywords access.
+ (unless kw-base
+ (setq kw-file k-f)
+ (setq kw-base (quack-file-url dir nil))
+ (setq start-url (quack-file-url dir index-name)))
+ ;; Keywords file, but no index file. So, unless we
+ ;; already have a keywords file, set it to this one.
+ (unless kw-file
+ (setq kw-file k-f)))
+ ;; No keywords file. So, if there is an index file, and we
+ ;; don't already have one, then use this one.
+ (when (and i-r (not start-url))
+ (setq start-url (quack-file-url dir index-name))))))))
+ ;; If we didn't find a start URL, use the Web one.
+ (unless start-url
+ (setq start-url (concat web-base index-name)))
+ ;; Do we have a keywords file?
+ (if kw-file
+ ;; We have a keywords file, so set the keywords base to the Web
+ ;; if needed and desired. Note that we never use the keywords
+ ;; file from one directory with the HTML files from a different
+ ;; directory, on the assumption that a local copy of HTML missing
+ ;; a keywords file is suspect, and that the Web version is
+ ;; therefore preferable.
+ (when (or (eq quack-local-keywords-for-remote-manuals-p 'always)
+ (and (not kw-base)
+ quack-local-keywords-for-remote-manuals-p))
+ (setq kw-base web-base))
+ ;; We don't have a keywords file, so warn if the user wanted
+ ;; keywords for this manual.
+ (when kw-p
+ (quack-warning "Could not find keywords file for manual %S."
+ plt-name)))))
+ ;; The location is an unrecognized symbol, so just barf.
+ (t (quack-internal-error))))
+ ;; The location is something other than a string or symbol, so just barf.
+ (t (quack-internal-error)))
+ ;; We've populated all the variables for the location type, so return the
+ ;; representation.
+ (vector 'manual sym title loc kw-p start-url kw-base kw-file nil)))
+
+(defun quack-doc-keyword-lookup (doc keyword)
+ (let ((ht (or (quack-doc-get-kw-hashtable doc)
+ (progn (quack-doc-import-keywords doc)
+ (quack-doc-get-kw-hashtable doc)))))
+ (if ht
+ (quack-gethash keyword ht nil)
+ (quack-warning "No keywords for document \"%S\"."
+ (quack-doc-get-sym doc))
+ nil)))
+
+(defun quack-doc-import-keywords (doc)
+ (if (eq (quack-doc-get-loc doc) 'plt)
+ (quack-doc-import-plt-manual-keywords doc)
+ (quack-internal-error)))
+
+(defun quack-doc-import-plt-manual-keywords (doc)
+ ;; Reads in the predetermined keywords file for PLT manual `doc' object,
+ ;; populating the `kw-hashtable' field of the `doc' object. The format of
+ ;; each entry in the PLT keywords file is a list of 5 strings:
+ ;;
+ ;; (KEYWORD SYNTAX FILE FRAGMENT SECTION)
+ ;;
+ ;; The hashtable is keyed on the KEYWORD string, for which the value is
+ ;; usually a vector:
+ ;;
+ ;; [SYNTAX FILE-CONST FRAGMENT]
+ ;;
+ ;; where FILE-CONST is the FILE string registered with the `quack-strconst'
+ ;; to save memory on redundant strings.
+ ;;
+ ;; When more there is more than one entry for a given keyword, then the value
+ ;; of the hashtable entry for that keyword is a list of vectors, in the order
+ ;; in which they were derived from the original keywords file.
+ ;;
+ ;; These duplicate values may be duplicated or conflicting, as in:
+ ;;
+ ;; (["(regexp-match pattern input-port [start-k end-k output-port])"
+ ;; "mzscheme-Z-H-10.html" "%_kw_definitionregexp-match"]
+ ;; ["(regexp-match pattern string [start-k end-k output-port])"
+ ;; "mzscheme-Z-H-10.html" "%_kw_definitionregexp-match"])
+ ;;
+ ;; No attempt is made here to weed out any duplicate/conflicting entries --
+ ;; that behavior left up to the code that accesses the hashtable. For the
+ ;; example above, a command to display the syntax for the keyword would need
+ ;; to display both values. However, a command to view the documentation for
+ ;; the keyword would need only to display one Web page without querying the
+ ;; user, since both entries above point to the same page and fragment.
+ (quack-activity
+ (format "Importing keywords for manual %S" (quack-doc-get-sym doc))
+ (let (sexp)
+ (garbage-collect)
+ (condition-case err
+ (setq sexp (quack-read-sexp-file
+ (or (quack-doc-get-kw-file doc)
+ (quack-warning "Manual %S has no keywords file."
+ (quack-doc-get-sym doc)))))
+ (error (quack-warning "Problem importing keywords for manual %S: %s"
+ (quack-doc-get-sym doc) err)))
+ (when sexp
+ (garbage-collect)
+ (let ((ht (quack-make-hash-table :test 'equal
+ :size (length sexp)
+ :rehash-threshold 1.0)))
+ ;; Note: We make the hashtable equal to the length of the read list of
+ ;; keyword forms so that it will be at least large enough for all the
+ ;; keywords without being excessively overlarge, and without having to
+ ;; do resizes or a counting pass or intermediate representation. The
+ ;; hashtable will be a little larger than necessary when there are
+ ;; multiple keyword forms for the same keyword. In a test with
+ ;; MzScheme 200.2, the hashtable used/size for "mzscheme" manual was
+ ;; 489/502; for "mzlib", 245/257.
+ (quack-doc-set-kw-hashtable doc ht)
+ (mapcar (function
+ (lambda (raw-entry)
+ (let* ((kw (nth 0 raw-entry))
+ (new (vector (nth 1 raw-entry)
+ (quack-strconst (nth 2 raw-entry))
+ (nth 3 raw-entry)))
+ (old (quack-gethash kw ht nil)))
+ (quack-puthash
+ kw
+ (cond ((not old) new)
+ ((vectorp old) (list old new))
+ ((listp old) (nconc old (list new))))
+ ht))))
+ sexp))))))
+
+(defun quack-read-sexp-file (filename)
+ (save-excursion
+ (let* ((buf (generate-new-buffer "*quack-read-sexp-file*")))
+ (set-buffer buf)
+ (unwind-protect
+ (progn (insert-file-contents-literally filename)
+ (goto-char (point-min))
+ (read buf))
+ ;; unwind-protect cleanup
+ (kill-buffer buf)))))
+
+;; Documentation Database:
+
+(defvar quack-docs 'invalid)
+
+(defun quack-docs ()
+ (when (eq quack-docs 'invalid)
+ (quack-docs-build))
+ quack-docs)
+
+(defun quack-docs-build ()
+ (quack-activity
+ "Building Quack docs database"
+ (quack-invalidate-manuals-caches)
+ (setq quack-docs (mapcar 'quack-manual-to-doc quack-manuals))))
+
+(defun quack-docs-manual-lookup (sym)
+ (let ((docs (quack-docs))
+ (found nil))
+ (while (and docs (not found))
+ (let ((doc (car docs)))
+ (setq docs (cdr docs))
+ (when (eq (quack-doc-get-sym doc) sym)
+ (setq found doc))))
+ found))
+
+(defun quack-docs-manual-keyword-lookup (keyword)
+ (let ((results '()))
+ (mapcar (function
+ (lambda (doc)
+ (cond
+ ((not (quack-doc-get-kw-p doc)) nil)
+ ((not (quack-doc-get-kw-base-url doc))
+ (quack-warning "Manual %S has no HTML."
+ (quack-doc-get-sym doc)))
+ (t (let ((match (quack-doc-keyword-lookup doc keyword)))
+ (cond
+ ((not match) nil)
+ ((vectorp match)
+ (setq results (cons (cons doc match) results)))
+ ((listp match)
+ (mapcar (function
+ (lambda (m)
+ (setq results (cons (cons doc m) results))))
+ match))
+ (t (quack-internal-error))))))))
+ (quack-docs))
+ (reverse results)))
+
+;; Keyword Lookup Match Object:
+
+(defmacro quack-kwmatch-get-doc (o) `(car ,o))
+(defmacro quack-kwmatch-get-kw (o) `(cdr ,o))
+
+(defun quack-kwmatch-url (kwmatch)
+ (let ((doc (car kwmatch))
+ (kw (cdr kwmatch)))
+ (concat (quack-doc-get-kw-base-url doc)
+ (quack-quote-url-substring (quack-kw-get-file kw))
+ "#"
+ (quack-quote-url-substring (quack-kw-get-fragment kw) t))))
+
+;; Manual Viewing:
+
+(defun quack-view-manual (&optional sym)
+ "View a manual."
+ (interactive
+ (list
+ (let* ((completes (or (quack-manuals-completes)
+ (error
+ "Sorry, variable \"quack-manuals\" is empty.")))
+ (default "R5RS")
+ (input (let ((completion-ignore-case t))
+ (completing-read
+ (format "Quack Manual (default %S): " default)
+ completes nil t nil nil default))))
+ (cdr (or (assoc input completes)
+ (error "No manual %S." input))))))
+ (quack-activity
+ (format "Viewing manual \"%S\"" sym)
+ (quack-browse-url (or (quack-doc-get-start-url
+ (or (quack-docs-manual-lookup sym)
+ (error "Manual \"%S\" not found." sym)))
+ (error "Don't know a URL for manual \"%S\"." sym)))))
+
+(defvar quack-manuals-menu-cache 'invalid)
+(defvar quack-manuals-completes-cache 'invalid)
+
+(defun quack-invalidate-manuals-caches ()
+ (setq quack-docs 'invalid)
+ (setq quack-manuals-completes-cache 'invalid)
+ (setq quack-manuals-menu-cache 'invalid))
+
+;;(quack-invalidate-manuals-caches)
+
+;; This version maps completion strings to URLs.
+;; (defun quack-manuals-completes ()
+;; (when (eq quack-manuals-completes-cache 'invalid)
+;; (let ((completes '()))
+;; (mapcar (function
+;; (lambda (doc)
+;; (let ((sym (quack-doc-get-sym doc))
+;; (url (quack-doc-get-start-url doc)))
+;; (setq completes
+;; (cons (cons (quack-doc-get-title doc) url)
+;; (cons (cons (symbol-name sym) url)
+;; completes))))))
+;; (quack-docs))
+;; (setq quack-manuals-completes-cache (reverse completes))))
+;; quack-manuals-completes-cache)
+
+(defun quack-manuals-completes ()
+ (when (eq quack-manuals-completes-cache 'invalid)
+ (let ((completes '()))
+ (mapcar (function
+ (lambda (doc)
+ (let ((sym (quack-doc-get-sym doc))
+ ;;(url (quack-doc-get-start-url doc))
+ )
+ (setq completes
+ (cons (cons (quack-doc-get-title doc) sym)
+ ;;(cons (cons (symbol-name sym) sym)
+ completes
+ ;;)
+ )))))
+ (quack-docs))
+ (setq quack-manuals-completes-cache (reverse completes))))
+ quack-manuals-completes-cache)
+
+(defun quack-manuals-menu ()
+ (when (eq quack-manuals-menu-cache 'invalid)
+ (setq quack-manuals-menu-cache
+ (mapcar (function
+ (lambda (manual)
+ (let ((sym (nth 0 manual))
+ (title (nth 1 manual)))
+ `[,title (quack-view-manual (quote ,sym))])))
+ quack-manuals)))
+ quack-manuals-menu-cache)
+
+(defun quack-manuals-webjump-sites ()
+ "Returns `webjump' entries for manuals in `quack-manuals'.
+
+Can be used in your `~/.emacs' file something like this:
+
+ (require 'quack)
+ (require 'webjump)
+ (require 'webjump-plus)
+ (setq webjump-sites
+ (append my-own-manually-maintained-webjump-sites
+ (quack-manuals-webjump-sites)
+ webjump-plus-sites
+ webjump-sample-sites))"
+ ;; TODO: Note what they should do if they are adding to plt collectsion dirs
+ ;; via custom settings but quack-manuals-webjump-sites is getting
+ ;; called before then.
+ (let ((result '())
+ (quack-quiet-warnings-p t))
+ (mapcar (function
+ (lambda (doc)
+ (let ((url (quack-doc-get-start-url doc)))
+ (when url
+ (setq result (cons (cons (quack-doc-get-title doc) url)
+ result))))))
+ (quack-docs))
+ result))
+
+;; Keyword Docs Viewing:
+
+;; TODO: Add doc lookup in PLT "doc.txt" files. A little tricky. Maybe make
+;; sure doc.txt is a long-term format first.
+
+(defun quack-view-keyword-docs (keyword)
+ ;; TODO: Don't prompt if all choices would result in the same URL.
+ (interactive (list (quack-prompt-for-keyword "View docs for keyword")))
+ (when (and keyword (stringp keyword) (not (string= keyword "")))
+ (let ((matches (quack-docs-manual-keyword-lookup keyword)))
+ (if (not matches)
+ (message "Sorry, no documentation found for keyword %S." keyword)
+ (quack-browse-url
+ (quack-kwmatch-url
+ (if (cdr matches)
+ (quack-prompt-for-kwmatch-choice "Which" matches)
+ (car matches))))))))
+
+(defun quack-keyword-at-point ()
+ ;; TODO: Make sure this reads all Scheme symbols -- it may currently only
+ ;; read valid Elisp symbols.
+ (let ((bounds (bounds-of-thing-at-point 'symbol)))
+ ;; In some cases (point at beginning of empty buffer?), `bounds' will be
+ ;; the bounds of an empty string, so check this.
+ (when bounds
+ (let ((beg (car bounds))
+ (end (cdr bounds)))
+ (when (/= beg end)
+ (buffer-substring-no-properties beg end))))))
+
+(defun quack-prompt-for-keyword (prompt)
+ (let* ((default (quack-keyword-at-point))
+ (history (list default)))
+ (read-string (if default
+ (format "%s (default %S): " prompt default)
+ (concat prompt ": "))
+ nil
+ ;; Note: Gratuitous reference to `history' eliminates warning
+ ;; from XEmacs 21 byte-compiler.
+ (if (and default history) 'history nil)
+ default)))
+
+(defun quack-prompt-for-kwmatch-choice (prompt kwmatch-list)
+ (let ((completes '()))
+ ;; Build the completion alist, ensure each key is unique.
+ (mapcar
+ (function
+ (lambda (kwmatch)
+ (let* ((kw (quack-kwmatch-get-kw kwmatch))
+ (orig-name (or (quack-kw-get-syntax kw)
+ (progn (quack-warning "No keyword syntax: %s"
+ kw)
+ "???")))
+ (name orig-name)
+ (name-tries 1))
+ ;; Ensure the name is unique within the completion list thus far.
+ (while (assoc name completes)
+ (setq name-tries (1+ name-tries))
+ (setq name (format "%s #%d" orig-name name-tries)))
+ ;; Prepend to the completion list (we'll reverse the list later).
+ (setq completes (cons (cons name kwmatch) completes)))))
+ kwmatch-list)
+ (setq completes (reverse completes))
+ ;; Prompt user and return selection.
+ (let* ((default (car (car completes)))
+ (read (let ((completion-ignore-case t))
+ (completing-read
+ (format "%s (default %S): " prompt default)
+ completes nil t nil nil default))))
+ (cdr (assoc read completes)))))
+
+;; Inferior Process:
+
+(defvar quack-run-scheme-prompt-history '())
+
+(defun quack-remember-program-maybe (program)
+ (when (and quack-remember-new-programs-p
+ (not (member program quack-programs)))
+ (quack-option-set 'quack-programs (cons program quack-programs) t)
+ (message "Remembering program %S." program)))
+
+(defun quack-run-scheme-prompt ()
+ (let* ((last (car quack-run-scheme-prompt-history))
+ (default (or (and quack-run-scheme-prompt-defaults-to-last-p
+ last)
+ quack-default-program
+ scheme-program-name
+ last
+ "mzscheme"))
+ (program (let ((minibuffer-allow-text-properties nil))
+ (completing-read
+ (concat "Run Scheme"
+ (if default
+ (format " (default %S)" default)
+ "")
+ ": ")
+ (quack-run-scheme-prompt-completion-collection)
+ nil nil nil
+ 'quack-run-scheme-prompt-history
+ default))))
+ (quack-remember-program-maybe program)
+ program))
+
+(defun quack-run-scheme-prompt-completion-collection ()
+ (let ((program-list quack-programs))
+ (mapcar (function (lambda (program)
+ (and program
+ (not (member program program-list))
+ (setq program-list (cons program program-list)))))
+ (list quack-default-program
+ scheme-program-name))
+ (mapcar (function (lambda (program) (cons program nil)))
+ program-list)))
+
+(defadvice run-scheme (around quack-ad-run first nil activate)
+ "Adds prompting for which Scheme interpreter program to run."
+ ;; We don't want to prompt if there's already a Scheme running, but it's
+ ;; possible for process to die between the comint check in `interactive' form
+ ;; of this advice and the comint check in the `run-scheme' function. We
+ ;; should override `run-scheme' altogether, but for now let's only call the
+ ;; original in the case that we do not detect a running Scheme.
+ (interactive (list (cond ((comint-check-proc "*scheme*") nil)
+ ((or current-prefix-arg
+ quack-run-scheme-always-prompts-p)
+ (quack-run-scheme-prompt))
+ (t quack-default-program))))
+ (if cmd
+ ;; We will assume there is no running Scheme, so... Since `run-scheme'
+ ;; calls `pop-to-buffer' rather than `switch-to-scheme', our options for
+ ;; Scheme process window management, such as putting the process buffer
+ ;; window in its own frame, do not take effect when the process buffer is
+ ;; displayed by `run-scheme'. So, unless we are using the `cmuscheme'
+ ;; window management behavior, we attempt to undo whatever window changes
+ ;; and buffer changes `run-scheme' makes, then just call
+ ;; `switch-to-scheme'. (This code will be revisited once we decide how
+ ;; to handle multiple Schemes, if not before then.)
+ (let ((buf (current-buffer))
+ (wg (current-window-configuration)))
+ ad-do-it
+ (unless (or (not quack-switch-to-scheme-method)
+ (eq quack-switch-to-scheme-method 'cmuscheme))
+ (set-window-configuration wg)
+ (set-buffer buf)
+ (switch-to-scheme t))
+ (message "Started Scheme: %s" scheme-program-name))
+ ;; There is a running Scheme, so don't call the `run-scheme' function at
+ ;; all -- just call `switch-to-scheme' or duplicate the `cmuscheme'
+ ;; package's `pop-to-buffer' behavior.
+ (if (or (not quack-switch-to-scheme-method)
+ (eq quack-switch-to-scheme-method 'cmuscheme))
+ (pop-to-buffer "*scheme*")
+ (switch-to-scheme t))
+ (message "Switched to running Scheme: %s" scheme-program-name)))
+
+(defadvice scheme-interactively-start-process (around
+ quack-ad-sisp
+ first
+ (&optional cmd)
+ activate)
+ ;; (save-window-excursion
+ (call-interactively 'run-scheme)
+ ;; )
+ )
+
+(defadvice scheme-proc (around quack-ad-scheme-proc first nil activate)
+ (condition-case nil
+ ad-do-it
+ (error (message "Oops, we must start a Scheme process!")
+ (call-interactively 'run-scheme)
+ (setq ad-return-value (scheme-proc)))))
+
+;; Switch-to-Scheme:
+
+(defun quack-force-frame-switch-to-window (win)
+ (let ((frame (window-frame win)))
+ (unless (eq frame (selected-frame))
+ (and window-system
+ quack-warp-pointer-to-frame-p
+ (set-mouse-position frame 0 0))
+ (select-frame frame))
+ (select-window win)))
+
+(defadvice switch-to-scheme (before quack-ad-switch last nil activate)
+ "Adds support for the `quack-switch-to-scheme-method' option."
+ ;; This can be done as before-advice since the `pop-to-buffer' that
+ ;; `switch-to-scheme' is using appears to always be a no-op when the target
+ ;; buffer is already the current buffer.
+ (require 'cmuscheme)
+ ;; The `eval' below is to avoid problems with the byte-compiler and advising.
+ ;; It doesn't seem to like: (and (boundp 'SYM) SYM)
+ (let ((repl-buf (eval '(and (boundp 'scheme-buffer)
+ scheme-buffer
+ (get-buffer scheme-buffer)))))
+ (cond ((not repl-buf)
+ (error (concat "No process current buffer."
+ " Set `scheme-buffer' or execute `run-scheme'")))
+
+ ((or (not quack-switch-to-scheme-method)
+ (eq quack-switch-to-scheme-method 'cmuscheme))
+ nil)
+
+ ((eq (current-buffer) repl-buf) nil)
+
+ ((eq quack-switch-to-scheme-method 'other-window)
+ (switch-to-buffer-other-window repl-buf))
+
+ ;; The following code may be revived if anyone reports problems with
+ ;; the use of `special-display-popup-frame'.
+ ;;
+ ;; ((eq quack-switch-to-scheme-method 'own-frame)
+ ;; (let ((pop-up-frames t)
+ ;; (same-window-buffer-names nil)
+ ;; (same-window-regexps nil)
+ ;; (special-display-buffer-names nil)
+ ;; (special-display-regexps nil))
+ ;; (switch-to-buffer (pop-to-buffer repl-buf))))
+
+ ((eq quack-switch-to-scheme-method 'own-frame)
+ (quack-force-frame-switch-to-window
+ (special-display-popup-frame repl-buf)))
+
+ (t (error "Invalid quack-switch-to-scheme-method: %S"
+ quack-switch-to-scheme-method)))))
+
+;; Customize:
+
+(defun quack-customize ()
+ "Customize the Quack package."
+ (interactive)
+ (customize-group 'quack))
+
+;; Auto Modes:
+
+(defun quack-add-auto-mode-alist (alist)
+ (setq auto-mode-alist
+ (append alist
+ (let ((retained '()))
+ (mapcar (function (lambda (pair)
+ (unless (assoc (car pair) alist)
+ (setq retained (cons pair retained)))))
+ auto-mode-alist)
+ (reverse retained)))))
+
+(quack-add-auto-mode-alist '(("\\.ccl\\'" . scheme-mode)
+ ("\\.sch\\'" . scheme-mode)
+ ("\\.scm\\'" . scheme-mode)
+ ("\\.ss\\'" . scheme-mode)
+ ("\\.stk\\'" . scheme-mode)
+ ("\\.stklos\\'" . scheme-mode)
+ ;;
+ ("/\\.mzschemerc\\'" . scheme-mode)
+ ;; Non-Scheme:
+ ("\\.plt\\'" . quack-pltfile-mode)))
+
+;; Syntax Table:
+
+(defmacro quack-str-syntax (str)
+ `(,(if (and quack-gnuemacs-p (>= emacs-major-version 21))
+ 'string-to-syntax
+ 'quack-kludged-string-to-syntax)
+ ,str))
+
+(defun quack-kludged-string-to-syntax (str)
+ (let* ((str-len (length str))
+ (code (aref str 0))
+ (matches (if (> str-len 1) (aref str 1)))
+ (result (cond ((= code 32) 0)
+ ((= code ?_) 3)
+ (t (quack-internal-error))))
+ (i 2))
+ (while (< i str-len)
+ (let ((c (aref str i)))
+ (setq i (1+ i))
+ (setq result (logior result
+ (lsh 1 (cond ((= c ?1) 16)
+ ((= c ?2) 17)
+ ((= c ?3) 18)
+ ((= c ?4) 19)
+ ((= c ?p) 20)
+ ((= c ?b) 21)
+ ((= c ?n) 21)
+ (t (quack-internal-error))))))))
+ (cons result (if (= matches 32) nil matches))))
+
+;; Note: We are assuming that it is better to endeavor to fontify all "#|"
+;; block comments as nestable rather than as unnestable, regardless of
+;; whether or not a user's target Scheme dialect supports nested.
+
+(defconst quack-pound-syntax-string (if quack-gnuemacs-p "_ p14bn" "_ p14b"))
+;; (defconst quack-bar-syntax-string (if quack-gnuemacs-p " 23bn" " 23b"))
+(defconst quack-bar-syntax-string (if quack-gnuemacs-p "_ 23bn" "_ 23b"))
+
+(defconst quack-pound-syntax (quack-str-syntax quack-pound-syntax-string))
+(defconst quack-bar-syntax (quack-str-syntax quack-bar-syntax-string))
+
+(modify-syntax-entry ?# quack-pound-syntax-string scheme-mode-syntax-table)
+(modify-syntax-entry ?| quack-bar-syntax-string scheme-mode-syntax-table)
+
+;; Note: Unclear why, but `scheme.el' in GNU Emacs 21.2 is doing
+;; `(set-syntax-table scheme-mode-syntax-table)' in whatever buffer is
+;; active at the time the Elisp package is loaded.
+
+;; Indent Properties:
+
+(put 'begin0 'scheme-indent-function 1)
+(put 'c-declare 'scheme-indent-function 0)
+(put 'c-lambda 'scheme-indent-function 2)
+(put 'case-lambda 'scheme-indent-function 0)
+(put 'catch 'scheme-indent-function 1)
+(put 'chicken-setup 'scheme-indent-function 1)
+(put 'class 'scheme-indent-function 'defun)
+(put 'class* 'scheme-indent-function 'defun)
+(put 'compound-unit/sig 'scheme-indent-function 0)
+(put 'dynamic-wind 'scheme-indent-function 0)
+(put 'for/fold 'scheme-indent-function 2)
+(put 'instantiate 'scheme-indent-function 2)
+(put 'interface 'scheme-indent-function 1)
+(put 'let*-values 'scheme-indent-function 1)
+(put 'let+ 'scheme-indent-function 1)
+(put 'let-values 'scheme-indent-function 1)
+(put 'let/ec 'scheme-indent-function 1)
+(put 'mixin 'scheme-indent-function 2)
+(put 'module 'scheme-indent-function 'defun)
+(put 'opt-lambda 'scheme-indent-function 1)
+(put 'parameterize 'scheme-indent-function 1)
+(put 'quasisyntax/loc 'scheme-indent-function 1)
+(put 'receive 'scheme-indent-function 2)
+(put 'send* 'scheme-indent-function 1)
+(put 'sigaction 'scheme-indent-function 1)
+(put 'syntax-case 'scheme-indent-function 2)
+(put 'syntax/loc 'scheme-indent-function 1)
+(put 'unit 'scheme-indent-function 'defun)
+(put 'unit/sig 'scheme-indent-function 2)
+(put 'unless 'scheme-indent-function 1)
+(put 'when 'scheme-indent-function 1)
+(put 'while 'scheme-indent-function 1)
+(put 'with-handlers 'scheme-indent-function 1)
+(put 'with-method 'scheme-indent-function 1)
+(put 'with-syntax 'scheme-indent-function 1)
+
+;; Keymaps:
+
+(defvar quack-scheme-mode-keymap nil)
+
+(setq quack-scheme-mode-keymap (make-sparse-keymap))
+
+;; TODO: Maybe have an option to also map the Ctrl variants of each of these
+;; keys to their respective bindings. As Eli pointed out, `C-c C-q C-x'
+;; is arguably easier to type than `C-c C-q x'. Actually, though, I
+;; don't like the `C-c C-q' prefix at all -- it signifies everything that
+;; is wrong with traditional modifier-happy Emacs keybindings. Maybe we
+;; should encourage users to set the prefix to some other key, like an
+;; unmodified function key.
+
+(define-key quack-scheme-mode-keymap "f" 'quack-find-file)
+(define-key quack-scheme-mode-keymap "k" 'quack-view-keyword-docs)
+(define-key quack-scheme-mode-keymap "m" 'quack-view-manual)
+(define-key quack-scheme-mode-keymap "r" 'run-scheme)
+(define-key quack-scheme-mode-keymap "s" 'quack-view-srfi)
+(define-key quack-scheme-mode-keymap "l" 'quack-toggle-lambda)
+(define-key quack-scheme-mode-keymap "t" 'quack-tidy-buffer)
+
+;; Menus:
+
+(defmacro quack-bool-menuitem (title var &rest rest)
+ (unless (stringp title) (quack-internal-error))
+ (unless (symbolp var) (quack-internal-error))
+ `[,title (quack-option-toggle (quote ,var)) :style toggle :selected ,var
+ ,@rest])
+
+(defmacro quack-radio-menuitems (var alist)
+ (unless (symbolp var) (quack-internal-error))
+ (unless (listp alist) (quack-internal-error))
+ `(quote ,(mapcar
+ (function (lambda (pair)
+ (let ((title (car pair))
+ (value (cdr pair)))
+ (unless (stringp title) (quack-internal-error))
+ (unless (symbolp value) (quack-internal-error))
+ `[,title
+ (quack-option-set (quote ,var) (quote ,value))
+ :style radio
+ :selected (eq ,var (quote ,value))])))
+ alist)))
+
+(defconst quack-browser-radio-alist
+ '((nil . "(Browse-URL Default)")
+ (browse-url-galeon . "Galeon")
+ (browse-url-mozilla . "Mozilla")
+ (browse-url-kde . "KDE Konqueror")
+ (browse-url-netscape . "Netscape Navigator")
+ (browse-url-w3 . "Emacs W3")
+ (w3m-browse-url . "W3M")
+ (quack-w3m-browse-url-other-window . "W3M (in other window)")
+ (browse-url-lynx-xterm . "Lynx in Xterm")
+ (browse-url-lynx-emacs . "Lynx in Emacs")
+ (browse-url-default-windows-browser . "MS Windows Default")))
+
+(defconst quack-global-menuspec
+ `("Quack"
+ ["About Quack..." quack-about]
+ ("Options"
+ ("Startup Options"
+ "These settings take full effect"
+ "once Emacs is restarted."
+ "---"
+ ,(quack-bool-menuitem "Put Quack on Global Menu Bar" quack-global-menu-p)
+ ,(quack-bool-menuitem "Remap Find-File Bindings"
+ quack-remap-find-file-bindings-p)
+ "---"
+ ["Quack Directory..." (customize-option 'quack-dir)]
+ ["Quack Scheme Mode Keymap Prefix..."
+ (customize-option 'quack-scheme-mode-keymap-prefix)])
+ "---"
+ ("Default Program" :filter quack-defaultprogram-menufilter)
+ ,(quack-bool-menuitem "Always Prompt for Program"
+ quack-run-scheme-always-prompts-p)
+ ,(quack-bool-menuitem "Program Prompt Defaults to Last"
+ quack-run-scheme-prompt-defaults-to-last-p)
+ ,(quack-bool-menuitem "Remember New Programs"
+ quack-remember-new-programs-p)
+ "---"
+ ("Newline Behavior"
+ ,@(quack-radio-menuitems
+ quack-newline-behavior
+ (("Newline" . newline)
+ ("Newline-Indent" . newline-indent)
+ ("Indent-Newline-Indent" . indent-newline-indent))))
+ ,(quack-bool-menuitem "Smart Open-Paren"
+ quack-smart-open-paren-p)
+ ("Switch-to-Scheme Method"
+ ,@(quack-radio-menuitems quack-switch-to-scheme-method
+ (("Other Window" . other-window)
+ ("Own Frame" . own-frame)
+ ("Cmuscheme Behavior" . cmuscheme)))
+ "---"
+ ,(quack-bool-menuitem
+ "Warp Pointer to Frame"
+ quack-warp-pointer-to-frame-p
+ :active (eq quack-switch-to-scheme-method 'own-frame)))
+ ("Fontification"
+ ,@(quack-radio-menuitems quack-fontify-style
+ (("PLT Style" . plt)
+ ("Extended GNU Emacs Style" . emacs)
+ ("Emacs Default" . nil)))
+ "---"
+ ,(quack-bool-menuitem "Pretty Lambda \(in PLT Style\)"
+ quack-pretty-lambda-p
+ :active (and quack-pretty-lambda-supported-p
+ (memq quack-fontify-style '(plt))))
+ ,(quack-bool-menuitem "Fontify Definition Names \(in PLT Style\)"
+ quack-pltish-fontify-definition-names-p
+ :active (eq quack-fontify-style 'plt))
+ ,(quack-bool-menuitem "Fontify Keywords \(in PLT Style\)"
+ quack-pltish-fontify-keywords-p
+ :active (eq quack-fontify-style 'plt))
+ ,(quack-bool-menuitem "Fontify 3-Semicolon Comments \(in PLT Style\)"
+ quack-fontify-threesemi-p
+ :active (memq quack-fontify-style '(plt)))
+ )
+ ("Web Browser"
+ ,@(mapcar (function
+ (lambda (n)
+ (let ((func (car n))
+ (title (cdr n)))
+ `[,title
+ (quack-option-set 'quack-browse-url-browser-function
+ (quote ,func))
+ :style radio
+ :selected ,(if (not func)
+ '(not quack-browse-url-browser-function)
+ `(eq quack-browse-url-browser-function
+ (quote ,func)))])))
+ quack-browser-radio-alist)
+ ["(Other)..."
+ (customize-option 'quack-browse-url-browser-function)
+ :style radio
+ :selected (not (assq quack-browse-url-browser-function
+ quack-browser-radio-alist))])
+ ,(quack-bool-menuitem "Tab Characters are Evil" quack-tabs-are-evil-p)
+ ("Local Keywords for Remote Manuals"
+ ,@(quack-radio-menuitems
+ quack-local-keywords-for-remote-manuals-p
+ (("Permit" . t)
+ ("Forbid" . nil)
+ ("Always" . always))))
+ ["PLT Collection Directories..."
+ (customize-option 'quack-pltcollect-dirs)]
+ "---"
+ ["Customize..." quack-customize])
+ "---"
+ ["Run Scheme" run-scheme]
+ ["Switch to Scheme Buffer" switch-to-scheme]
+ "---"
+ ("View Manual" :filter quack-view-manual-menufilter)
+ ("View SRFI" :filter quack-view-srfi-menufilter)
+ ["View Keyword Docs..." quack-view-keyword-docs]
+ ["Dired on PLT Collection..." quack-dired-pltcollect]))
+
+(defun quack-install-global-menu ()
+ (when quack-global-menu-p
+ (quack-when-gnuemacs
+ (unless (assq 'Quack menu-bar-final-items)
+ (setq menu-bar-final-items (cons 'Quack menu-bar-final-items)))
+ (easy-menu-define quack-global-menu global-map ""
+ quack-global-menuspec))
+ (quack-when-xemacs
+ ;; Die! Die! Die!
+ ;;(mapcar (function (lambda (n)
+ ;;(delete-menu-item '("Quack") n)
+ ;;(add-submenu nil quack-global-menuspec "Help" n)))
+ ;;(list
+ ;;;;current-menubar
+ ;;default-menubar
+ ;;))
+ (delete-menu-item '("Quack") current-menubar)
+ (add-submenu nil quack-global-menuspec "Help" current-menubar)
+ (set-menubar-dirty-flag))))
+
+;; TODO: We should make sure the user's custom settings have been loaded
+;; before we do this.
+(quack-install-global-menu)
+
+;; And die some more!
+;;(quack-when-xemacs (add-hook 'after-init-hook 'quack-install-global-menu))
+
+(defconst quack-scheme-mode-menuspec
+ `("Scheme"
+ ("Quack Global" ,@(cdr quack-global-menuspec))
+ "---"
+ ["Toggle Lambda Syntax" quack-toggle-lambda]
+ ["Tidy Buffer Formatting" quack-tidy-buffer]
+ ["Comment-Out Region" comment-region]
+ ["Un-Comment-Out Region" quack-uncomment-region]
+ "---"
+ ["Evaluate Last S-expression" scheme-send-last-sexp]
+ ["Evaluate Region" scheme-send-region]
+ ["Evaluate Region & Go" scheme-send-region-and-go]
+ ["Evaluate Last Definition" scheme-send-definition]
+ ["Evaluate Last Definition & Go" scheme-send-definition-and-go]
+ ["Compile Definition" scheme-compile-definition]
+ ["Compile Definition & Go" scheme-compile-definition-and-go]
+ ["Load Scheme File" scheme-load-file]
+ ["Compile Scheme File" scheme-compile-file]
+ "---"
+ ["View Keyword Docs..." quack-view-keyword-docs]
+ ["Quack Find File" quack-find-file]))
+
+(defvar quack-scheme-mode-menu)
+(quack-when-gnuemacs
+ (let ((map (make-sparse-keymap)))
+ (setq quack-scheme-mode-menu nil)
+ (easy-menu-define quack-scheme-mode-menu map ""
+ quack-scheme-mode-menuspec)
+ (define-key scheme-mode-map [menu-bar scheme]
+ (cons "Scheme"
+ (or (lookup-key map [menu-bar Scheme])
+ (lookup-key map [menu-bar scheme]))))))
+
+(defun quack-view-manual-menufilter (arg)
+ (quack-menufilter-return "quack-view-manual-menufilter-menu"
+ (quack-manuals-menu)))
+
+(defun quack-view-srfi-menufilter (arg)
+ (quack-menufilter-return
+ "quack-view-srfi-menufilter-menu"
+ (condition-case nil
+ (quack-srfi-menu t)
+ ;; TODO: Move the generation of this fallback menu down to
+ ;; quack-srfi-menu.
+ (error '(["Update SRFI Index" quack-update-srfi-index]
+ "---"
+ ("Draft" :active nil "")
+ ("Final" :active nil "")
+ ("Withdrawn" :active nil "")
+ ["Other SRFI..." quack-view-srfi])))))
+
+(defun quack-defaultprogram-menufilter (arg)
+ (quack-menufilter-return
+ "quack-defaultprogram-menufilter-menu"
+ `(,@(quack-optionmenu-items-setdefaultprogram)
+ "---"
+ ["Other Program..." quack-set-other-default-program]
+ "---"
+ ("Forget Program"
+ ,@(mapcar
+ (function
+ (lambda (program)
+ `[,(format "Forget %s" program)
+ (quack-forget-program ,program)]))
+ quack-programs)))))
+
+(defun quack-optionmenu-items-setdefaultprogram ()
+ (let* ((programs (quack-sort-string-list-copy quack-programs))
+ (add-default-p (and quack-default-program
+ (not (member quack-default-program programs)))))
+ (and add-default-p
+ (setq programs (cons quack-default-program programs)))
+ (mapcar
+ (function
+ (lambda (program)
+ (let* ((selected-p (and quack-default-program
+ (equal program quack-default-program))))
+ `[,(format "%s%s"
+ program
+ (if (and add-default-p
+ (equal program quack-default-program))
+ " (temporary)"
+ ""))
+ (quack-option-set 'quack-default-program ,program)
+ :style radio :selected ,selected-p])))
+ programs)))
+
+(mapcar (function (lambda (sym) (put sym 'menu-enable 'mark-active)))
+ '(comment-region
+ indent-region
+ quack-uncomment-region
+ scheme-send-region
+ scheme-send-region-and-go))
+
+;; Option Menu Callbacks:
+
+(defun quack-set-other-default-program ()
+ (interactive)
+ (let* ((minibuffer-allow-text-properties nil)
+ (program (quack-without-side-whitespace
+ (read-string "Other Default Program: "))))
+ (if (string= program "")
+ (message "Default program unchanged.")
+ (quack-remember-program-maybe program)
+ (quack-option-set 'quack-default-program
+ program))))
+
+(defun quack-forget-program (program)
+ (setq quack-programs (delete program quack-programs))
+ (quack-option-set 'quack-programs quack-programs t)
+ (message "Forgot program %S." program))
+
+(defun quack-custom-set (sym value)
+ ;; Clean up the value based on the variable symbol.
+ (cond ((eq sym 'quack-programs)
+ (setq value (quack-sort-string-list-copy value))))
+
+ ;; Set default binding. Set local binding just for the halibut, although if
+ ;; there are local bindings, then other things will likely break. \(We used
+ ;; to have a check here, but removed it while porting to XEmacs.\)
+ (set sym value)
+ (set-default sym value)
+
+ ;; TODO: Probably don't do this during Emacs initialization time, to avoid
+ ;; unnecessary behavior like:
+ ;;
+ ;; Loading ~/emacs/my-custom.el (source)...
+ ;; Updating Scheme Mode buffers...done
+ ;; Updating Scheme Mode buffers...done
+ ;; Updating Scheme Mode buffers...done
+ ;; Updating Scheme Mode buffers...done
+ ;; Updating Scheme Mode buffers...done
+ ;; Loading ~/emacs/my-custom.el (source)...done
+
+ ;; Update dependent program state.
+ (cond ((memq sym '(quack-emacsish-keywords-to-fontify
+ quack-fontify-style
+ quack-fontify-threesemi-p
+ quack-pltish-fontify-definition-names-p
+ quack-pltish-fontify-keywords-p
+ quack-pltish-keywords-to-fontify
+ quack-pretty-lambda-p))
+ (quack-update-scheme-mode-buffers))
+
+ ((eq sym 'quack-local-keywords-for-remote-manuals-p)
+ (quack-invalidate-manuals-caches))
+
+ ((eq sym 'quack-pltcollect-dirs)
+ (quack-invalidate-pltcollects-caches))))
+
+(defun quack-option-set (sym value &optional silently)
+ (if quack-options-persist-p
+ (customize-save-variable sym value)
+ (quack-custom-set sym value))
+ (or silently
+ (message "Set %s%s to: %S"
+ sym
+ (if quack-options-persist-p "" " (non-persistently)")
+ value)))
+
+(defun quack-option-toggle (sym &optional silently)
+ (quack-option-set sym (not (symbol-value sym)) t)
+ (or silently
+ (message "Set %s%s %s."
+ sym
+ (if quack-options-persist-p "" " (non-persistently)")
+ (if (symbol-value sym) "ON" "OFF"))))
+
+(defun quack-update-scheme-mode-buffers ()
+ (save-excursion
+ (quack-activity
+ "Updating Scheme Mode buffers"
+ (mapcar (function
+ (lambda (buf)
+ (set-buffer buf)
+ (when (eq major-mode 'scheme-mode)
+ (quack-activity (format "Updating buffer %S" (buffer-name))
+ (scheme-mode)))))
+ (buffer-list)))))
+
+;; Pretty Lambda:
+
+(defconst quack-lambda-char (make-char 'greek-iso8859-7 107))
+
+(defconst quack-pretty-lambda-supported-p
+ (and quack-gnuemacs-p (>= emacs-major-version 21)))
+
+;; Font Lock:
+
+(defconst quack-emacsish1-font-lock-keywords
+ `((,(concat "[[(]"
+ "\\(" ; #<1
+ "define\\*?"
+ ; #=2 #=3
+ (quack-re-alt (quack-re-alt ""
+ "-generic"
+ "-generic-procedure"
+ "-method"
+ "-public"
+ "/override"
+ "/private"
+ "/public")
+ ; #=4
+ (quack-re-alt "-macro"
+ "-syntax")
+ "-class"
+ "-module"
+ "-signature"
+ "-struct")
+ "\\)" ; #>1
+ "\\>"
+ "[ \t]*[[(]?"
+ ; #=5
+ "\\(\\sw+\\)?")
+ (1 font-lock-keyword-face)
+ (5 (cond ((match-beginning 3) font-lock-function-name-face)
+ ((match-beginning 4) font-lock-variable-name-face)
+ (t font-lock-type-face))
+ nil t))
+
+ ;; PLT module definitions.
+ ("[[(]\\(module\\)\\>[ \t]+\\(\\sw+\\)?"
+ (1 font-lock-keyword-face)
+ (2 font-lock-type-face nil t))))
+
+(defconst quack-emacsish2-font-lock-keywords
+ (append quack-emacsish1-font-lock-keywords
+ `(
+ ;; Misc. keywords.
+ (,(concat
+ "[[(]\\("
+ (regexp-opt quack-emacsish-keywords-to-fontify)
+ "\\)\\>")
+ . 1)
+ ;; Class specifiers in SOS, Stklos, Goops.
+ ("\\<<\\sw+>\\>" . font-lock-type-face)
+ ;; Colon keywords.
+ ("\\<:\\sw+\\>" . font-lock-builtin-face))))
+
+(defvar quack-pltish-font-lock-keywords nil)
+
+(defun quack-pltish-num-re (radix digit base16-p)
+ ;; These regexps started as a transliteration of the R5RS BNF to regular
+ ;; expressions, adapted for PLTisms, and with a few optimizations.
+ ;;
+ ;; PLTisms are that 'e' is not permitted as an exponent marker in base-16
+ ;; literals, and that "decimal-point" forms are permitted in any radix.
+ ;;
+ ;; There's obvious opportunity for further optimization, especially if we
+ ;; relax the accepted syntax a little. These regexps have not been tested
+ ;; much, but, since this is only Emacs syntax fontification, false-positives
+ ;; and false-negatives will be obvious yet benign.
+ (let* ((uint (concat digit "+#*"))
+ (sign "[-+]?")
+ (suffix (quack-re-optional (if base16-p "[sSfFdDlL]" "[eEsSfFdDlL]")
+ sign
+ "[0-9]+"))
+ (decimal (quack-re-alt
+ (concat uint suffix)
+ (concat "\\." digit "+#*" suffix)
+ (concat digit
+ "+"
+ (quack-re-alt (concat "\\." digit "*")
+ "#+\\.")
+ "#*")))
+ (ureal (quack-re-alt uint
+ (concat uint "/" uint)
+ decimal))
+ (real (concat sign ureal))
+ (complex (quack-re-alt
+ (concat real
+ (quack-re-alt (concat "@" real)
+ (quack-re-optional
+ "[-+]"
+ (quack-re-optional ureal)
+ "i")
+ ""))
+ (concat "[-+]" (quack-re-optional ureal) "i")))
+ (exact (quack-re-optional "#[eEiI]"))
+ (prefix (quack-re-alt (concat radix exact)
+ (concat exact radix))))
+ (concat "\\<" prefix complex "\\>")))
+
+(defconst quack-pltish-fls-base
+ `(
+ ("\\`\\(MrEd\\|Welcome to MzScheme\\) v[^\n]+" . quack-banner-face)
+ ("\\`Gambit Version 4\\.0[^\n]*" . quack-banner-face)
+ ("\\`Welcome to scsh [0-9][^\n]+\nType ,\\? for help[^\n]+"
+ . quack-banner-face)
+ ("\\`MIT/GNU Scheme running under [^\n]+" . quack-banner-face)
+ ;;("\\`; This is the CHICKEN interpreter - Version [^\n]+\n; (c)[^\n]+"
+ ;; . quack-banner-face)
+ ;;("\\`Scheme Microcode Version[^\n]+\nMIT Scheme[^\n]+\n\\([^\n]+\n\\)+" .
+ ;;quack-banner-face)
+ ("'\\sw+\\>" . quack-pltish-selfeval-face)
+ ("'|\\(\\sw\\| \\)+|" . quack-pltish-selfeval-face)
+ ;; Note: The first alternative in the following rule will misleadingly
+ ;; fontify some invalid syntax, such as "#\(x".
+ ("\\<#\\\\\\([][-`~!@#$%&*()_+=^{}\;:'\"<>,.?/|\\\\]\\|\\sw+\\>\\)"
+ . quack-pltish-selfeval-face)
+ ("[][()]" . quack-pltish-paren-face)
+ ("\\<#\\(t\\|f\\)\\>" . quack-pltish-selfeval-face)
+ ("\\<+\\(inf.0\\|nan\\)\\>" . quack-pltish-selfeval-face)
+ ("\\<-inf.0\\>" . quack-pltish-selfeval-face)
+ ,@(mapcar (function (lambda (args)
+ (cons (apply 'quack-pltish-num-re args)
+ 'quack-pltish-selfeval-face)))
+ '(("#b" "[01]" nil)
+ ("#o" "[0-7]" nil)
+ ("\\(#d\\)?" "[0-9]" nil)
+ ("#x" "[0-9a-fA-F]" t)))))
+
+(defconst quack-pltish-fls-defnames
+ ;; TODO: Optimize these once they're fairly complete and correct.
+
+ ;; TODO: Would be nice to fontify binding names everywhere they are
+ ;; introduced, such as in `let' and `lambda' forms. That may require
+ ;; real parsing to do reasonably well -- the kludges get too bad and
+ ;; slow, and font-lock gets in the way more than it helps.
+
+ `(
+ ;,@quack-pltish-font-lock-keywords
+
+ ;; Lots of definition forms that start with "define".
+ (,(concat "[[(]"
+ "define\\*?"
+ ;; TODO: make this into regexp-opt
+ (quack-re-alt ""
+ "-class"
+ "-class"
+ "-const-structure"
+ "-constant"
+ "-embedded"
+ "-entry-point"
+ "-external"
+ "-for-syntax"
+ "-foreign-record"
+ "-foreign-type"
+ "-foreign-variable"
+ "-generic"
+ "-generic-procedure"
+ "-inline"
+ "-location"
+ "-macro"
+ "-method"
+ "-opt"
+ "-parameters"
+ "-public"
+ "-reader-ctor"
+ "-record"
+ "-record-printer"
+ "-record-type"
+ "-signature"
+ "-struct"
+ "-structure"
+ "-syntax"
+ "-values"
+ "-values-for-syntax"
+ "/contract"
+ "/override"
+ "/private"
+ "/public")
+ "\\>"
+ "[ \t]*[[(]?"
+ "\\(\\sw+\\)")
+ (2 (let ((name (quack-match-string-no-properties 2)))
+ (if (= (aref name (1- (length name))) ?%)
+ quack-pltish-class-defn-face
+ quack-pltish-defn-face))
+ nil t))
+
+ ;; `defmacro' and related SCM forms.
+ (,(concat "[[(]def"
+ (quack-re-alt (concat "macro"
+ (quack-re-alt "" "-public"))
+ "syntax")
+ "\\>[ \t]+\\(\\sw+\\)")
+ 3 quack-pltish-defn-face nil t)
+
+ ;; `defmac' from SIOD.
+ ("[[(]defmac[ \t]+[[(][ \t]*\\(\\sw+\\)"
+ 1 quack-pltish-defn-face nil t)
+
+ ;; `defvar' and `defun' from SIOD.
+ (,(concat "[[(]def"
+ (quack-re-alt "un"
+ "var")
+ "[ \t]+\\(\\sw+\\)")
+ 2 quack-pltish-defn-face nil t)
+
+ ;; Guile and Chicken `define-module'.
+ ("[[(]define-module\\>[ \t]+[[(][ \t]*\\(\\sw+\\([ \t]+\\sw+\\)*\\)"
+ 1 quack-pltish-module-defn-face nil t)
+
+ ;; PLT `define-values', `define-syntaxes', and `define-syntax-set'.
+ (,(concat "[[(]define-"
+ (quack-re-alt "values" "syntax-set" "syntaxes")
+ "\\>[ \t]+[[(][ \t]*\\(\\sw+\\([ \t]+\\sw+\\)*\\)")
+ 2 quack-pltish-defn-face nil t)
+
+ ;; PLT `module'.
+ ("[[(]module\\>[ \t]+\\(\\sw+\\)"
+ 1 quack-pltish-module-defn-face nil t)
+
+ ;; Named `let'. (Note: This is disabled because it's too incongruous.)
+ ;;("[[(]let\\>[ \t]+\\(\\sw+\\)"
+ ;; 1 quack-pltish-defn-face nil t)
+ ))
+
+;; TODO: Adding PLT-style (quasi)quoted list fontifying is obviously not doable
+;; with just regexps. Probably requires either cloning
+;; `font-lock-default-fontify-region' just to get it to call our
+;; replacement syntactic pass fontification function, *or*
+;; before-advising `font-lock-fontify-keywords-region' to perform our
+;; syntactic pass when in scheme-mode, and around-advising
+;; `font-lock-fontify-syntactically-region' to not do anything for
+;; scheme-mode (or maybe setting `font-lock-keywords-only' to non-nil,
+;; unless that breaks something else). Or just ditch font-lock. See
+;; `font-lock-fontify-region-function' variable in font-lock specs.
+
+;; (defconst quack-pltish-fls-keywords
+;; `((,(concat
+;; "[[(]\\("
+;; (regexp-opt quack-pltish-keywords-to-fontify)
+;; "\\)\\>")
+;; (1 quack-pltish-keyword-face))))
+
+(defun quack-install-fontification ()
+
+ (when (eq quack-fontify-style 'plt)
+ (set (make-local-variable 'font-lock-comment-face)
+ 'quack-pltish-comment-face)
+ (set (make-local-variable 'font-lock-string-face)
+ 'quack-pltish-selfeval-face))
+
+ (let* ((sk `(("\\(#\\)\\(|\\)"
+ (1 ,quack-pound-syntax)
+ (2 ,quack-bar-syntax))
+ ("\\(|\\)\\(#\\)"
+ (1 ,quack-bar-syntax)
+ (2 ,quack-pound-syntax))))
+ (pl (if (and quack-pretty-lambda-supported-p quack-pretty-lambda-p)
+ '(("[[(]\\(case-\\|match-\\|opt-\\)?\\(lambda\\)\\>"
+ 2
+ (progn (compose-region (match-beginning 2)
+ (match-end 2)
+ quack-lambda-char)
+ nil)))
+ '()))
+ (threesemi (if quack-fontify-threesemi-p
+ `((,(concat "^\\(\;\;\;\\)"
+ "\\("
+ "[ \t]*"
+ "\\("
+ "[^\r\n]*"
+ "\\)"
+ "\r?\n?\\)")
+ (1 quack-threesemi-semi-face prepend)
+ (2 quack-threesemi-text-face prepend)
+ ;;(4 quack-threesemi-h1-face prepend)
+ ;;(5 quack-threesemi-h2-face prepend)
+ )
+ ("^\;\;\; @\\(Package\\|section\\|unnumberedsec\\)[ \t]+\\([^\r\n]*\\)"
+ (2 quack-threesemi-h1-face prepend))
+ ("^\;\;\; @subsection[ \t]+\\([^\r\n]*\\)"
+ (1 quack-threesemi-h2-face prepend))
+ )
+ '()))
+ (fld `(,(cond
+ ((eq quack-fontify-style 'plt)
+ (set (make-local-variable
+ 'quack-pltish-font-lock-keywords)
+ `(,@quack-pltish-fls-base
+ ,@(if quack-pltish-fontify-definition-names-p
+ quack-pltish-fls-defnames
+ '())
+ ,@pl
+ ,@(if quack-pltish-fontify-keywords-p
+ ;; quack-pltish-fls-keywords
+ `((,(concat
+ "[[(]\\("
+ (regexp-opt
+ quack-pltish-keywords-to-fontify)
+ "\\)\\>")
+ (1 quack-pltish-keyword-face)))
+ '())
+ ,@threesemi
+ ))
+ 'quack-pltish-font-lock-keywords)
+ ((eq quack-fontify-style 'emacs)
+ ;; TODO: Do pretty-lambda here too. But first get rid of
+ ;; this font-lock style "degrees of general gaudiness"
+ ;; and switch to separate options for each property of
+ ;; fontification.
+ '(quack-emacsish1-font-lock-keywords
+ quack-emacsish1-font-lock-keywords
+ quack-emacsish2-font-lock-keywords))
+ (t (quack-internal-error)))
+ nil
+ t
+ ((?! . "w") (?$ . "w") (?% . "w") (?& . "w") (?* . "w")
+ (?+ . "w") (?- . "w") (?. . "w") (?/ . "w") (?: . "w")
+ (?< . "w") (?= . "w") (?> . "w") (?? . "w") (?@ . "w")
+ (?^ . "w") (?_ . "w") (?~ . "w")
+ ,@(if (eq quack-fontify-style 'plt)
+ '((?# . "w"))
+ '()))
+ ;; TODO: Using `beginning-of-defun' here could be very slow,
+ ;; say, when you have a large buffer that is wrapped in a
+ ;; `module' form. Look into whether this is a problem.
+ beginning-of-defun
+ ,@(if t ; quack-gnuemacs-p
+ `((font-lock-mark-block-function . mark-defun)
+ (font-lock-syntactic-keywords . ,sk))
+ '()))))
+
+ ;; TODO: Figure out why `font-lock-syntactic-keywords' just doesn't work in
+ ;; XEmacs 21, even though the syntax text properties seem to get set.
+ ;; We have already beaten it like an egg-sucking dog.
+
+ ;;(if quack-xemacs-p
+ ;;(put 'scheme-mode 'font-lock-defaults fld)
+ (set (make-local-variable 'font-lock-defaults) fld)
+ ;;)
+
+ ;;(when quack-xemacs-p
+ ;; (set (make-local-variable 'font-lock-syntactic-keywords)
+ ;; syntactic-keywords))
+ ))
+
+;; Scheme Mode Startup Hook:
+
+(defun quack-locally-steal-key-bindings (old-func new-func)
+ (mapcar (function (lambda (key)
+ (unless (and (vectorp key)
+ (eq (aref key 0) 'menu-bar))
+ (local-set-key key new-func))))
+ (where-is-internal old-func)))
+
+(defun quack-shared-mode-hookfunc-stuff ()
+
+ ;; Install the Quack keymap and menu items.
+ (local-set-key quack-scheme-mode-keymap-prefix quack-scheme-mode-keymap)
+ (quack-when-xemacs
+ (when (featurep 'menubar)
+ ;;(set-buffer-menubar current-menubar)
+ ;; TODO: For XEmacs, we could have two versions of this menu -- the popup
+ ;; one would have the Global submenu, but the menubar one would have
+ ;; the Global submenu only if quack-global-menu-p were nil.
+ (add-submenu nil quack-scheme-mode-menuspec)
+ (set-menubar-dirty-flag)
+ (setq mode-popup-menu quack-scheme-mode-menuspec)))
+
+ ;; Bind the paren-matching keys.
+ (local-set-key ")" 'quack-insert-closing-paren)
+ (local-set-key "]" 'quack-insert-closing-bracket)
+
+ (local-set-key "(" 'quack-insert-opening-paren)
+ (local-set-key "[" 'quack-insert-opening-bracket)
+
+ ;; Steal any find-file bindings.
+ (when quack-remap-find-file-bindings-p
+ (quack-locally-steal-key-bindings 'find-file 'quack-find-file)
+ (quack-locally-steal-key-bindings 'ido-find-file 'quack-find-file))
+
+ ;; Fight against tabs.
+ (when quack-tabs-are-evil-p
+ (setq indent-tabs-mode nil))
+
+ ;; Remove character compositions, to get rid of any pretty-lambda. (Note:
+ ;; This is bad, if it turns out compositions are used for other purposes in
+ ;; buffers that are edited with Scheme Mode.)
+ (when quack-pretty-lambda-supported-p
+ (eval '(decompose-region (point-min) (point-max))))
+
+ ;; Install fontification
+ (when quack-fontify-style
+ (when (and (boundp 'font-lock-keywords)
+ (symbol-value 'font-lock-keywords)
+ (not (featurep 'noweb-mode)))
+ ;; This warning is not given if the `noweb-mode' package is installed.
+ (quack-warning "`font-lock-keywords' already set when hook ran."))
+ (quack-install-fontification))
+
+ ;; Die! Die! Die!
+ (quack-when-xemacs
+ (quack-install-global-menu)))
+
+(defun quack-inferior-scheme-mode-hookfunc ()
+ (quack-shared-mode-hookfunc-stuff))
+
+(defun quack-scheme-mode-hookfunc ()
+ (quack-shared-mode-hookfunc-stuff)
+
+ ;; Bind Return/Enter key.
+ (local-set-key "\r" 'quack-newline)
+
+ ;; Install toolbar.
+ ;;(unless quack-xemacs-p
+ ;;(when (display-graphic-p)
+ ;;(quack-install-tool-bar)))
+ )
+
+(add-hook 'scheme-mode-hook 'quack-scheme-mode-hookfunc)
+(add-hook 'inferior-scheme-mode-hook 'quack-inferior-scheme-mode-hookfunc)
+
+;; Compilation Mode:
+
+;; TODO: Add compilation-directory-matcher support for "setup-plt: in".
+
+(defvar quack-saved-compilation-error-regexp-alist nil)
+
+(defconst quack-compilation-error-regexp-alist-additions
+ (let ((no-line (if quack-xemacs-p
+ (let ((m (make-marker))) (set-marker m 0) m)
+ 'quack-compile-no-line-number)))
+ `(
+
+ ;; PLT MzScheme 205 "setup-plt"
+ ;; load-handler: expected a `module' declaration for `bar-unit' in
+ ;; "/u/collects/bar/bar-unit.ss", but found something else
+ (,(concat "load-handler: expected a `module' declaration for `[^']+' in "
+ "\"\\([^:\n\"]+\\)\", but found something else")
+ 1 ,no-line)
+
+ ;; PLT MzScheme 205 "setup-plt".
+ ;; setup-plt: Error during Compiling .zos for Foo Bar (/u/collects/fb)
+ ("setup-plt: Error during Compiling .zos for [^\n]+ \(\\([^\n\)]+\\)\)"
+ 1 ,no-line)
+
+ ;; PLT MzScheme 4.0.1 "setup-plt".
+ ("setup-plt: +\\(?:WARNING: +\\)\\([^:\n]+\\)::"
+ 1 ,no-line)
+
+ ;; PLT MzScheme 4.0.1 "setup-plt".
+ ("setup-plt: +\\(?:WARNING: +\\)\\([^:\n]+\\):\\([0-9]+\\):\\([0-9]+\\)"
+ 1 2 3)
+
+ ;; PLT MzScheme 4.0.1 "setup-plt":
+ ("load-handler: expected a `module' declaration for `[^'\n]+' in #<path:\\([^>\n]+\\)>[^\n]+"
+ 1 ,no-line)
+
+ )))
+
+(defun quack-compile-no-line-number (filename column)
+ (list (point-marker) filename 1 (and column (string-to-number column))))
+
+(defun quack-install-compilation-mode-stuff ()
+ (unless quack-saved-compilation-error-regexp-alist
+ (setq quack-saved-compilation-error-regexp-alist
+ compilation-error-regexp-alist))
+ (setq compilation-error-regexp-alist
+ (append quack-compilation-error-regexp-alist-additions
+ quack-saved-compilation-error-regexp-alist)))
+
+(quack-install-compilation-mode-stuff)
+
+;; PLT Package Mode:
+
+;; TODO: Do some simple checking and summarize what directories and files are
+;; getting modified by this package.
+
+;; TODO: Maybe don't worry about preserving the decompressed text verbatim in
+;; the buffer -- set markers and generate headings, and be able to
+;; construct valid package.
+
+;; TODO: Command to install package from original file using "setup-plt".
+
+;; TODO: Fontify Scheme code file contents.
+
+(defvar quack-pltfile-mode-hook nil)
+
+(defvar quack-hiding-ovlcat)
+(put 'quack-hiding-ovlcat 'face 'default)
+(put 'quack-hiding-ovlcat 'intangible t)
+(put 'quack-hiding-ovlcat 'invisible t)
+
+(defvar quack-pltfile-mode-map (make-sparse-keymap))
+(define-key quack-pltfile-mode-map "q" 'quack-pltfile-quit)
+(define-key quack-pltfile-mode-map "r" 'quack-pltfile-raw)
+(define-key quack-pltfile-mode-map " " 'scroll-up)
+
+;; TODO: Make a menu map for pltfile-mode.
+
+(defun quack-pltfile-mode ()
+ (interactive)
+ "Major mode for viewing PLT Scheme `.plt' package files.
+
+\\{quack-pltfile-mode-map}
+
+Provided by Quack: http://www.neilvandyke.org/quack/"
+ (kill-all-local-variables)
+ (put 'quack-pltfile-mode 'mode-class 'special)
+ (setq major-mode 'quack-pltfile-mode)
+ (setq mode-name "PLT Package")
+ (use-local-map quack-pltfile-mode-map)
+ ;; Note: Currently, the `font-lock' feature is always defined, since we
+ ;; require it.
+ (when (featurep 'font-lock)
+ (setq font-lock-defaults nil))
+ (buffer-disable-undo)
+ (let ((saved-bmp (buffer-modified-p)))
+ (quack-activity "Decoding PLT package" (quack-pltfile-decode-buffer))
+ (setq buffer-read-only t)
+ (set-buffer-modified-p saved-bmp))
+ (quack-when-xemacs
+ (make-variable-buffer-local 'write-contents-hooks))
+ (add-hook 'write-contents-hooks 'quack-prevent-pltfile-write)
+ (run-hooks 'quack-pltfile-mode-hook)
+ (message "Decoded PLT package. %s"
+ (substitute-command-keys
+ (concat "`\\[quack-pltfile-quit]' to quit"
+ ", `\\[quack-pltfile-raw]' for raw format."))))
+
+(defun quack-prevent-pltfile-write ()
+ (unless (yes-or-no-p
+ "Write a decoded PLT package buffer?! Are you *sure*?!")
+ (error "Aborted write of decoded PLT package buffer.")))
+
+(defun quack-pltfile-raw ()
+ (interactive)
+ (let ((auto-mode-alist '()))
+ (setq buffer-read-only nil)
+ (widen)
+ (delete-region (point-min) (point-max))
+ (fundamental-mode)
+ (revert-buffer t t)))
+
+(defun quack-pltfile-quit ()
+ (interactive)
+ (kill-buffer (current-buffer)))
+
+(defun quack-skip-whitespace-to-nonblank-line-beginning ()
+ (save-match-data
+ (while (looking-at "[ \t\r\f]*\n")
+ (goto-char (match-end 0)))))
+
+(defun quack-pltfile-decode-buffer ()
+
+ ;; MIME Base-64 decode. (Note: an error is signaled if this fails.)
+ (base64-decode-region (point-min) (point-max))
+
+ ;; Gzip decompress.
+ (let ((coding-system-for-write (if quack-xemacs-p 'binary 'raw-text-unix))
+ (coding-system-for-read (if quack-xemacs-p 'binary 'raw-text-unix))
+ (inhibit-eol-conversion t)
+ status)
+ (unless (= (setq status (call-process-region (point-min) (point-max)
+ "gzip" t t nil "-d")) 0)
+ (error "Could not decompress PLT package: gzip process status %s"
+ status)))
+
+ ;; Move past the "PLT" cookie, and the two sexp forms.
+ (goto-char (point-min))
+ (unless (looking-at "PLT")
+ (error "This does not appear to be a PLT package file."))
+ (goto-char (match-end 0))
+ (forward-list 2)
+ (quack-skip-whitespace-to-nonblank-line-beginning)
+ (quack-make-face-ovlext (point-min) (point) 'quack-pltfile-prologue-face)
+
+ ;; Process the buffer contents.
+ (let ((standard-input (current-buffer)))
+
+ (while (not (eobp))
+ (let ((step-beg (point)))
+ ;; TODO: This read will fail if we just had whitespace at the end of
+ ;; the file, which it shouldn't, but maybe we should check, just
+ ;; in case.
+ (let ((sym (read)))
+ (unless (symbolp sym)
+ (error "Expected a symbol, but saw: %S" sym))
+ (cond
+
+ ((eq sym 'dir)
+ (forward-list)
+ (quack-skip-whitespace-to-nonblank-line-beginning)
+ (quack-make-face-ovlext step-beg
+ (point)
+ 'quack-pltfile-dir-face))
+
+ ((memq sym '(file file-replace))
+ (forward-list)
+ (let ((size (read)))
+ (unless (and (integerp size) (>= size 0))
+ (error "Expected a file size, but saw: %S" size))
+ (unless (looking-at "[ \t\r\n\f]*\\*")
+ (error "Expected a `*' after file size."))
+ (goto-char (match-end 0))
+
+ ;; Fontify the file header.
+ (quack-make-face-ovlext step-beg
+ (1- (point))
+ 'quack-pltfile-file-face)
+
+ ;; Hide the file contents asterisk.
+ (quack-make-hiding-ovlext (1- (point)) (point))
+
+ ;; Set the coding region for the content.
+ (let* ((content-beg (point))
+ (content-end (+ content-beg size))
+ (cs (detect-coding-region content-beg
+ content-end)))
+ (goto-char content-end)
+ (when (listp cs)
+ (setq cs (car cs)))
+ (unless (eq cs 'undecided)
+ (cond ((eq cs 'undecided-dos) (setq cs 'raw-text-dos))
+ ((eq cs 'undecided-mac) (setq cs 'raw-text-mac))
+ ((eq cs 'undecided-unix) (setq cs 'raw-text-unix)))
+ (decode-coding-region content-beg content-end cs))
+ ;; TODO: XEmacs 21 `decode-coding-region' seems to lose the
+ ;; point position. This is disconcerting, since the
+ ;; point semantics under coding system changes do not
+ ;; currently seem to be well-specified, so resetting the
+ ;; point here *might* not always be the right thing to
+ ;; do. Verify.
+ (quack-when-xemacs
+ (goto-char content-end)))))
+
+ (t (error "Expected `dir', `file', or `file-replace', but saw: %S"
+ sym)))))))
+
+ ;; Return point to top of buffer.
+ (goto-char (point-min)))
+
+;; The rest of this file except for the `provide' form is TODO comments.
+
+;; TODO: Add tool bar support later.
+;;
+;; (defvar quack-toolbarimage-width 24)
+;; (defvar quack-toolbarimage-height 24)
+;;
+;; (defun quack-create-image (&rest args)
+;; (if (and quack-gnuemacs-p (>= emacs-major-version 21))
+;; (apply 'create-image args)
+;; nil))
+;;
+;; (defun quack-make-toolbarimage (&rest lines)
+;; ;; TODO: We really should make an efficient function to print N spaces
+;; ;; or to return a string of N spaces. Or at least keep 1-2
+;; ;; strings for the left and right padding here, which will
+;; ;; usually be the same for the duration of this function.
+;; (quack-create-image
+;; (let* ((lines-count (length lines))
+;; (blank-line (make-string quack-toolbarimage-width 32)))
+;; (and (> lines-count quack-toolbarimage-height) (quack-internal-error))
+;; (with-output-to-string
+;; (princ "/* XPM */\nstatic char *magick[] = {\n")
+;; ;;(princ "/* columns rows colors chars-per-pixel */\n")
+;; (princ (format "\"%d %d 5 1\",\n"
+;; quack-toolbarimage-width quack-toolbarimage-height))
+;; (princ "\". c #f0f0f0\",\n")
+;; (princ "\"@ c #0f0f0f\",\n")
+;; (princ "\"g c #00b000\",\n")
+;; (princ "\"r c #d00000\",\n")
+;; (princ "\" c None\",\n")
+;; ;;(princ "/* pixels */\n")
+;; (let ((line-num 0))
+;; (mapcar (function
+;; (lambda (line)
+;; (princ "\"")
+;; (if line
+;; (let* ((c (length line))
+;; (l (/ (- quack-toolbarimage-width c) 2)))
+;; (and (> c quack-toolbarimage-width)
+;; (quack-internal-error))
+;; (princ (make-string l 32))
+;; (princ line)
+;; (princ (make-string (- quack-toolbarimage-width
+;; c l)
+;; 32)))
+;; (princ blank-line))
+;; (if (< (setq line-num (1+ line-num))
+;; quack-toolbarimage-height)
+;; (princ "\",\n")
+;; (princ "\"\n"))))
+;; (let ((rows-before (/ (- quack-toolbarimage-width
+;; lines-count)
+;; 2)))
+;; `(,@(make-list rows-before nil)
+;; ,@lines
+;; ,@(make-list (- quack-toolbarimage-height
+;; lines-count rows-before)
+;; nil)))))
+;; (princ "};\n")))
+;; 'xpm t))
+;;
+;; (defvar quack-tbi-evalbuf
+;; (quack-make-toolbarimage
+;; "@@@@@@@@@@ "
+;; "@........@@ "
+;; "@........@.@ ggg "
+;; "@........@..@ ggg "
+;; "@........@@@@@ ggg "
+;; "@............@ ggg "
+;; "@..@@........@ ggg "
+;; "@...@@.......@ ggg "
+;; "@....@@......@ ggg "
+;; "@.....@@.....@ ggg "
+;; "@....@@@@....@ ggg "
+;; "@...@@..@@...@ ggg "
+;; "@..@@....@@..@ ggg "
+;; "@............@ ggg "
+;; "@@@@@@@@@@@@@@ ggg "
+;; " ggg "
+;; " ggggggg"
+;; " ggggg "
+;; " ggg "
+;; " g "))
+;;
+;; (defvar quack-tbi-adoc
+;; (quack-make-toolbarimage
+;; "@@@@@@@@@@ "
+;; "@........@@ "
+;; "@........@.@ "
+;; "@........@..@ "
+;; "@........@@@@@"
+;; "@...@@@......@"
+;; "@..@@@@@@....@"
+;; "@..@....@@...@"
+;; "@...@@@.@@...@"
+;; "@..@@@@@@@...@"
+;; "@..@@...@@...@"
+;; "@..@@..@@@...@"
+;; "@...@@@@.@@..@"
+;; "@............@"
+;; "@@@@@@@@@@@@@@"))
+;;
+;; (defvar quack-tbi-manual
+;; (quack-make-toolbarimage
+;; "@@@@@@@@@@ "
+;; "@........@@ "
+;; "@........@.@ "
+;; "@........@..@ "
+;; "@........@@@@@"
+;; "@............@"
+;; "@..@@.@.@@...@"
+;; "@..@@@@@@@@..@"
+;; "@..@@.@@.@@..@"
+;; "@..@@.@@.@@..@"
+;; "@..@@.@@.@@..@"
+;; "@..@@.@@.@@..@"
+;; "@..@@.@@.@@..@"
+;; "@............@"
+;; "@@@@@@@@@@@@@@"))
+;;
+;; (defvar quack-tbi-manuallookup
+;; (quack-make-toolbarimage
+;; "@@@@@@@@@@ "
+;; "@........@@ "
+;; "@........@.@ "
+;; "@........@..@ "
+;; "@........@@@@@ "
+;; "@............@ "
+;; "@..@@.@@@@@@@@@@ "
+;; "@...@@@........@@ "
+;; "@....@@........@.@ "
+;; "@.....@........@..@ "
+;; "@....@@........@@@@@"
+;; "@...@@@............@"
+;; "@..@@.@..@@.@.@@...@"
+;; "@.....@..@@@@@@@@..@"
+;; "@@@@@@@..@@.@@.@@..@"
+;; " @..@@.@@.@@..@"
+;; " @..@@.@@.@@..@"
+;; " @..@@.@@.@@..@"
+;; " @..@@.@@.@@..@"
+;; " @............@"
+;; " @@@@@@@@@@@@@@"))
+;;
+;; (defvar quack-tbi-stop
+;; (quack-make-toolbarimage
+;; " @@@@@ "
+;; " @@rrrrr@@ "
+;; " @rrrrrrrrr@ "
+;; " @rrrrrrrrr@ "
+;; "@rr@@rrr@@rr@"
+;; "@rrr@@r@@rrr@"
+;; "@rrrr@@@rrrr@"
+;; "@rrr@@r@@rrr@"
+;; "@rr@@rrr@@rr@"
+;; " @rrrrrrrrr@ "
+;; " @rrrrrrrrr@ "
+;; " @@rrrrr@@ "
+;; " @@@@@ "))
+;;
+;; (defun quack-install-tool-bar ()
+;; (require 'tool-bar)
+;; (let ((map (make-sparse-keymap)))
+;;
+;; (quack-define-key-after map [quack-load-file]
+;; `(menu-item "quack-evalbuffer" scheme-load-file
+;; :image ,quack-tbi-evalbuf
+;; :help "Load File"))
+;;
+;; (quack-define-key-after map [quack-alpha]
+;; `(menu-item "quack-alpha" quack-alpha
+;; :image ,quack-tbi-adoc
+;; :help "alpha"))
+;;
+;; (quack-define-key-after map [quack-manual]
+;; `(menu-item "quack-manual" quack-manual
+;; :image ,quack-tbi-manual
+;; :help "View Manual"))
+;;
+;; (quack-define-key-after map [quack-view-keyword-docs]
+;; `(menu-item "quack-view-keyword-docs"
+;; quack-view-keyword-docs
+;; :image ,quack-tbi-manuallookup
+;; :help "View Keyword Docs"))
+;;
+;; (quack-define-key-after map [quack-stop]
+;; `(menu-item "quack-stop" quack-stop
+;; :image ,quack-tbi-stop
+;; :help "Stop"))
+;;
+;; (set (make-local-variable 'tool-bar-map) map)))
+
+;; TODO: Extend `scheme-imenu-generic-expression' for PLT-specific definition
+;; forms and for definitions within modules.
+
+;; TODO: Clickable URLs
+;;
+;; (defvar quack-url-keymap)
+;;
+;; (setq quack-url-keymap (make-sparse-keymap))
+;; (define-key quack-url-keymap "\r" 'quack-browse-overlaid-url)
+;; (define-key quack-url-keymap "q" 'quack-browse-overlaid-url)
+;;
+;; (defun quack-make-url-overlay (beg end &optional url)
+;; (let ((ovl (make-overlay beg end nil t)))
+;; (overlay-put ovl 'face 'underline)
+;; (overlay-put ovl 'local-map 'quack-url-keymap)
+;; (overlay-put ovl 'help-echo "Press RET to browse this URL.")
+;; (overlay-put ovl 'quack-url
+;; (or url (buffer-substring-no-properties beg end)))
+;; ovl))
+;;
+;; (defun quack-insert-url (url)
+;; (let* ((beg (point)))
+;; (insert url)
+;; (quack-make-url-overlay beg (point))))
+;;
+;; (defun quack-overlaid-url-at-point (&optional pt)
+;; (let ((overlays (overlays-at (or pt (point))))
+;; (url nil))
+;; (while overlays
+;; (setq overlays (if (setq url (overlay-get (car overlays) 'quack-url))
+;; (cdr overlays)
+;; '())))
+;; url))
+;;
+;; (defun quack-browse-overlaid-url (pt)
+;; ;; Dehydration.
+;; (interactive "d")
+;; (quack-browse-url (quack-overlaid-url-at-point pt)))
+
+;; TODO: Possible Future Inferior Process I/O Stuff. Make encoding with
+;; inferior process disambiguate REPL values, port output, error info,
+;; etc. Start of code commented out below. This may require rewriting
+;; chunks of `cmuscheme' and `comint'.
+;;
+;; Try to use ELI protocol first. http://www.cliki.net/ELI
+;;
+;; (defface quack-output-face
+;; '((((class color)) (:foreground "purple4" :background "lavender"))
+;; (t (:inverse-video t)))
+;; "Face used for..."
+;; :group 'quack)
+;;
+;; (defface quack-value-face
+;; '((((class color)) (:foreground "blue4" :background "light sky blue"))
+;; (t (:inverse-video t)))
+;; "Face used for..."
+;; :group 'quack)
+;;
+;; Escape Codes:
+;; REPL State:
+;; R repl read begin
+;; r repl read end
+;; E repl eval begin
+;; e repl eval end
+;; P repl print begin
+;; p repl print end
+;; Stream Change:
+;; O output stream
+;; E error stream
+;; Error Info?
+;;
+;; (defconst quack-mzscheme-init-string
+;; (let ((print-length nil)
+;; (print-level nil))
+;; (prin1-to-string
+;; '(let ((o (current-output-port))
+;; (i (current-input-port))
+;; (e (current-eval)))
+;; ;; TODO: Define custom escaping output and error ports here.
+;; (current-prompt-read
+;; (lambda ()
+;; (display "\eR" o)
+;; (begin0 (read-syntax "quack-repl" i)
+;; (display "\er" o))))
+;; (current-eval
+;; (lambda (n)
+;; (display "\eE" o)
+;; (begin0 (e n)
+;; (display "\ee" o))))
+;; (current-print
+;; (lambda (n)
+;; (display "\eP" o)
+;; (begin0 (print n o)
+;; (display "\ep" o))))))))
+;;
+;; In `quack' function, after call to `run-scheme':
+;;
+;; (add-hook 'comint-preoutput-filter-functions
+;; 'quack-comint-preoutput-filter-func)
+;; (comint-send-string (scheme-proc) quack-mzscheme-init-string)
+;; (comint-send-string (scheme-proc) "\n")
+
+;; TODO: If we do that, then add pretty-printing of REPL results.
+
+;; TODO: Maybe provide utilities for converting to/from PLT-style
+;; square-bracket paren conventions.
+
+;; TODO: Populate abbrevs table from keywords extracted from manuals, and from
+;; definitions in current buffer. Or maybe query running MzScheme
+;; process for bound symbols.
+
+;; TODO: Maybe use `compile-zos' to do error-checking for PLT (look up person
+;; to credit with idea of using that to get more warnings). Need to know
+;; more about a particular Scheme implementation than just the command
+;; line to start its REPL, though.
+
+;; TODO: Perhaps put some initialization code that depends on user's custom
+;; settings into after-init-hook. See if this works in XEmacs.
+
+;; TODO: Set `interpreter-mode-alist' based on interpreter list.
+
+;; TODO: "I think it would be good if the quack menu showed up only when emacs
+;; was in Scheme mode."
+
+;; TODO: Support this:
+;;
+;; * Added 'addon-dir for `find-system-path':
+;; Unix: "~/.plt-scheme"
+;; Windows: "PLT Scheme" in the user's Application Data folder.
+;; Mac OS X: "~/Library/PLT Scheme"
+;; Mac OS Classic: "PLT Scheme" in the preferences folder.
+;;
+;; The version string for "~/.plt-scheme/<version>/collects/" might be:
+;; mzscheme -mqe '(begin (display (version)) (exit))'
+;; Double-check PLT source first.
+
+;; TODO: Add autoindenting to inferior Scheme buffer when pressing RET on an
+;; incomplete sexp -- iff we can do this reliably enough.
+
+;; TODO: When tidying and point is within a series of multiple blank lines that
+;; are reduced to a single blank line, leave point at the beginning of
+;; the single blank line.
+
+;; TODO: Riastradh says: Do you suppose you could add a feature to Quack that
+;; indents lists beginning with symbols of the form WITH-... &
+;; CALL-WITH-... as if their SCHEME-INDENT-FUNCTION property were DEFUN?
+
+;; TODO: Matt Dickerson asks " Also, the command history appears to be based on
+;; newlines -- I work with blocks of code in the REPL and would like C-p
+;; to give me the last block, not the last line of the previous block."
+
+;; TODO: Maybe get appropriate PLT collection path from the default for
+;; whatever "mzscheme" executable is picked up.
+;;
+;; mzscheme -emq '(begin (write (current-library-collection-paths)) (exit 0))'
+;; ("/home/neil/collects" "/home/neil/.plt-scheme/208/collects"
+;; "/usr/lib/plt/collects")
+
+;; TODO: Bind M-[ to quack-insert-parentheses
+
+;; TODO: Peter Barabas reports that `quack-global-menu-p' set to nil doesn't
+;; disable the menu.
+
+;; TODO: Way to get default collects directories. From Matthew Flatt,
+;; 2006-04-22:
+;;
+;; env PLTCOLLECTS="" mzscheme -mvqe '(printf "~s\n" (map path->string
+;; (current-library-collection-paths)))'
+
+;; TODO: Have key binding to insert "lambda" (for use with pretty-lambda).
+;; Suggested by Olwe Bottorff on 2006-04-20.
+
+;; TODO: Jerry van Dijk writes: "I would like to try out quack, but I do not
+;; like its menu constantly on the main menu bar (as I use emacs for a lot of
+;; things). Unfortunately sofar quack has bravely defied all my attempts to
+;; remove it. From desecting the customize option to adding (define-key
+;; global-map [menu-bar quack] nil)"
+
+;; TODO: We could do this:
+;;
+;; mzscheme -m -e "(begin (display #\') (write (map path->string (current-library-collection-paths))) (newline) (exit))"
+;; '("/home/neil/collects"
+;; "/home/neil/.plt-scheme/360/collects"
+;; "/usr/lib/plt/collects")
+
+;; emacs22 -batch -no-site-file -f batch-byte-compile quack.el ; rm quack.elc
+;; emacs21 -batch -no-site-file -f batch-byte-compile quack.el ; rm quack.elc
+;; emacs20 -batch -no-site-file -f batch-byte-compile quack.el ; rm quack.elc
+;; xemacs21 -batch -no-site-file -f batch-byte-compile quack.el ; rm quack.elc
+
+;; End:
+
+(provide 'quack)
+
+;; quack.el ends here
--- /dev/null
+;;;
+;; Smart Tab
+
+(defvar smart-tab-using-hippie-expand 't
+ "turn this on if you want to use hippie-expand completion.")
+
+;; (global-set-key [(tab)] 'smart-tab)
+(defun smart-tab (prefix)
+ "Needs `transient-mark-mode' to be on. This smart tab is
+minibuffer compliant: it acts as usual in the minibuffer.
+
+In all other buffers: if PREFIX is \\[universal-argument], calls
+`smart-indent'. Else if point is at the end of a symbol,
+expands it. Else calls `smart-indent'."
+ (interactive "P")
+ (if (minibufferp)
+ (minibuffer-complete)
+ (if (smart-tab-must-expand prefix)
+ (if smart-tab-using-hippie-expand
+ (hippie-expand nil)
+ (dabbrev-expand nil))
+ (smart-indent))))
+
+(defun smart-indent ()
+ "Indents region if mark is active, or current line otherwise."
+ (interactive)
+ (if mark-active
+ (indent-region (region-beginning)
+ (region-end))
+ (indent-for-tab-command)))
+
+(defun smart-tab-must-expand (&optional prefix)
+ "If PREFIX is \\[universal-argument], answers no.
+Otherwise, analyses point position and answers."
+ (unless (or (consp prefix)
+ mark-active)
+ (looking-at "\\_>")))
--- /dev/null
+;;;
+;; Smart Tab
+
+(defvar smart-tab-using-hippie-expand nil
+ "turn this on if you want to use hippie-expand completion.")
+
+;; (global-set-key [(tab)] 'smart-tab)
+(defun smart-tab (prefix)
+ "Needs `transient-mark-mode' to be on. This smart tab is
+minibuffer compliant: it acts as usual in the minibuffer.
+
+In all other buffers: if PREFIX is \\[universal-argument], calls
+`smart-indent'. Else if point is at the end of a symbol,
+expands it. Else calls `smart-indent'."
+ (interactive "P")
+ (if (minibufferp)
+ (minibuffer-complete)
+ (if (smart-tab-must-expand prefix)
+ (if smart-tab-using-hippie-expand
+ (hippie-expand nil)
+ (dabbrev-expand nil))
+ (smart-indent))))
+
+(defun smart-indent ()
+ "Indents region if mark is active, or current line otherwise."
+ (interactive)
+ (if mark-active
+ (indent-region (region-beginning)
+ (region-end))
+ (indent-for-tab-command)))
+
+(defun smart-tab-must-expand (&optional prefix)
+ "If PREFIX is \\[universal-argument], answers no.
+Otherwise, analyses point position and answers."
+ (unless (or (consp prefix)
+ mark-active)
+ (looking-at "\\_>")))
--- /dev/null
+;;;
+;;
+;; write-or-die.el
+;; version 0.1, 2008-11-20
+;;
+;; An emacs version of Dr. Wicked's "Write-or-die" webapp, by Duncan Mortimer <dmorti@gmail.com>
+;;
+;; As soon as it is write-or-die-go is invoked, the time spent writing and the number of
+;; words written are tracked.
+;;
+;; However, if you stop writing for some period of time, the buffer
+;; changes colour to give you some warning, and then words are deleted
+;; from the end of the document at a rate of 1 per second. Beginning
+;; writing again stops this.
+;;
+;; TODO:
+;;
+;; - Need to work out what variables need to be made buffer-local etc.
+;; They don't behave quite as I expected them to...
+;; - Reinstate write-or-die-timer each second, rather than use the repeat feature.
+;; (i.e. so that bad things don't happen if emacs happens to freeze for a while...)
+;; - Get it to work smoothely with colour themes; i.e. instead of changing to a white background by
+;; default, need to change to the initial background colour. (17/12/2008)
+;;
+;; Please let me know if this is useful to you, or if you have any suggestions!
+
+(require 'timer)
+
+(define-minor-mode write-or-die-mode
+ "A mode to keep you motivated to continue writing. Based on
+ 'write-or-die' by Dr. Wicked (http://lab.drwicked.com/writeordie.html)."
+ :lighter write-or-die-mode-text
+ :group write-or-die
+ (if write-or-die-mode
+ (add-hook 'post-command-hook 'write-or-die-post-command-hook)
+ (progn
+ (write-or-die-stop)
+ (remove-hook 'post-command-hook 'write-or-die-post-command-hook))))
+
+;; Customisable variables
+(defcustom write-or-die-target-words 500
+ "The target number of words to be written after write-or-die-go is invoked."
+ :group 'write-or-die)
+(defcustom write-or-die-target-time 1200
+ "The target time (in seconds) for which you want to write after
+ write-or-die-go is invoked."
+ :group 'write-or-die)
+(defcustom write-or-die-progress-format " [%s of %s, TIMER: %s]"
+ "A format string that controls how your current progress is
+displayed"
+ :group 'write-or-die)
+(defcustom write-or-die-warning-period 10
+ "Number of seconds of idleness before warning occurs."
+ :group 'write-or-die)
+(defcustom write-or-die-grace-period 20
+ "Number of seconds of idleness before aversive stimulus occurs."
+ :group 'write-or-die)
+
+;; Working variables:
+(defvar write-or-die-mode-text " Write!")
+
+; state = 0: off
+; state = 1: on and going well
+; state = 2: warning
+; state = 3: Zap!!
+(defvar write-or-die-state 0)
+
+; number of words when 'write-or-die-go' most recently called
+(defvar write-or-die-num-words-begin 0)
+
+; timers:
+; write-or-die-timer:
+; how long since 'w-o-d-go' called, with w-o-d-state = 0
+; write-or-die-warning-timer:
+; sets the state to 2 when w-o-d-warning-period seconds pass while idle.
+; write-or-die-grace-timer:
+; sets the state to 3 when w-o-d-grace-period seconds pass while idle.
+(defvar write-or-die-timer nil)
+(defvar write-or-die-warning-timer nil)
+(defvar write-or-die-grace-timer nil)
+
+(defvar write-or-die-time-so-far 0)
+(make-variable-buffer-local 'write-or-die-time-so-far)
+
+(defun write-or-die-update ()
+ "This is called every second, and updates word count etc. / calls
+warning routine or stimulus routine."
+ (if (> write-or-die-state 0)
+ (let (
+ (num-words-written
+ (- (word-count) write-or-die-num-words-begin))
+ (time-to-go
+ (- write-or-die-target-time write-or-die-time-so-far)))
+ (setq write-or-die-time-so-far
+ (+ 1 write-or-die-time-so-far))
+ (setq write-or-die-mode-text
+ (format write-or-die-progress-format
+ num-words-written
+ write-or-die-target-words
+ time-to-go))
+ )
+ (setq write-or-die-mode-text " write!"))
+ ;; If we're being warned about not concentrating on our writing....
+ (if (> write-or-die-state 1)
+ (write-or-die-warning)
+ (modify-frame-parameters nil '((background-color . "White"))))
+ ;; If we're being punished for not writing for too long!
+ (if (> write-or-die-state 2)
+ (write-or-die-stimulus))
+
+ (force-mode-line-update)
+ )
+
+(defun write-or-die-post-command-hook ()
+ "Used to reset the 'stimulus/warning' after you start typing again..."
+ (if (> write-or-die-state 1)
+ (setq write-or-die-state 1))
+ )
+
+(defun word-count nil
+ "Count words in buffer"
+ (how-many "\\w+" (point-min) (point-max))
+)
+
+(defun write-or-die-go ()
+ "Start incentivised writing!"
+ (interactive)
+ (if (= 0 write-or-die-state)
+ (progn
+ (setq write-or-die-state 1)
+ (setq write-or-die-num-words-begin (word-count))
+ (setq write-or-die-time-so-far 0)
+ (setq write-or-die-timer
+ (run-with-timer
+ 0 1 ;; i.e. update once per second, starting NOW!
+ 'write-or-die-update))
+ (setq write-or-die-warning-timer
+ (run-with-idle-timer write-or-die-warning-period
+ 1
+ (lambda () (setq write-or-die-state 2))))
+ (setq write-or-die-grace-timer
+ (run-with-idle-timer write-or-die-grace-period
+ 1
+ (lambda () (setq write-or-die-state 3))))
+ )))
+
+(defun write-or-die-stop ()
+ "Stop incentivised writing!"
+ (interactive)
+ (setq write-or-die-state 0)
+ (cancel-timer write-or-die-timer)
+ (cancel-timer write-or-die-warning-timer)
+ (cancel-timer write-or-die-grace-timer)
+ (modify-frame-parameters nil '((background-color . "White")))
+ (write-or-die-update)
+)
+
+(defun write-or-die-warning ()
+ (modify-frame-parameters nil '((background-color . "Red")))
+)
+
+(defun write-or-die-stimulus ()
+ (backward-kill-word 1))
+
+(provide 'write-or-die)