2009-09-28 01:39:27 +00:00
|
|
|
|
;;; mode-local.el --- Support for mode local facilities
|
|
|
|
|
;;
|
2015-01-01 14:26:41 -08:00
|
|
|
|
;; Copyright (C) 2004-2005, 2007-2015 Free Software Foundation, Inc.
|
2009-09-28 01:39:27 +00:00
|
|
|
|
;;
|
|
|
|
|
;; Author: David Ponce <david@dponce.com>
|
|
|
|
|
;; Maintainer: David Ponce <david@dponce.com>
|
|
|
|
|
;; Created: 27 Apr 2004
|
|
|
|
|
;; Keywords: syntax
|
|
|
|
|
|
|
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
|
|
|
|
|
|
;; GNU Emacs is free software: you can redistribute it and/or modify
|
|
|
|
|
;; it under the terms of the GNU General Public License as published by
|
|
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
;; (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
|
|
|
|
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
;;
|
|
|
|
|
;; Each major mode will want to support a specific set of behaviors.
|
|
|
|
|
;; Usually generic behaviors that need just a little bit of local
|
|
|
|
|
;; specifics.
|
|
|
|
|
;;
|
|
|
|
|
;; This library permits the setting of override functions for tasks of
|
|
|
|
|
;; that nature, and also provides reasonable defaults.
|
|
|
|
|
;;
|
|
|
|
|
;; There are buffer local variables, and frame local variables.
|
|
|
|
|
;; This library gives the illusion of mode specific variables.
|
|
|
|
|
;;
|
|
|
|
|
;; You should use a mode-local variable or override to allow extension
|
|
|
|
|
;; only if you expect a mode author to provide that extension. If a
|
2011-11-20 04:48:53 +01:00
|
|
|
|
;; user might wish to customize a given variable or function then
|
2009-09-28 01:39:27 +00:00
|
|
|
|
;; the existing customization mechanism should be used.
|
|
|
|
|
|
|
|
|
|
;; To Do:
|
|
|
|
|
;; Allow customization of a variable for a specific mode?
|
|
|
|
|
;;
|
|
|
|
|
;; Add macro for defining the '-default' functionality.
|
|
|
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
|
|
|
|
|
(eval-when-compile (require 'cl))
|
|
|
|
|
|
2015-08-26 16:43:29 -05:00
|
|
|
|
(require 'find-func)
|
|
|
|
|
;; For find-function-regexp-alist. It is tempting to replace this
|
2015-09-03 15:31:12 -07:00
|
|
|
|
;; ‘require’ by (defvar find-function-regexp-alist) and
|
2015-08-26 16:43:29 -05:00
|
|
|
|
;; with-eval-after-load, but model-local.el is typically loaded when a
|
|
|
|
|
;; semantic autoload is invoked, and something in semantic loads
|
|
|
|
|
;; find-func.el before mode-local.el, so the eval-after-load is lost.
|
|
|
|
|
|
2009-09-28 01:39:27 +00:00
|
|
|
|
;;; Misc utilities
|
|
|
|
|
;;
|
|
|
|
|
(defun mode-local-map-file-buffers (function &optional predicate buffers)
|
|
|
|
|
"Run FUNCTION on every file buffer found.
|
|
|
|
|
FUNCTION does not have arguments; when it is entered `current-buffer'
|
|
|
|
|
is the currently selected file buffer.
|
|
|
|
|
If optional argument PREDICATE is non nil, only select file buffers
|
2011-11-20 04:48:53 +01:00
|
|
|
|
for which the function PREDICATE returns non-nil.
|
2009-09-28 01:39:27 +00:00
|
|
|
|
If optional argument BUFFERS is non-nil, it is a list of buffers to
|
|
|
|
|
walk through. It defaults to `buffer-list'."
|
|
|
|
|
(dolist (b (or buffers (buffer-list)))
|
|
|
|
|
(and (buffer-live-p b) (buffer-file-name b)
|
|
|
|
|
(with-current-buffer b
|
|
|
|
|
(when (or (not predicate) (funcall predicate))
|
|
|
|
|
(funcall function))))))
|
|
|
|
|
|
|
|
|
|
(defsubst get-mode-local-parent (mode)
|
|
|
|
|
"Return the mode parent of the major mode MODE.
|
|
|
|
|
Return nil if MODE has no parent."
|
|
|
|
|
(or (get mode 'mode-local-parent)
|
|
|
|
|
(get mode 'derived-mode-parent)))
|
|
|
|
|
|
2009-11-03 03:22:30 +00:00
|
|
|
|
;; FIXME doc (and function name) seems wrong.
|
|
|
|
|
;; Return a list of MODE and all its parent modes, if any.
|
|
|
|
|
;; Lists parent modes first.
|
2009-09-28 01:39:27 +00:00
|
|
|
|
(defun mode-local-equivalent-mode-p (mode)
|
|
|
|
|
"Is the major-mode in the current buffer equivalent to a mode in MODES."
|
|
|
|
|
(let ((modes nil))
|
|
|
|
|
(while mode
|
|
|
|
|
(setq modes (cons mode modes)
|
|
|
|
|
mode (get-mode-local-parent mode)))
|
|
|
|
|
modes))
|
|
|
|
|
|
|
|
|
|
(defun mode-local-map-mode-buffers (function modes)
|
|
|
|
|
"Run FUNCTION on every file buffer with major mode in MODES.
|
|
|
|
|
MODES can be a symbol or a list of symbols.
|
|
|
|
|
FUNCTION does not have arguments."
|
|
|
|
|
(or (listp modes) (setq modes (list modes)))
|
|
|
|
|
(mode-local-map-file-buffers
|
|
|
|
|
function #'(lambda ()
|
|
|
|
|
(let ((mm (mode-local-equivalent-mode-p major-mode))
|
|
|
|
|
(ans nil))
|
|
|
|
|
(while (and (not ans) mm)
|
|
|
|
|
(setq ans (memq (car mm) modes)
|
|
|
|
|
mm (cdr mm)) )
|
|
|
|
|
ans))))
|
|
|
|
|
|
|
|
|
|
;;; Hook machinery
|
|
|
|
|
;;
|
|
|
|
|
(defvar mode-local-init-hook nil
|
|
|
|
|
"Hook run after a new file buffer is created.
|
|
|
|
|
The current buffer is the newly created file buffer.")
|
|
|
|
|
|
|
|
|
|
(defvar mode-local-changed-mode-buffers nil
|
|
|
|
|
"List of buffers whose `major-mode' has changed recently.")
|
|
|
|
|
|
|
|
|
|
(defvar mode-local--init-mode nil)
|
|
|
|
|
|
|
|
|
|
(defsubst mode-local-initialized-p ()
|
|
|
|
|
"Return non-nil if mode local is initialized in current buffer.
|
|
|
|
|
That is, if the current `major-mode' is equal to the major mode for
|
|
|
|
|
which mode local bindings have been activated."
|
|
|
|
|
(eq mode-local--init-mode major-mode))
|
|
|
|
|
|
|
|
|
|
(defun mode-local-post-major-mode-change ()
|
|
|
|
|
"Initialize mode-local facilities.
|
|
|
|
|
This is run from `find-file-hook', and from `post-command-hook'
|
|
|
|
|
after changing the major mode."
|
|
|
|
|
(remove-hook 'post-command-hook 'mode-local-post-major-mode-change nil)
|
|
|
|
|
(let ((buffers mode-local-changed-mode-buffers))
|
|
|
|
|
(setq mode-local-changed-mode-buffers nil)
|
|
|
|
|
(mode-local-map-file-buffers
|
|
|
|
|
(lambda ()
|
|
|
|
|
;; Make sure variables are set up for this mode.
|
|
|
|
|
(activate-mode-local-bindings)
|
|
|
|
|
(run-hooks 'mode-local-init-hook))
|
|
|
|
|
(lambda ()
|
|
|
|
|
(not (mode-local-initialized-p)))
|
|
|
|
|
buffers)))
|
|
|
|
|
|
|
|
|
|
(defun mode-local-on-major-mode-change ()
|
|
|
|
|
"Function called in `change-major-mode-hook'."
|
|
|
|
|
(add-to-list 'mode-local-changed-mode-buffers (current-buffer))
|
|
|
|
|
(add-hook 'post-command-hook 'mode-local-post-major-mode-change t nil))
|
|
|
|
|
|
|
|
|
|
;;; Mode lineage
|
|
|
|
|
;;
|
|
|
|
|
(defsubst set-mode-local-parent (mode parent)
|
|
|
|
|
"Set parent of major mode MODE to PARENT mode.
|
|
|
|
|
To work properly, this function should be called after PARENT mode
|
|
|
|
|
local variables have been defined."
|
|
|
|
|
(put mode 'mode-local-parent parent)
|
|
|
|
|
;; Refresh mode bindings to get mode local variables inherited from
|
|
|
|
|
;; PARENT. To work properly, the following should be called after
|
|
|
|
|
;; PARENT mode local variables have been defined.
|
|
|
|
|
(mode-local-map-mode-buffers #'activate-mode-local-bindings mode))
|
|
|
|
|
|
|
|
|
|
(defmacro define-child-mode (mode parent &optional docstring)
|
2011-11-20 04:48:53 +01:00
|
|
|
|
"Make major mode MODE inherit behavior from PARENT mode.
|
2009-09-28 01:39:27 +00:00
|
|
|
|
DOCSTRING is optional and not used.
|
|
|
|
|
To work properly, this should be put after PARENT mode local variables
|
|
|
|
|
definition."
|
|
|
|
|
`(set-mode-local-parent ',mode ',parent))
|
|
|
|
|
|
|
|
|
|
(defun mode-local-use-bindings-p (this-mode desired-mode)
|
|
|
|
|
"Return non-nil if THIS-MODE can use bindings of DESIRED-MODE."
|
|
|
|
|
(let ((ans nil))
|
|
|
|
|
(while (and (not ans) this-mode)
|
|
|
|
|
(setq ans (eq this-mode desired-mode))
|
|
|
|
|
(setq this-mode (get-mode-local-parent this-mode)))
|
|
|
|
|
ans))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;; Core bindings API
|
|
|
|
|
;;
|
|
|
|
|
(defvar mode-local-symbol-table nil
|
|
|
|
|
"Buffer local mode bindings.
|
|
|
|
|
These symbols provide a hook for a `major-mode' to specify specific
|
|
|
|
|
behaviors. Use the function `mode-local-bind' to define new bindings.")
|
|
|
|
|
(make-variable-buffer-local 'mode-local-symbol-table)
|
|
|
|
|
|
|
|
|
|
(defvar mode-local-active-mode nil
|
|
|
|
|
"Major mode in which bindings are active.")
|
|
|
|
|
|
|
|
|
|
(defsubst new-mode-local-bindings ()
|
|
|
|
|
"Return a new empty mode bindings symbol table."
|
|
|
|
|
(make-vector 13 0))
|
|
|
|
|
|
|
|
|
|
(defun mode-local-bind (bindings &optional plist mode)
|
|
|
|
|
"Define BINDINGS in the specified environment.
|
|
|
|
|
BINDINGS is a list of (VARIABLE . VALUE).
|
|
|
|
|
Optional argument PLIST is a property list each VARIABLE symbol will
|
|
|
|
|
be set to. The following properties have special meaning:
|
|
|
|
|
|
|
|
|
|
- `constant-flag' if non-nil, prevent to rebind variables.
|
|
|
|
|
- `mode-variable-flag' if non-nil, define mode variables.
|
|
|
|
|
- `override-flag' if non-nil, define override functions.
|
|
|
|
|
|
|
|
|
|
The `override-flag' and `mode-variable-flag' properties are mutually
|
|
|
|
|
exclusive.
|
|
|
|
|
|
|
|
|
|
If optional argument MODE is non-nil, it must be a major mode symbol.
|
|
|
|
|
BINDINGS will be defined globally for this major mode. If MODE is
|
|
|
|
|
nil, BINDINGS will be defined locally in the current buffer, in
|
|
|
|
|
variable `mode-local-symbol-table'. The later should be done in MODE
|
|
|
|
|
hook."
|
|
|
|
|
;; Check plist consistency
|
|
|
|
|
(and (plist-get plist 'mode-variable-flag)
|
|
|
|
|
(plist-get plist 'override-flag)
|
|
|
|
|
(error "Bindings can't be both overrides and mode variables"))
|
|
|
|
|
(let (table variable varname value binding)
|
|
|
|
|
(if mode
|
|
|
|
|
(progn
|
|
|
|
|
;; Install in given MODE symbol table. Create a new one if
|
|
|
|
|
;; needed.
|
|
|
|
|
(setq table (or (get mode 'mode-local-symbol-table)
|
|
|
|
|
(new-mode-local-bindings)))
|
|
|
|
|
(put mode 'mode-local-symbol-table table))
|
|
|
|
|
;; Fail if trying to bind mode variables in local context!
|
|
|
|
|
(if (plist-get plist 'mode-variable-flag)
|
|
|
|
|
(error "Mode required to bind mode variables"))
|
|
|
|
|
;; Install in buffer local symbol table. Create a new one if
|
|
|
|
|
;; needed.
|
|
|
|
|
(setq table (or mode-local-symbol-table
|
|
|
|
|
(setq mode-local-symbol-table
|
|
|
|
|
(new-mode-local-bindings)))))
|
|
|
|
|
(while bindings
|
|
|
|
|
(setq binding (car bindings)
|
|
|
|
|
bindings (cdr bindings)
|
|
|
|
|
varname (symbol-name (car binding))
|
|
|
|
|
value (cdr binding))
|
|
|
|
|
(if (setq variable (intern-soft varname table))
|
|
|
|
|
;; Binding already exists
|
|
|
|
|
;; Check rebind consistency
|
|
|
|
|
(cond
|
|
|
|
|
((equal (symbol-value variable) value)
|
|
|
|
|
;; Just ignore rebind with the same value.
|
|
|
|
|
)
|
|
|
|
|
((get variable 'constant-flag)
|
|
|
|
|
(error "Can't change the value of constant `%s'"
|
|
|
|
|
variable))
|
|
|
|
|
((and (get variable 'mode-variable-flag)
|
|
|
|
|
(plist-get plist 'override-flag))
|
|
|
|
|
(error "Can't rebind override `%s' as a mode variable"
|
|
|
|
|
variable))
|
|
|
|
|
((and (get variable 'override-flag)
|
|
|
|
|
(plist-get plist 'mode-variable-flag))
|
|
|
|
|
(error "Can't rebind mode variable `%s' as an override"
|
|
|
|
|
variable))
|
|
|
|
|
(t
|
|
|
|
|
;; Merge plist and assign new value
|
|
|
|
|
(setplist variable (append plist (symbol-plist variable)))
|
|
|
|
|
(set variable value)))
|
|
|
|
|
;; New binding
|
|
|
|
|
(setq variable (intern varname table))
|
|
|
|
|
;; Set new plist and assign initial value
|
|
|
|
|
(setplist variable plist)
|
|
|
|
|
(set variable value)))
|
|
|
|
|
;; Return the symbol table used
|
|
|
|
|
table))
|
|
|
|
|
|
|
|
|
|
(defsubst mode-local-symbol (symbol &optional mode)
|
|
|
|
|
"Return the mode local symbol bound with SYMBOL's name.
|
|
|
|
|
Return nil if the mode local symbol doesn't exist.
|
|
|
|
|
If optional argument MODE is nil, lookup first into locally bound
|
|
|
|
|
symbols, then in those bound in current `major-mode' and its parents.
|
|
|
|
|
If MODE is non-nil, lookup into symbols bound in that major mode and
|
|
|
|
|
its parents."
|
|
|
|
|
(let ((name (symbol-name symbol)) bind)
|
|
|
|
|
(or mode
|
|
|
|
|
(setq mode mode-local-active-mode)
|
|
|
|
|
(setq mode major-mode
|
|
|
|
|
bind (and mode-local-symbol-table
|
|
|
|
|
(intern-soft name mode-local-symbol-table))))
|
|
|
|
|
(while (and mode (not bind))
|
|
|
|
|
(or (and (get mode 'mode-local-symbol-table)
|
|
|
|
|
(setq bind (intern-soft
|
|
|
|
|
name (get mode 'mode-local-symbol-table))))
|
|
|
|
|
(setq mode (get-mode-local-parent mode))))
|
|
|
|
|
bind))
|
|
|
|
|
|
|
|
|
|
(defsubst mode-local-symbol-value (symbol &optional mode property)
|
|
|
|
|
"Return the value of the mode local symbol bound with SYMBOL's name.
|
|
|
|
|
If optional argument MODE is non-nil, restrict lookup to that mode and
|
|
|
|
|
its parents (see the function `mode-local-symbol' for more details).
|
|
|
|
|
If optional argument PROPERTY is non-nil the mode local symbol must
|
|
|
|
|
have that property set. Return nil if the symbol doesn't exist, or
|
|
|
|
|
doesn't have PROPERTY set."
|
|
|
|
|
(and (setq symbol (mode-local-symbol symbol mode))
|
|
|
|
|
(or (not property) (get symbol property))
|
|
|
|
|
(symbol-value symbol)))
|
|
|
|
|
|
|
|
|
|
;;; Mode local variables
|
|
|
|
|
;;
|
|
|
|
|
(defun activate-mode-local-bindings (&optional mode)
|
|
|
|
|
"Activate variables defined locally in MODE and its parents.
|
|
|
|
|
That is, copy mode local bindings into corresponding buffer local
|
|
|
|
|
variables.
|
|
|
|
|
If MODE is not specified it defaults to current `major-mode'.
|
|
|
|
|
Return the alist of buffer-local variables that have been changed.
|
|
|
|
|
Elements are (SYMBOL . PREVIOUS-VALUE), describing one variable."
|
|
|
|
|
;; Hack -
|
|
|
|
|
;; do not do this if we are inside set-auto-mode as we may be in
|
|
|
|
|
;; an initialization race condition.
|
|
|
|
|
(if (or (and (featurep 'emacs) (boundp 'keep-mode-if-same))
|
|
|
|
|
(and (featurep 'xemacs) (boundp 'just-from-file-name)))
|
|
|
|
|
;; We are inside set-auto-mode, as this is an argument that is
|
|
|
|
|
;; vaguely unique.
|
|
|
|
|
|
|
|
|
|
;; This will make sure that when everything is over, this will get
|
|
|
|
|
;; called and we won't be under set-auto-mode anymore.
|
|
|
|
|
(mode-local-on-major-mode-change)
|
|
|
|
|
|
|
|
|
|
;; Do the normal thing.
|
|
|
|
|
(let (modes table old-locals)
|
|
|
|
|
(unless mode
|
|
|
|
|
(set (make-local-variable 'mode-local--init-mode) major-mode)
|
|
|
|
|
(setq mode major-mode))
|
|
|
|
|
;; Get MODE's parents & MODE in the right order.
|
|
|
|
|
(while mode
|
|
|
|
|
(setq modes (cons mode modes)
|
|
|
|
|
mode (get-mode-local-parent mode)))
|
|
|
|
|
;; Activate mode bindings following parent modes order.
|
|
|
|
|
(dolist (mode modes)
|
|
|
|
|
(when (setq table (get mode 'mode-local-symbol-table))
|
|
|
|
|
(mapatoms
|
|
|
|
|
#'(lambda (var)
|
|
|
|
|
(when (get var 'mode-variable-flag)
|
|
|
|
|
(let ((v (intern (symbol-name var))))
|
|
|
|
|
;; Save the current buffer-local value of the
|
|
|
|
|
;; mode-local variable.
|
|
|
|
|
(and (local-variable-p v (current-buffer))
|
|
|
|
|
(push (cons v (symbol-value v)) old-locals))
|
|
|
|
|
(set (make-local-variable v) (symbol-value var)))))
|
|
|
|
|
table)))
|
|
|
|
|
old-locals)))
|
|
|
|
|
|
|
|
|
|
(defun deactivate-mode-local-bindings (&optional mode)
|
|
|
|
|
"Deactivate variables defined locally in MODE and its parents.
|
|
|
|
|
That is, kill buffer local variables set from the corresponding mode
|
|
|
|
|
local bindings.
|
|
|
|
|
If MODE is not specified it defaults to current `major-mode'."
|
|
|
|
|
(unless mode
|
|
|
|
|
(kill-local-variable 'mode-local--init-mode)
|
|
|
|
|
(setq mode major-mode))
|
|
|
|
|
(let (table)
|
|
|
|
|
(while mode
|
|
|
|
|
(when (setq table (get mode 'mode-local-symbol-table))
|
|
|
|
|
(mapatoms
|
|
|
|
|
#'(lambda (var)
|
|
|
|
|
(when (get var 'mode-variable-flag)
|
|
|
|
|
(kill-local-variable (intern (symbol-name var)))))
|
|
|
|
|
table))
|
|
|
|
|
(setq mode (get-mode-local-parent mode)))))
|
|
|
|
|
|
|
|
|
|
(defmacro with-mode-local-symbol (mode &rest body)
|
|
|
|
|
"With the local bindings of MODE symbol, evaluate BODY.
|
|
|
|
|
The current mode bindings are saved, BODY is evaluated, and the saved
|
|
|
|
|
bindings are restored, even in case of an abnormal exit.
|
|
|
|
|
Value is what BODY returns.
|
|
|
|
|
This is like `with-mode-local', except that MODE's value is used.
|
|
|
|
|
To use the symbol MODE (quoted), use `with-mode-local'."
|
|
|
|
|
(let ((old-mode (make-symbol "mode"))
|
|
|
|
|
(old-locals (make-symbol "old-locals"))
|
|
|
|
|
(new-mode (make-symbol "new-mode"))
|
|
|
|
|
(local (make-symbol "local")))
|
|
|
|
|
`(let ((,old-mode mode-local-active-mode)
|
|
|
|
|
(,old-locals nil)
|
|
|
|
|
(,new-mode ,mode)
|
|
|
|
|
)
|
|
|
|
|
(unwind-protect
|
|
|
|
|
(progn
|
|
|
|
|
(deactivate-mode-local-bindings ,old-mode)
|
|
|
|
|
(setq mode-local-active-mode ,new-mode)
|
|
|
|
|
;; Save the previous value of buffer-local variables
|
|
|
|
|
;; changed by `activate-mode-local-bindings'.
|
|
|
|
|
(setq ,old-locals (activate-mode-local-bindings ,new-mode))
|
|
|
|
|
,@body)
|
|
|
|
|
(deactivate-mode-local-bindings ,new-mode)
|
|
|
|
|
;; Restore the previous value of buffer-local variables.
|
|
|
|
|
(dolist (,local ,old-locals)
|
|
|
|
|
(set (car ,local) (cdr ,local)))
|
|
|
|
|
;; Restore the mode local variables.
|
|
|
|
|
(setq mode-local-active-mode ,old-mode)
|
|
|
|
|
(activate-mode-local-bindings ,old-mode)))))
|
|
|
|
|
(put 'with-mode-local-symbol 'lisp-indent-function 1)
|
|
|
|
|
|
|
|
|
|
(defmacro with-mode-local (mode &rest body)
|
|
|
|
|
"With the local bindings of MODE, evaluate BODY.
|
|
|
|
|
The current mode bindings are saved, BODY is evaluated, and the saved
|
|
|
|
|
bindings are restored, even in case of an abnormal exit.
|
|
|
|
|
Value is what BODY returns.
|
2009-11-03 03:22:30 +00:00
|
|
|
|
This is like `with-mode-local-symbol', except that MODE is quoted
|
2009-11-03 03:29:19 +00:00
|
|
|
|
and is not evaluated."
|
2009-09-28 01:39:27 +00:00
|
|
|
|
`(with-mode-local-symbol ',mode ,@body))
|
|
|
|
|
(put 'with-mode-local 'lisp-indent-function 1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(defsubst mode-local-value (mode sym)
|
|
|
|
|
"Return the value of the MODE local variable SYM."
|
|
|
|
|
(or mode (error "Missing major mode symbol"))
|
|
|
|
|
(mode-local-symbol-value sym mode 'mode-variable-flag))
|
|
|
|
|
|
|
|
|
|
(defmacro setq-mode-local (mode &rest args)
|
|
|
|
|
"Assign new values to variables local in MODE.
|
|
|
|
|
MODE must be a major mode symbol.
|
|
|
|
|
ARGS is a list (SYM VAL SYM VAL ...).
|
|
|
|
|
The symbols SYM are variables; they are literal (not evaluated).
|
|
|
|
|
The values VAL are expressions; they are evaluated.
|
|
|
|
|
Set each SYM to the value of its VAL, locally in buffers already in
|
|
|
|
|
MODE, or in buffers switched to that mode.
|
|
|
|
|
Return the value of the last VAL."
|
|
|
|
|
(when args
|
|
|
|
|
(let (i ll bl sl tmp sym val)
|
|
|
|
|
(setq i 0)
|
|
|
|
|
(while args
|
|
|
|
|
(setq tmp (make-symbol (format "tmp%d" i))
|
|
|
|
|
i (1+ i)
|
|
|
|
|
sym (car args)
|
|
|
|
|
val (cadr args)
|
|
|
|
|
ll (cons (list tmp val) ll)
|
|
|
|
|
bl (cons `(cons ',sym ,tmp) bl)
|
|
|
|
|
sl (cons `(set (make-local-variable ',sym) ,tmp) sl)
|
|
|
|
|
args (cddr args)))
|
|
|
|
|
`(let* ,(nreverse ll)
|
|
|
|
|
;; Save mode bindings
|
|
|
|
|
(mode-local-bind (list ,@bl) '(mode-variable-flag t) ',mode)
|
|
|
|
|
;; Assign to local variables in all existing buffers in MODE
|
|
|
|
|
(mode-local-map-mode-buffers #'(lambda () ,@sl) ',mode)
|
|
|
|
|
;; Return the last value
|
|
|
|
|
,tmp)
|
|
|
|
|
)))
|
|
|
|
|
|
|
|
|
|
(defmacro defvar-mode-local (mode sym val &optional docstring)
|
|
|
|
|
"Define MODE local variable SYM with value VAL.
|
|
|
|
|
DOCSTRING is optional."
|
|
|
|
|
`(progn
|
|
|
|
|
(setq-mode-local ,mode ,sym ,val)
|
|
|
|
|
(put (mode-local-symbol ',sym ',mode)
|
|
|
|
|
'variable-documentation ,docstring)
|
|
|
|
|
',sym))
|
|
|
|
|
(put 'defvar-mode-local 'lisp-indent-function 'defun)
|
|
|
|
|
|
|
|
|
|
(defmacro defconst-mode-local (mode sym val &optional docstring)
|
|
|
|
|
"Define MODE local constant SYM with value VAL.
|
|
|
|
|
DOCSTRING is optional."
|
|
|
|
|
(let ((tmp (make-symbol "tmp")))
|
|
|
|
|
`(let (,tmp)
|
|
|
|
|
(setq-mode-local ,mode ,sym ,val)
|
|
|
|
|
(setq ,tmp (mode-local-symbol ',sym ',mode))
|
|
|
|
|
(put ,tmp 'constant-flag t)
|
|
|
|
|
(put ,tmp 'variable-documentation ,docstring)
|
|
|
|
|
',sym)))
|
|
|
|
|
(put 'defconst-mode-local 'lisp-indent-function 'defun)
|
|
|
|
|
|
|
|
|
|
;;; Function overloading
|
|
|
|
|
;;
|
2009-10-28 14:01:49 +00:00
|
|
|
|
(defun make-obsolete-overload (old new when)
|
|
|
|
|
"Mark OLD overload as obsoleted by NEW overload.
|
|
|
|
|
WHEN is a string describing the first release where it was made obsolete."
|
2009-09-28 01:39:27 +00:00
|
|
|
|
(put old 'overload-obsoleted-by new)
|
2009-10-28 14:01:49 +00:00
|
|
|
|
(put old 'overload-obsoleted-since when)
|
2009-09-28 01:39:27 +00:00
|
|
|
|
(put old 'mode-local-overload t)
|
|
|
|
|
(put new 'overload-obsolete old))
|
|
|
|
|
|
|
|
|
|
(defsubst overload-obsoleted-by (overload)
|
|
|
|
|
"Get the overload symbol obsoleted by OVERLOAD.
|
|
|
|
|
Return the obsolete symbol or nil if not found."
|
|
|
|
|
(get overload 'overload-obsolete))
|
|
|
|
|
|
|
|
|
|
(defsubst overload-that-obsolete (overload)
|
|
|
|
|
"Return the overload symbol that obsoletes OVERLOAD.
|
|
|
|
|
Return the symbol found or nil if OVERLOAD is not obsolete."
|
|
|
|
|
(get overload 'overload-obsoleted-by))
|
|
|
|
|
|
|
|
|
|
(defsubst fetch-overload (overload)
|
|
|
|
|
"Return the current OVERLOAD function, or nil if not found.
|
|
|
|
|
First, lookup for OVERLOAD into locally bound mode local symbols, then
|
|
|
|
|
in those bound in current `major-mode' and its parents."
|
|
|
|
|
(or (mode-local-symbol-value overload nil 'override-flag)
|
|
|
|
|
;; If an obsolete overload symbol exists, try it.
|
|
|
|
|
(and (overload-obsoleted-by overload)
|
|
|
|
|
(mode-local-symbol-value
|
|
|
|
|
(overload-obsoleted-by overload) nil 'override-flag))))
|
|
|
|
|
|
|
|
|
|
(defun mode-local--override (name args body)
|
|
|
|
|
"Return the form that handles overloading of function NAME.
|
|
|
|
|
ARGS are the arguments to the function.
|
|
|
|
|
BODY is code that would be run when there is no override defined. The
|
|
|
|
|
default is to call the function `NAME-default' with the appropriate
|
|
|
|
|
arguments.
|
|
|
|
|
See also the function `define-overload'."
|
|
|
|
|
(let* ((default (intern (format "%s-default" name)))
|
|
|
|
|
(overargs (delq '&rest (delq '&optional (copy-sequence args))))
|
|
|
|
|
(override (make-symbol "override")))
|
|
|
|
|
`(let ((,override (fetch-overload ',name)))
|
|
|
|
|
(if ,override
|
|
|
|
|
(funcall ,override ,@overargs)
|
|
|
|
|
,@(or body `((,default ,@overargs)))))
|
|
|
|
|
))
|
|
|
|
|
|
|
|
|
|
(defun mode-local--expand-overrides (name args body)
|
|
|
|
|
"Expand override forms that overload function NAME.
|
|
|
|
|
ARGS are the arguments to the function NAME.
|
|
|
|
|
BODY is code where override forms are searched for expansion.
|
|
|
|
|
Return result of expansion, or BODY if no expansion occurred.
|
|
|
|
|
See also the function `define-overload'."
|
|
|
|
|
(let ((forms body)
|
|
|
|
|
(ditto t)
|
|
|
|
|
form xbody)
|
|
|
|
|
(while forms
|
|
|
|
|
(setq form (car forms))
|
|
|
|
|
(cond
|
|
|
|
|
((atom form))
|
|
|
|
|
((eq (car form) :override)
|
|
|
|
|
(setq form (mode-local--override name args (cdr form))))
|
|
|
|
|
((eq (car form) :override-with-args)
|
|
|
|
|
(setq form (mode-local--override name (cadr form) (cddr form))))
|
|
|
|
|
((setq form (mode-local--expand-overrides name args form))))
|
|
|
|
|
(setq ditto (and ditto (eq (car forms) form))
|
|
|
|
|
xbody (cons form xbody)
|
|
|
|
|
forms (cdr forms)))
|
|
|
|
|
(if ditto body (nreverse xbody))))
|
|
|
|
|
|
|
|
|
|
(defun mode-local--overload-body (name args body)
|
|
|
|
|
"Return the code that implements overloading of function NAME.
|
|
|
|
|
ARGS are the arguments to the function NAME.
|
|
|
|
|
BODY specifies the overload code.
|
|
|
|
|
See also the function `define-overload'."
|
|
|
|
|
(let ((result (mode-local--expand-overrides name args body)))
|
|
|
|
|
(if (eq body result)
|
|
|
|
|
(list (mode-local--override name args body))
|
|
|
|
|
result)))
|
|
|
|
|
|
2012-05-17 21:46:20 -04:00
|
|
|
|
;;;###autoload
|
|
|
|
|
(put 'define-overloadable-function 'doc-string-elt 3)
|
|
|
|
|
|
2009-09-28 01:39:27 +00:00
|
|
|
|
(defmacro define-overloadable-function (name args docstring &rest body)
|
2011-11-20 04:48:53 +01:00
|
|
|
|
"Define a new function, as with `defun', which can be overloaded.
|
2009-09-28 01:39:27 +00:00
|
|
|
|
NAME is the name of the function to create.
|
|
|
|
|
ARGS are the arguments to the function.
|
|
|
|
|
DOCSTRING is a documentation string to describe the function. The
|
2011-11-20 04:48:53 +01:00
|
|
|
|
docstring will automatically have details about its overload symbol
|
2009-09-28 01:39:27 +00:00
|
|
|
|
appended to the end.
|
|
|
|
|
BODY is code that would be run when there is no override defined. The
|
|
|
|
|
default is to call the function `NAME-default' with the appropriate
|
|
|
|
|
arguments.
|
|
|
|
|
|
|
|
|
|
BODY can also include an override form that specifies which part of
|
|
|
|
|
BODY is specifically overridden. This permits to specify common code
|
|
|
|
|
run for both default and overridden implementations.
|
|
|
|
|
An override form is one of:
|
|
|
|
|
|
|
|
|
|
1. (:override [OVERBODY])
|
|
|
|
|
2. (:override-with-args OVERARGS [OVERBODY])
|
|
|
|
|
|
|
|
|
|
OVERBODY is the code that would be run when there is no override
|
|
|
|
|
defined. The default is to call the function `NAME-default' with the
|
|
|
|
|
appropriate arguments deduced from ARGS.
|
|
|
|
|
OVERARGS is a list of arguments passed to the override and
|
|
|
|
|
`NAME-default' function, in place of those deduced from ARGS."
|
2012-05-17 21:46:20 -04:00
|
|
|
|
(declare (doc-string 3))
|
2009-09-28 01:39:27 +00:00
|
|
|
|
`(eval-and-compile
|
|
|
|
|
(defun ,name ,args
|
|
|
|
|
,docstring
|
|
|
|
|
,@(mode-local--overload-body name args body))
|
|
|
|
|
(put ',name 'mode-local-overload t)))
|
|
|
|
|
(put :override-with-args 'lisp-indent-function 1)
|
|
|
|
|
|
|
|
|
|
(defalias 'define-overload 'define-overloadable-function)
|
|
|
|
|
|
|
|
|
|
(defsubst function-overload-p (symbol)
|
|
|
|
|
"Return non-nil if SYMBOL is a function which can be overloaded."
|
|
|
|
|
(and symbol (symbolp symbol) (get symbol 'mode-local-overload)))
|
|
|
|
|
|
|
|
|
|
(defmacro define-mode-local-override
|
|
|
|
|
(name mode args docstring &rest body)
|
|
|
|
|
"Define a mode specific override of the function overload NAME.
|
|
|
|
|
Has meaning only if NAME has been created with `define-overload'.
|
|
|
|
|
MODE is the major mode this override is being defined for.
|
|
|
|
|
ARGS are the function arguments, which should match those of the same
|
|
|
|
|
named function created with `define-overload'.
|
|
|
|
|
DOCSTRING is the documentation string.
|
|
|
|
|
BODY is the implementation of this function."
|
|
|
|
|
(let ((newname (intern (format "%s-%s" name mode))))
|
|
|
|
|
`(progn
|
|
|
|
|
(eval-and-compile
|
|
|
|
|
(defun ,newname ,args
|
|
|
|
|
,(format "%s\n\nOverride %s in `%s' buffers."
|
|
|
|
|
docstring name mode)
|
|
|
|
|
;; The body for this implementation
|
|
|
|
|
,@body)
|
|
|
|
|
;; For find-func to locate the definition of NEWNAME.
|
|
|
|
|
(put ',newname 'definition-name ',name))
|
|
|
|
|
(mode-local-bind '((,name . ,newname))
|
|
|
|
|
'(override-flag t)
|
|
|
|
|
',mode))
|
|
|
|
|
))
|
|
|
|
|
|
|
|
|
|
;;; Read/Query Support
|
|
|
|
|
(defun mode-local-read-function (prompt &optional initial hist default)
|
|
|
|
|
"Interactively read in the name of a mode-local function.
|
|
|
|
|
PROMPT, INITIAL, HIST, and DEFAULT are the same as for `completing-read'."
|
|
|
|
|
(completing-read prompt obarray 'function-overload-p t initial hist default))
|
|
|
|
|
|
|
|
|
|
;;; Help support
|
|
|
|
|
;;
|
|
|
|
|
(defun overload-docstring-extension (overload)
|
|
|
|
|
"Return the doc string that augments the description of OVERLOAD."
|
|
|
|
|
(let ((doc "\n\This function can be overloaded\
|
Improve the optional translation of quotes
Fix several problems with the recently-added custom variable
help-quote-translation where the code would quote inconsistently
in help buffers. Add support for quoting 'like this', which
is common in other GNU programs in ASCII environments. Change
help-quote-translation to use more mnemonic values: values are now the
initial quoting char, e.g., (setq help-quote-translation ?`) gets the
traditional Emacs help-buffer quoting style `like this'. Change the
default behavior of substitute-command-keys to match what's done in
set-locale-environment, i.e., quote ‘like this’ if displayable,
'like this' otherwise.
* doc/lispref/help.texi (Keys in Documentation): Document
new behavior of substitute-command-keys, and document
help-quote-translation.
* doc/lispref/tips.texi (Documentation Tips):
Mention the effect of help-quote-translation.
* etc/NEWS: Mention new behavior of substitute-command-keys,
and merge help-quote-translation news into it.
When talking about doc strings, mention new ways to type quotes.
* lisp/cedet/mode-local.el (overload-docstring-extension):
Revert my recent change to this function, which shouldn't be
needed as the result is a doc string.
* lisp/cedet/mode-local.el (mode-local-print-binding)
(mode-local-describe-bindings-2):
* lisp/cedet/srecode/srt-mode.el (srecode-macro-help):
* lisp/cus-theme.el (describe-theme-1):
* lisp/descr-text.el (describe-text-properties-1, describe-char):
* lisp/emacs-lisp/cl-generic.el (cl--generic-describe):
* lisp/emacs-lisp/eieio-opt.el (eieio-help-class)
(eieio-help-constructor):
* lisp/emacs-lisp/package.el (describe-package-1):
* lisp/faces.el (describe-face):
* lisp/help-fns.el (help-fns--key-bindings)
(help-fns--compiler-macro, help-fns--parent-mode)
(help-fns--obsolete, help-fns--interactive-only)
(describe-function-1, describe-variable):
* lisp/help.el (describe-mode):
Use substitute-command-keys to ensure a more-consistent quoting
style in help buffers.
* lisp/cus-start.el (standard):
Document new help-quote-translation behavior.
* lisp/emacs-lisp/lisp-mode.el (lisp-fdefs):
* lisp/help-mode.el (help-xref-symbol-regexp, help-xref-info-regexp)
(help-xref-url-regexp):
* lisp/international/mule-cmds.el (help-xref-mule-regexp-template):
* lisp/wid-edit.el (widget-documentation-link-regexp):
Also match 'foo', in case we're in a help buffer generated when
help-quote-translation is ?'.
* src/doc.c: Include disptab.h, for DISP_CHAR_VECTOR.
(LEFT_SINGLE_QUOTATION_MARK, uLSQM0, uLSQM1, uLSQM2, uRSQM0)
(uRSQM1, uRSQM2, LSQM, RSQM): New constants.
(Fsubstitute_command_keys): Document and implement new behavior.
(Vhelp_quote_translation): Document new behavior.
2015-06-19 00:35:43 -07:00
|
|
|
|
with `define-mode-local-override'.")
|
2009-09-28 01:39:27 +00:00
|
|
|
|
(sym (overload-obsoleted-by overload)))
|
|
|
|
|
(when sym
|
Improve the optional translation of quotes
Fix several problems with the recently-added custom variable
help-quote-translation where the code would quote inconsistently
in help buffers. Add support for quoting 'like this', which
is common in other GNU programs in ASCII environments. Change
help-quote-translation to use more mnemonic values: values are now the
initial quoting char, e.g., (setq help-quote-translation ?`) gets the
traditional Emacs help-buffer quoting style `like this'. Change the
default behavior of substitute-command-keys to match what's done in
set-locale-environment, i.e., quote ‘like this’ if displayable,
'like this' otherwise.
* doc/lispref/help.texi (Keys in Documentation): Document
new behavior of substitute-command-keys, and document
help-quote-translation.
* doc/lispref/tips.texi (Documentation Tips):
Mention the effect of help-quote-translation.
* etc/NEWS: Mention new behavior of substitute-command-keys,
and merge help-quote-translation news into it.
When talking about doc strings, mention new ways to type quotes.
* lisp/cedet/mode-local.el (overload-docstring-extension):
Revert my recent change to this function, which shouldn't be
needed as the result is a doc string.
* lisp/cedet/mode-local.el (mode-local-print-binding)
(mode-local-describe-bindings-2):
* lisp/cedet/srecode/srt-mode.el (srecode-macro-help):
* lisp/cus-theme.el (describe-theme-1):
* lisp/descr-text.el (describe-text-properties-1, describe-char):
* lisp/emacs-lisp/cl-generic.el (cl--generic-describe):
* lisp/emacs-lisp/eieio-opt.el (eieio-help-class)
(eieio-help-constructor):
* lisp/emacs-lisp/package.el (describe-package-1):
* lisp/faces.el (describe-face):
* lisp/help-fns.el (help-fns--key-bindings)
(help-fns--compiler-macro, help-fns--parent-mode)
(help-fns--obsolete, help-fns--interactive-only)
(describe-function-1, describe-variable):
* lisp/help.el (describe-mode):
Use substitute-command-keys to ensure a more-consistent quoting
style in help buffers.
* lisp/cus-start.el (standard):
Document new help-quote-translation behavior.
* lisp/emacs-lisp/lisp-mode.el (lisp-fdefs):
* lisp/help-mode.el (help-xref-symbol-regexp, help-xref-info-regexp)
(help-xref-url-regexp):
* lisp/international/mule-cmds.el (help-xref-mule-regexp-template):
* lisp/wid-edit.el (widget-documentation-link-regexp):
Also match 'foo', in case we're in a help buffer generated when
help-quote-translation is ?'.
* src/doc.c: Include disptab.h, for DISP_CHAR_VECTOR.
(LEFT_SINGLE_QUOTATION_MARK, uLSQM0, uLSQM1, uLSQM2, uRSQM0)
(uRSQM1, uRSQM2, LSQM, RSQM): New constants.
(Fsubstitute_command_keys): Document and implement new behavior.
(Vhelp_quote_translation): Document new behavior.
2015-06-19 00:35:43 -07:00
|
|
|
|
(setq doc (format "%s\nIt has made the overload `%s' obsolete since %s."
|
2009-10-28 14:01:49 +00:00
|
|
|
|
doc sym (get sym 'overload-obsoleted-since))))
|
2009-09-28 01:39:27 +00:00
|
|
|
|
(setq sym (overload-that-obsolete overload))
|
|
|
|
|
(when sym
|
Improve the optional translation of quotes
Fix several problems with the recently-added custom variable
help-quote-translation where the code would quote inconsistently
in help buffers. Add support for quoting 'like this', which
is common in other GNU programs in ASCII environments. Change
help-quote-translation to use more mnemonic values: values are now the
initial quoting char, e.g., (setq help-quote-translation ?`) gets the
traditional Emacs help-buffer quoting style `like this'. Change the
default behavior of substitute-command-keys to match what's done in
set-locale-environment, i.e., quote ‘like this’ if displayable,
'like this' otherwise.
* doc/lispref/help.texi (Keys in Documentation): Document
new behavior of substitute-command-keys, and document
help-quote-translation.
* doc/lispref/tips.texi (Documentation Tips):
Mention the effect of help-quote-translation.
* etc/NEWS: Mention new behavior of substitute-command-keys,
and merge help-quote-translation news into it.
When talking about doc strings, mention new ways to type quotes.
* lisp/cedet/mode-local.el (overload-docstring-extension):
Revert my recent change to this function, which shouldn't be
needed as the result is a doc string.
* lisp/cedet/mode-local.el (mode-local-print-binding)
(mode-local-describe-bindings-2):
* lisp/cedet/srecode/srt-mode.el (srecode-macro-help):
* lisp/cus-theme.el (describe-theme-1):
* lisp/descr-text.el (describe-text-properties-1, describe-char):
* lisp/emacs-lisp/cl-generic.el (cl--generic-describe):
* lisp/emacs-lisp/eieio-opt.el (eieio-help-class)
(eieio-help-constructor):
* lisp/emacs-lisp/package.el (describe-package-1):
* lisp/faces.el (describe-face):
* lisp/help-fns.el (help-fns--key-bindings)
(help-fns--compiler-macro, help-fns--parent-mode)
(help-fns--obsolete, help-fns--interactive-only)
(describe-function-1, describe-variable):
* lisp/help.el (describe-mode):
Use substitute-command-keys to ensure a more-consistent quoting
style in help buffers.
* lisp/cus-start.el (standard):
Document new help-quote-translation behavior.
* lisp/emacs-lisp/lisp-mode.el (lisp-fdefs):
* lisp/help-mode.el (help-xref-symbol-regexp, help-xref-info-regexp)
(help-xref-url-regexp):
* lisp/international/mule-cmds.el (help-xref-mule-regexp-template):
* lisp/wid-edit.el (widget-documentation-link-regexp):
Also match 'foo', in case we're in a help buffer generated when
help-quote-translation is ?'.
* src/doc.c: Include disptab.h, for DISP_CHAR_VECTOR.
(LEFT_SINGLE_QUOTATION_MARK, uLSQM0, uLSQM1, uLSQM2, uRSQM0)
(uRSQM1, uRSQM2, LSQM, RSQM): New constants.
(Fsubstitute_command_keys): Document and implement new behavior.
(Vhelp_quote_translation): Document new behavior.
2015-06-19 00:35:43 -07:00
|
|
|
|
(setq doc (format "%s\nThis overload is obsolete since %s;\nUse `%s' instead."
|
|
|
|
|
doc (get overload 'overload-obsoleted-since) sym)))
|
2009-09-28 01:39:27 +00:00
|
|
|
|
doc))
|
|
|
|
|
|
|
|
|
|
(defun mode-local-augment-function-help (symbol)
|
|
|
|
|
"Augment the *Help* buffer for SYMBOL.
|
|
|
|
|
SYMBOL is a function that can be overridden."
|
|
|
|
|
(with-current-buffer "*Help*"
|
|
|
|
|
(pop-to-buffer (current-buffer))
|
2010-10-29 00:48:10 -07:00
|
|
|
|
(goto-char (point-min))
|
|
|
|
|
(unless (re-search-forward "^$" nil t)
|
|
|
|
|
(goto-char (point-max))
|
|
|
|
|
(beginning-of-line)
|
|
|
|
|
(forward-line -1))
|
|
|
|
|
(let ((inhibit-read-only t))
|
|
|
|
|
(insert (overload-docstring-extension symbol) "\n")
|
|
|
|
|
;; NOTE TO SELF:
|
|
|
|
|
;; LIST ALL LOADED OVERRIDES FOR SYMBOL HERE
|
|
|
|
|
)))
|
2009-09-28 01:39:27 +00:00
|
|
|
|
|
2015-08-26 15:33:41 -05:00
|
|
|
|
(defun describe-mode-local-overload (symbol)
|
|
|
|
|
"For `help-fns-describe-function-functions'; add overloads for SYMBOL."
|
|
|
|
|
(when (get symbol 'mode-local-overload)
|
|
|
|
|
(let ((default (or (intern-soft (format "%s-default" (symbol-name symbol)))
|
|
|
|
|
symbol))
|
2015-09-01 04:36:05 -05:00
|
|
|
|
(override (with-current-buffer describe-function-orig-buffer
|
|
|
|
|
(fetch-overload symbol)))
|
|
|
|
|
modes)
|
|
|
|
|
|
2015-08-26 15:33:41 -05:00
|
|
|
|
(insert (overload-docstring-extension symbol) "\n\n")
|
2015-08-29 21:40:21 -07:00
|
|
|
|
(insert (format-message "default function: `%s'\n" default))
|
2015-09-01 05:10:52 -05:00
|
|
|
|
(if override
|
|
|
|
|
(insert (format-message "\noverride in buffer '%s': `%s'\n"
|
|
|
|
|
describe-function-orig-buffer override))
|
|
|
|
|
(insert (format-message "\nno override in buffer '%s'\n"
|
|
|
|
|
describe-function-orig-buffer)))
|
2015-09-01 04:36:05 -05:00
|
|
|
|
|
|
|
|
|
(mapatoms
|
|
|
|
|
(lambda (sym) (when (get sym 'mode-local-symbol-table) (push sym modes)))
|
|
|
|
|
obarray)
|
|
|
|
|
|
|
|
|
|
(dolist (mode modes)
|
|
|
|
|
(let* ((major-mode mode)
|
|
|
|
|
(override (fetch-overload symbol)))
|
|
|
|
|
|
|
|
|
|
(when override
|
|
|
|
|
(insert (format-message "\noverride in mode ‘%s’: ’%s’\n"
|
|
|
|
|
major-mode override))
|
|
|
|
|
)))
|
2015-08-26 15:33:41 -05:00
|
|
|
|
)))
|
|
|
|
|
|
|
|
|
|
(add-hook 'help-fns-describe-function-functions 'describe-mode-local-overload)
|
|
|
|
|
|
2015-08-26 16:43:29 -05:00
|
|
|
|
(declare-function xref-item-location "xref" (xref))
|
|
|
|
|
|
|
|
|
|
(defun xref-mode-local--override-present (sym xrefs)
|
|
|
|
|
"Return non-nil if SYM is in XREFS."
|
|
|
|
|
(let (result)
|
|
|
|
|
(while (and (null result)
|
|
|
|
|
xrefs)
|
|
|
|
|
(when (equal sym (car (xref-elisp-location-symbol (xref-item-location (pop xrefs)))))
|
|
|
|
|
(setq result t)))
|
|
|
|
|
result))
|
|
|
|
|
|
|
|
|
|
(defun xref-mode-local-overload (symbol)
|
|
|
|
|
"For ‘elisp-xref-find-def-functions’; add overloads for SYMBOL."
|
|
|
|
|
;; Current buffer is the buffer where xref-find-definitions was invoked.
|
|
|
|
|
(when (get symbol 'mode-local-overload)
|
|
|
|
|
(let* ((symbol-file (find-lisp-object-file-name symbol (symbol-function symbol)))
|
|
|
|
|
(default (intern-soft (format "%s-default" (symbol-name symbol))))
|
|
|
|
|
(default-file (when default (find-lisp-object-file-name default (symbol-function default))))
|
|
|
|
|
modes
|
|
|
|
|
xrefs)
|
|
|
|
|
|
|
|
|
|
(mapatoms
|
|
|
|
|
(lambda (sym) (when (get sym 'mode-local-symbol-table) (push sym modes)))
|
|
|
|
|
obarray)
|
|
|
|
|
|
|
|
|
|
;; mode-local-overrides are inherited from parent modes; we
|
|
|
|
|
;; don't want to list the same function twice. So order ‘modes’
|
|
|
|
|
;; with parents first, and check for duplicates.
|
|
|
|
|
|
|
|
|
|
(setq modes
|
|
|
|
|
(sort modes
|
|
|
|
|
(lambda (a b)
|
|
|
|
|
(not (equal b (get a 'mode-local-parent)))))) ;; a is not a child, or not a child of b
|
|
|
|
|
|
|
|
|
|
(dolist (mode modes)
|
|
|
|
|
(let* ((major-mode mode)
|
|
|
|
|
(override (fetch-overload symbol))
|
|
|
|
|
(override-file (when override (find-lisp-object-file-name override (symbol-function override)))))
|
|
|
|
|
|
|
|
|
|
(when (and override override-file)
|
|
|
|
|
(let ((meta-name (cons override major-mode))
|
|
|
|
|
;; For the declaration:
|
|
|
|
|
;;
|
|
|
|
|
;;(define-mode-local-override xref-elisp-foo c-mode
|
|
|
|
|
;;
|
|
|
|
|
;; The override symbol name is
|
|
|
|
|
;; "xref-elisp-foo-c-mode". The summary should match
|
|
|
|
|
;; the declaration, so strip the mode from the
|
|
|
|
|
;; symbol name.
|
|
|
|
|
(summary (format elisp--xref-format-extra
|
|
|
|
|
'define-mode-local-override
|
|
|
|
|
(substring (symbol-name override) 0 (- (1+ (length (symbol-name major-mode)))))
|
|
|
|
|
major-mode)))
|
|
|
|
|
|
|
|
|
|
(unless (xref-mode-local--override-present override xrefs)
|
|
|
|
|
(push (elisp--xref-make-xref
|
|
|
|
|
'define-mode-local-override meta-name override-file summary)
|
|
|
|
|
xrefs))))))
|
|
|
|
|
|
|
|
|
|
;; %s-default is interned whether it is a separate function or
|
|
|
|
|
;; not, so we have to check that here.
|
|
|
|
|
(when (and (functionp default) default-file)
|
|
|
|
|
(push (elisp--xref-make-xref nil default default-file) xrefs))
|
|
|
|
|
|
|
|
|
|
(when symbol-file
|
|
|
|
|
(push (elisp--xref-make-xref 'define-overloadable-function symbol symbol-file) xrefs))
|
|
|
|
|
|
|
|
|
|
xrefs)))
|
|
|
|
|
|
|
|
|
|
(add-hook 'elisp-xref-find-def-functions 'xref-mode-local-overload)
|
|
|
|
|
|
|
|
|
|
(defconst xref-mode-local-find-overloadable-regexp
|
|
|
|
|
"(\\(\\(define-overloadable-function\\)\\|\\(define-overload\\)\\) +%s"
|
|
|
|
|
"Regexp used by ‘xref-find-definitions’ when searching for a
|
|
|
|
|
mode-local overloadable function definition.")
|
|
|
|
|
|
|
|
|
|
(defun xref-mode-local-find-override (meta-name)
|
|
|
|
|
"Function used by ‘xref-find-definitions’ when searching for an
|
|
|
|
|
override of a mode-local overloadable function.
|
|
|
|
|
META-NAME is a cons (OVERLOADABLE-SYMBOL . MAJOR-MODE)."
|
|
|
|
|
(let* ((override (car meta-name))
|
|
|
|
|
(mode (cdr meta-name))
|
|
|
|
|
(regexp (format "(define-mode-local-override +%s +%s"
|
|
|
|
|
(substring (symbol-name override) 0 (- (1+ (length (symbol-name mode)))))
|
|
|
|
|
mode)))
|
|
|
|
|
(re-search-forward regexp nil t)
|
|
|
|
|
))
|
|
|
|
|
|
|
|
|
|
(add-to-list 'find-function-regexp-alist '(define-overloadable-function . xref-mode-local-find-overloadable-regexp))
|
|
|
|
|
(add-to-list 'find-function-regexp-alist (cons 'define-mode-local-override #'xref-mode-local-find-override))
|
|
|
|
|
|
2009-09-28 01:39:27 +00:00
|
|
|
|
;; Help for mode-local bindings.
|
|
|
|
|
(defun mode-local-print-binding (symbol)
|
|
|
|
|
"Print the SYMBOL binding."
|
|
|
|
|
(let ((value (symbol-value symbol)))
|
More-conservative ‘format’ quote restyling
Instead of restyling curved quotes for every call to ‘format’,
create a new function ‘format-message’ that does the restyling,
and using the new function instead of ‘format’ only in contexts
where this seems appropriate.
Problem reported by Dmitry Gutov and Andreas Schwab in:
http://lists.gnu.org/archive/html/emacs-devel/2015-08/msg00826.html
http://lists.gnu.org/archive/html/emacs-devel/2015-08/msg00827.html
* doc/lispref/commands.texi (Using Interactive):
* doc/lispref/control.texi (Signaling Errors, Signaling Errors):
* doc/lispref/display.texi (Displaying Messages, Progress):
* doc/lispref/elisp.texi:
* doc/lispref/help.texi (Keys in Documentation):
* doc/lispref/minibuf.texi (Minibuffer Misc):
* doc/lispref/strings.texi (Formatting Strings):
* etc/NEWS:
Document the changes.
* lisp/abbrev.el (expand-region-abbrevs):
* lisp/apropos.el (apropos-library):
* lisp/calc/calc-ext.el (calc-record-message)
(calc-user-function-list):
* lisp/calc/calc-help.el (calc-describe-key, calc-full-help):
* lisp/calc/calc-lang.el (math-read-big-balance):
* lisp/calc/calc-store.el (calc-edit-variable):
* lisp/calc/calc-units.el (math-build-units-table-buffer):
* lisp/calc/calc-yank.el (calc-edit-mode):
* lisp/calendar/icalendar.el (icalendar-export-region)
(icalendar--add-diary-entry):
* lisp/cedet/mode-local.el (mode-local-print-binding)
(mode-local-describe-bindings-2):
* lisp/cedet/semantic/complete.el (semantic-completion-message):
* lisp/cedet/semantic/edit.el (semantic-parse-changes-failed):
* lisp/cedet/semantic/wisent/comp.el (wisent-log):
* lisp/cedet/srecode/insert.el (srecode-insert-show-error-report):
* lisp/descr-text.el (describe-text-properties-1, describe-char):
* lisp/dframe.el (dframe-message):
* lisp/dired-aux.el (dired-query):
* lisp/emacs-lisp/byte-opt.el (byte-compile-log-lap-1):
* lisp/emacs-lisp/bytecomp.el (byte-compile-log)
(byte-compile-log-file, byte-compile-warn, byte-compile-form):
* lisp/emacs-lisp/cconv.el (cconv-convert, cconv--analyze-use)
(cconv-analyze-form):
* lisp/emacs-lisp/check-declare.el (check-declare-warn):
* lisp/emacs-lisp/checkdoc.el (checkdoc-this-string-valid-engine):
* lisp/emacs-lisp/cl-macs.el (cl-symbol-macrolet):
* lisp/emacs-lisp/edebug.el (edebug-format):
* lisp/emacs-lisp/eieio-core.el (eieio-oref):
* lisp/emacs-lisp/eldoc.el (eldoc-minibuffer-message)
(eldoc-message):
* lisp/emacs-lisp/elint.el (elint-file, elint-log):
* lisp/emacs-lisp/find-func.el (find-function-library):
* lisp/emacs-lisp/macroexp.el (macroexp--obsolete-warning):
* lisp/emacs-lisp/map-ynp.el (map-y-or-n-p):
* lisp/emacs-lisp/nadvice.el (advice--make-docstring):
* lisp/emacs-lisp/package.el (package-compute-transaction)
(package-install-button-action, package-delete-button-action)
(package-menu--list-to-prompt):
* lisp/emacs-lisp/timer.el (timer-event-handler):
* lisp/emacs-lisp/warnings.el (lwarn, warn):
* lisp/emulation/viper-cmd.el:
(viper-toggle-parse-sexp-ignore-comments)
(viper-kill-buffer, viper-brac-function):
* lisp/emulation/viper-macs.el (viper-record-kbd-macro):
* lisp/facemenu.el (facemenu-add-new-face):
* lisp/faces.el (face-documentation, read-face-name)
(face-read-string, read-face-font, describe-face):
* lisp/files.el (find-alternate-file, hack-local-variables)
(hack-one-local-variable--obsolete, write-file)
(basic-save-buffer, delete-directory):
* lisp/format.el (format-write-file, format-find-file)
(format-insert-file):
* lisp/help-fns.el (help-fns--key-bindings)
(help-fns--compiler-macro, help-fns--obsolete)
(help-fns--interactive-only, describe-function-1)
(describe-variable):
* lisp/help.el (describe-mode):
* lisp/info-xref.el (info-xref-output):
* lisp/info.el (Info-virtual-index-find-node)
(Info-virtual-index, info-apropos):
* lisp/international/kkc.el (kkc-error):
* lisp/international/mule-cmds.el:
(select-safe-coding-system-interactively)
(select-safe-coding-system, describe-input-method):
* lisp/international/mule-conf.el (code-offset):
* lisp/international/mule-diag.el (describe-character-set)
(list-input-methods-1):
* lisp/international/quail.el (quail-error):
* lisp/minibuffer.el (minibuffer-message):
* lisp/mpc.el (mpc--debug):
* lisp/msb.el (msb--choose-menu):
* lisp/net/ange-ftp.el (ange-ftp-message):
* lisp/net/gnutls.el (gnutls-message-maybe):
* lisp/net/newst-backend.el (newsticker--sentinel-work):
* lisp/net/newst-treeview.el (newsticker--treeview-load):
* lisp/net/nsm.el (nsm-query-user):
* lisp/net/rlogin.el (rlogin):
* lisp/net/soap-client.el (soap-warning):
* lisp/net/tramp.el (tramp-debug-message):
* lisp/nxml/nxml-outln.el (nxml-report-outline-error):
* lisp/nxml/nxml-parse.el (nxml-parse-error):
* lisp/nxml/rng-cmpct.el (rng-c-error):
* lisp/nxml/rng-match.el (rng-compile-error):
* lisp/nxml/rng-uri.el (rng-uri-error):
* lisp/obsolete/iswitchb.el (iswitchb-possible-new-buffer):
* lisp/org/org-ctags.el:
(org-ctags-ask-rebuild-tags-file-then-find-tag):
* lisp/proced.el (proced-log):
* lisp/progmodes/ebnf2ps.el (ebnf-log):
* lisp/progmodes/flymake.el (flymake-log):
* lisp/progmodes/vhdl-mode.el (vhdl-warning-when-idle):
* lisp/replace.el (occur-1):
* lisp/simple.el (execute-extended-command)
(undo-outer-limit-truncate, define-alternatives):
* lisp/startup.el (command-line):
* lisp/subr.el (error, user-error, add-to-list):
* lisp/tutorial.el (tutorial--describe-nonstandard-key)
(tutorial--find-changed-keys):
* src/callint.c (Fcall_interactively):
* src/editfns.c (Fmessage, Fmessage_box):
Restyle the quotes of format strings intended for use as a
diagnostic, when restyling seems appropriate.
* lisp/subr.el (format-message): New function.
* src/doc.c (Finternal__text_restyle): New function.
(syms_of_doc): Define it.
2015-08-23 22:38:02 -07:00
|
|
|
|
(princ (format-message "\n ‘%s’ value is\n " symbol))
|
2009-09-28 01:39:27 +00:00
|
|
|
|
(if (and value (symbolp value))
|
More-conservative ‘format’ quote restyling
Instead of restyling curved quotes for every call to ‘format’,
create a new function ‘format-message’ that does the restyling,
and using the new function instead of ‘format’ only in contexts
where this seems appropriate.
Problem reported by Dmitry Gutov and Andreas Schwab in:
http://lists.gnu.org/archive/html/emacs-devel/2015-08/msg00826.html
http://lists.gnu.org/archive/html/emacs-devel/2015-08/msg00827.html
* doc/lispref/commands.texi (Using Interactive):
* doc/lispref/control.texi (Signaling Errors, Signaling Errors):
* doc/lispref/display.texi (Displaying Messages, Progress):
* doc/lispref/elisp.texi:
* doc/lispref/help.texi (Keys in Documentation):
* doc/lispref/minibuf.texi (Minibuffer Misc):
* doc/lispref/strings.texi (Formatting Strings):
* etc/NEWS:
Document the changes.
* lisp/abbrev.el (expand-region-abbrevs):
* lisp/apropos.el (apropos-library):
* lisp/calc/calc-ext.el (calc-record-message)
(calc-user-function-list):
* lisp/calc/calc-help.el (calc-describe-key, calc-full-help):
* lisp/calc/calc-lang.el (math-read-big-balance):
* lisp/calc/calc-store.el (calc-edit-variable):
* lisp/calc/calc-units.el (math-build-units-table-buffer):
* lisp/calc/calc-yank.el (calc-edit-mode):
* lisp/calendar/icalendar.el (icalendar-export-region)
(icalendar--add-diary-entry):
* lisp/cedet/mode-local.el (mode-local-print-binding)
(mode-local-describe-bindings-2):
* lisp/cedet/semantic/complete.el (semantic-completion-message):
* lisp/cedet/semantic/edit.el (semantic-parse-changes-failed):
* lisp/cedet/semantic/wisent/comp.el (wisent-log):
* lisp/cedet/srecode/insert.el (srecode-insert-show-error-report):
* lisp/descr-text.el (describe-text-properties-1, describe-char):
* lisp/dframe.el (dframe-message):
* lisp/dired-aux.el (dired-query):
* lisp/emacs-lisp/byte-opt.el (byte-compile-log-lap-1):
* lisp/emacs-lisp/bytecomp.el (byte-compile-log)
(byte-compile-log-file, byte-compile-warn, byte-compile-form):
* lisp/emacs-lisp/cconv.el (cconv-convert, cconv--analyze-use)
(cconv-analyze-form):
* lisp/emacs-lisp/check-declare.el (check-declare-warn):
* lisp/emacs-lisp/checkdoc.el (checkdoc-this-string-valid-engine):
* lisp/emacs-lisp/cl-macs.el (cl-symbol-macrolet):
* lisp/emacs-lisp/edebug.el (edebug-format):
* lisp/emacs-lisp/eieio-core.el (eieio-oref):
* lisp/emacs-lisp/eldoc.el (eldoc-minibuffer-message)
(eldoc-message):
* lisp/emacs-lisp/elint.el (elint-file, elint-log):
* lisp/emacs-lisp/find-func.el (find-function-library):
* lisp/emacs-lisp/macroexp.el (macroexp--obsolete-warning):
* lisp/emacs-lisp/map-ynp.el (map-y-or-n-p):
* lisp/emacs-lisp/nadvice.el (advice--make-docstring):
* lisp/emacs-lisp/package.el (package-compute-transaction)
(package-install-button-action, package-delete-button-action)
(package-menu--list-to-prompt):
* lisp/emacs-lisp/timer.el (timer-event-handler):
* lisp/emacs-lisp/warnings.el (lwarn, warn):
* lisp/emulation/viper-cmd.el:
(viper-toggle-parse-sexp-ignore-comments)
(viper-kill-buffer, viper-brac-function):
* lisp/emulation/viper-macs.el (viper-record-kbd-macro):
* lisp/facemenu.el (facemenu-add-new-face):
* lisp/faces.el (face-documentation, read-face-name)
(face-read-string, read-face-font, describe-face):
* lisp/files.el (find-alternate-file, hack-local-variables)
(hack-one-local-variable--obsolete, write-file)
(basic-save-buffer, delete-directory):
* lisp/format.el (format-write-file, format-find-file)
(format-insert-file):
* lisp/help-fns.el (help-fns--key-bindings)
(help-fns--compiler-macro, help-fns--obsolete)
(help-fns--interactive-only, describe-function-1)
(describe-variable):
* lisp/help.el (describe-mode):
* lisp/info-xref.el (info-xref-output):
* lisp/info.el (Info-virtual-index-find-node)
(Info-virtual-index, info-apropos):
* lisp/international/kkc.el (kkc-error):
* lisp/international/mule-cmds.el:
(select-safe-coding-system-interactively)
(select-safe-coding-system, describe-input-method):
* lisp/international/mule-conf.el (code-offset):
* lisp/international/mule-diag.el (describe-character-set)
(list-input-methods-1):
* lisp/international/quail.el (quail-error):
* lisp/minibuffer.el (minibuffer-message):
* lisp/mpc.el (mpc--debug):
* lisp/msb.el (msb--choose-menu):
* lisp/net/ange-ftp.el (ange-ftp-message):
* lisp/net/gnutls.el (gnutls-message-maybe):
* lisp/net/newst-backend.el (newsticker--sentinel-work):
* lisp/net/newst-treeview.el (newsticker--treeview-load):
* lisp/net/nsm.el (nsm-query-user):
* lisp/net/rlogin.el (rlogin):
* lisp/net/soap-client.el (soap-warning):
* lisp/net/tramp.el (tramp-debug-message):
* lisp/nxml/nxml-outln.el (nxml-report-outline-error):
* lisp/nxml/nxml-parse.el (nxml-parse-error):
* lisp/nxml/rng-cmpct.el (rng-c-error):
* lisp/nxml/rng-match.el (rng-compile-error):
* lisp/nxml/rng-uri.el (rng-uri-error):
* lisp/obsolete/iswitchb.el (iswitchb-possible-new-buffer):
* lisp/org/org-ctags.el:
(org-ctags-ask-rebuild-tags-file-then-find-tag):
* lisp/proced.el (proced-log):
* lisp/progmodes/ebnf2ps.el (ebnf-log):
* lisp/progmodes/flymake.el (flymake-log):
* lisp/progmodes/vhdl-mode.el (vhdl-warning-when-idle):
* lisp/replace.el (occur-1):
* lisp/simple.el (execute-extended-command)
(undo-outer-limit-truncate, define-alternatives):
* lisp/startup.el (command-line):
* lisp/subr.el (error, user-error, add-to-list):
* lisp/tutorial.el (tutorial--describe-nonstandard-key)
(tutorial--find-changed-keys):
* src/callint.c (Fcall_interactively):
* src/editfns.c (Fmessage, Fmessage_box):
Restyle the quotes of format strings intended for use as a
diagnostic, when restyling seems appropriate.
* lisp/subr.el (format-message): New function.
* src/doc.c (Finternal__text_restyle): New function.
(syms_of_doc): Define it.
2015-08-23 22:38:02 -07:00
|
|
|
|
(princ (format-message "‘%s’" value))
|
2009-09-28 01:39:27 +00:00
|
|
|
|
(let ((pt (point)))
|
|
|
|
|
(pp value)
|
|
|
|
|
(save-excursion
|
|
|
|
|
(goto-char pt)
|
|
|
|
|
(indent-sexp))))
|
|
|
|
|
(or (bolp) (princ "\n"))))
|
|
|
|
|
|
|
|
|
|
(defun mode-local-print-bindings (table)
|
|
|
|
|
"Print bindings in TABLE."
|
2011-11-15 01:54:19 +01:00
|
|
|
|
(let (us ;; List of unspecified symbols
|
2009-09-28 01:39:27 +00:00
|
|
|
|
mc ;; List of mode local constants
|
|
|
|
|
mv ;; List of mode local variables
|
|
|
|
|
ov ;; List of overloaded functions
|
|
|
|
|
fo ;; List of final overloaded functions
|
|
|
|
|
)
|
|
|
|
|
;; Order symbols by type
|
|
|
|
|
(mapatoms
|
|
|
|
|
#'(lambda (s)
|
|
|
|
|
(add-to-list (cond
|
|
|
|
|
((get s 'mode-variable-flag)
|
|
|
|
|
(if (get s 'constant-flag) 'mc 'mv))
|
|
|
|
|
((get s 'override-flag)
|
|
|
|
|
(if (get s 'constant-flag) 'fo 'ov))
|
|
|
|
|
('us))
|
|
|
|
|
s))
|
|
|
|
|
table)
|
|
|
|
|
;; Print symbols by type
|
|
|
|
|
(when us
|
2011-11-14 12:23:26 -08:00
|
|
|
|
(princ "\n !! Unspecified symbols\n")
|
2009-09-28 01:39:27 +00:00
|
|
|
|
(mapc 'mode-local-print-binding us))
|
|
|
|
|
(when mc
|
|
|
|
|
(princ "\n ** Mode local constants\n")
|
|
|
|
|
(mapc 'mode-local-print-binding mc))
|
|
|
|
|
(when mv
|
|
|
|
|
(princ "\n ** Mode local variables\n")
|
|
|
|
|
(mapc 'mode-local-print-binding mv))
|
|
|
|
|
(when fo
|
|
|
|
|
(princ "\n ** Final overloaded functions\n")
|
|
|
|
|
(mapc 'mode-local-print-binding fo))
|
|
|
|
|
(when ov
|
|
|
|
|
(princ "\n ** Overloaded functions\n")
|
|
|
|
|
(mapc 'mode-local-print-binding ov))
|
|
|
|
|
))
|
|
|
|
|
|
|
|
|
|
(defun mode-local-describe-bindings-2 (buffer-or-mode)
|
|
|
|
|
"Display mode local bindings active in BUFFER-OR-MODE."
|
|
|
|
|
(let (table mode)
|
|
|
|
|
(princ "Mode local bindings active in ")
|
|
|
|
|
(cond
|
|
|
|
|
((bufferp buffer-or-mode)
|
|
|
|
|
(with-current-buffer buffer-or-mode
|
|
|
|
|
(setq table mode-local-symbol-table
|
|
|
|
|
mode major-mode))
|
|
|
|
|
(princ (format "%S\n" buffer-or-mode))
|
|
|
|
|
)
|
|
|
|
|
((symbolp buffer-or-mode)
|
|
|
|
|
(setq mode buffer-or-mode)
|
More-conservative ‘format’ quote restyling
Instead of restyling curved quotes for every call to ‘format’,
create a new function ‘format-message’ that does the restyling,
and using the new function instead of ‘format’ only in contexts
where this seems appropriate.
Problem reported by Dmitry Gutov and Andreas Schwab in:
http://lists.gnu.org/archive/html/emacs-devel/2015-08/msg00826.html
http://lists.gnu.org/archive/html/emacs-devel/2015-08/msg00827.html
* doc/lispref/commands.texi (Using Interactive):
* doc/lispref/control.texi (Signaling Errors, Signaling Errors):
* doc/lispref/display.texi (Displaying Messages, Progress):
* doc/lispref/elisp.texi:
* doc/lispref/help.texi (Keys in Documentation):
* doc/lispref/minibuf.texi (Minibuffer Misc):
* doc/lispref/strings.texi (Formatting Strings):
* etc/NEWS:
Document the changes.
* lisp/abbrev.el (expand-region-abbrevs):
* lisp/apropos.el (apropos-library):
* lisp/calc/calc-ext.el (calc-record-message)
(calc-user-function-list):
* lisp/calc/calc-help.el (calc-describe-key, calc-full-help):
* lisp/calc/calc-lang.el (math-read-big-balance):
* lisp/calc/calc-store.el (calc-edit-variable):
* lisp/calc/calc-units.el (math-build-units-table-buffer):
* lisp/calc/calc-yank.el (calc-edit-mode):
* lisp/calendar/icalendar.el (icalendar-export-region)
(icalendar--add-diary-entry):
* lisp/cedet/mode-local.el (mode-local-print-binding)
(mode-local-describe-bindings-2):
* lisp/cedet/semantic/complete.el (semantic-completion-message):
* lisp/cedet/semantic/edit.el (semantic-parse-changes-failed):
* lisp/cedet/semantic/wisent/comp.el (wisent-log):
* lisp/cedet/srecode/insert.el (srecode-insert-show-error-report):
* lisp/descr-text.el (describe-text-properties-1, describe-char):
* lisp/dframe.el (dframe-message):
* lisp/dired-aux.el (dired-query):
* lisp/emacs-lisp/byte-opt.el (byte-compile-log-lap-1):
* lisp/emacs-lisp/bytecomp.el (byte-compile-log)
(byte-compile-log-file, byte-compile-warn, byte-compile-form):
* lisp/emacs-lisp/cconv.el (cconv-convert, cconv--analyze-use)
(cconv-analyze-form):
* lisp/emacs-lisp/check-declare.el (check-declare-warn):
* lisp/emacs-lisp/checkdoc.el (checkdoc-this-string-valid-engine):
* lisp/emacs-lisp/cl-macs.el (cl-symbol-macrolet):
* lisp/emacs-lisp/edebug.el (edebug-format):
* lisp/emacs-lisp/eieio-core.el (eieio-oref):
* lisp/emacs-lisp/eldoc.el (eldoc-minibuffer-message)
(eldoc-message):
* lisp/emacs-lisp/elint.el (elint-file, elint-log):
* lisp/emacs-lisp/find-func.el (find-function-library):
* lisp/emacs-lisp/macroexp.el (macroexp--obsolete-warning):
* lisp/emacs-lisp/map-ynp.el (map-y-or-n-p):
* lisp/emacs-lisp/nadvice.el (advice--make-docstring):
* lisp/emacs-lisp/package.el (package-compute-transaction)
(package-install-button-action, package-delete-button-action)
(package-menu--list-to-prompt):
* lisp/emacs-lisp/timer.el (timer-event-handler):
* lisp/emacs-lisp/warnings.el (lwarn, warn):
* lisp/emulation/viper-cmd.el:
(viper-toggle-parse-sexp-ignore-comments)
(viper-kill-buffer, viper-brac-function):
* lisp/emulation/viper-macs.el (viper-record-kbd-macro):
* lisp/facemenu.el (facemenu-add-new-face):
* lisp/faces.el (face-documentation, read-face-name)
(face-read-string, read-face-font, describe-face):
* lisp/files.el (find-alternate-file, hack-local-variables)
(hack-one-local-variable--obsolete, write-file)
(basic-save-buffer, delete-directory):
* lisp/format.el (format-write-file, format-find-file)
(format-insert-file):
* lisp/help-fns.el (help-fns--key-bindings)
(help-fns--compiler-macro, help-fns--obsolete)
(help-fns--interactive-only, describe-function-1)
(describe-variable):
* lisp/help.el (describe-mode):
* lisp/info-xref.el (info-xref-output):
* lisp/info.el (Info-virtual-index-find-node)
(Info-virtual-index, info-apropos):
* lisp/international/kkc.el (kkc-error):
* lisp/international/mule-cmds.el:
(select-safe-coding-system-interactively)
(select-safe-coding-system, describe-input-method):
* lisp/international/mule-conf.el (code-offset):
* lisp/international/mule-diag.el (describe-character-set)
(list-input-methods-1):
* lisp/international/quail.el (quail-error):
* lisp/minibuffer.el (minibuffer-message):
* lisp/mpc.el (mpc--debug):
* lisp/msb.el (msb--choose-menu):
* lisp/net/ange-ftp.el (ange-ftp-message):
* lisp/net/gnutls.el (gnutls-message-maybe):
* lisp/net/newst-backend.el (newsticker--sentinel-work):
* lisp/net/newst-treeview.el (newsticker--treeview-load):
* lisp/net/nsm.el (nsm-query-user):
* lisp/net/rlogin.el (rlogin):
* lisp/net/soap-client.el (soap-warning):
* lisp/net/tramp.el (tramp-debug-message):
* lisp/nxml/nxml-outln.el (nxml-report-outline-error):
* lisp/nxml/nxml-parse.el (nxml-parse-error):
* lisp/nxml/rng-cmpct.el (rng-c-error):
* lisp/nxml/rng-match.el (rng-compile-error):
* lisp/nxml/rng-uri.el (rng-uri-error):
* lisp/obsolete/iswitchb.el (iswitchb-possible-new-buffer):
* lisp/org/org-ctags.el:
(org-ctags-ask-rebuild-tags-file-then-find-tag):
* lisp/proced.el (proced-log):
* lisp/progmodes/ebnf2ps.el (ebnf-log):
* lisp/progmodes/flymake.el (flymake-log):
* lisp/progmodes/vhdl-mode.el (vhdl-warning-when-idle):
* lisp/replace.el (occur-1):
* lisp/simple.el (execute-extended-command)
(undo-outer-limit-truncate, define-alternatives):
* lisp/startup.el (command-line):
* lisp/subr.el (error, user-error, add-to-list):
* lisp/tutorial.el (tutorial--describe-nonstandard-key)
(tutorial--find-changed-keys):
* src/callint.c (Fcall_interactively):
* src/editfns.c (Fmessage, Fmessage_box):
Restyle the quotes of format strings intended for use as a
diagnostic, when restyling seems appropriate.
* lisp/subr.el (format-message): New function.
* src/doc.c (Finternal__text_restyle): New function.
(syms_of_doc): Define it.
2015-08-23 22:38:02 -07:00
|
|
|
|
(princ (format-message "‘%s’\n" buffer-or-mode))
|
2009-09-28 01:39:27 +00:00
|
|
|
|
)
|
|
|
|
|
((signal 'wrong-type-argument
|
|
|
|
|
(list 'buffer-or-mode buffer-or-mode))))
|
|
|
|
|
(when table
|
|
|
|
|
(princ "\n- Buffer local\n")
|
|
|
|
|
(mode-local-print-bindings table))
|
|
|
|
|
(while mode
|
|
|
|
|
(setq table (get mode 'mode-local-symbol-table))
|
|
|
|
|
(when table
|
More-conservative ‘format’ quote restyling
Instead of restyling curved quotes for every call to ‘format’,
create a new function ‘format-message’ that does the restyling,
and using the new function instead of ‘format’ only in contexts
where this seems appropriate.
Problem reported by Dmitry Gutov and Andreas Schwab in:
http://lists.gnu.org/archive/html/emacs-devel/2015-08/msg00826.html
http://lists.gnu.org/archive/html/emacs-devel/2015-08/msg00827.html
* doc/lispref/commands.texi (Using Interactive):
* doc/lispref/control.texi (Signaling Errors, Signaling Errors):
* doc/lispref/display.texi (Displaying Messages, Progress):
* doc/lispref/elisp.texi:
* doc/lispref/help.texi (Keys in Documentation):
* doc/lispref/minibuf.texi (Minibuffer Misc):
* doc/lispref/strings.texi (Formatting Strings):
* etc/NEWS:
Document the changes.
* lisp/abbrev.el (expand-region-abbrevs):
* lisp/apropos.el (apropos-library):
* lisp/calc/calc-ext.el (calc-record-message)
(calc-user-function-list):
* lisp/calc/calc-help.el (calc-describe-key, calc-full-help):
* lisp/calc/calc-lang.el (math-read-big-balance):
* lisp/calc/calc-store.el (calc-edit-variable):
* lisp/calc/calc-units.el (math-build-units-table-buffer):
* lisp/calc/calc-yank.el (calc-edit-mode):
* lisp/calendar/icalendar.el (icalendar-export-region)
(icalendar--add-diary-entry):
* lisp/cedet/mode-local.el (mode-local-print-binding)
(mode-local-describe-bindings-2):
* lisp/cedet/semantic/complete.el (semantic-completion-message):
* lisp/cedet/semantic/edit.el (semantic-parse-changes-failed):
* lisp/cedet/semantic/wisent/comp.el (wisent-log):
* lisp/cedet/srecode/insert.el (srecode-insert-show-error-report):
* lisp/descr-text.el (describe-text-properties-1, describe-char):
* lisp/dframe.el (dframe-message):
* lisp/dired-aux.el (dired-query):
* lisp/emacs-lisp/byte-opt.el (byte-compile-log-lap-1):
* lisp/emacs-lisp/bytecomp.el (byte-compile-log)
(byte-compile-log-file, byte-compile-warn, byte-compile-form):
* lisp/emacs-lisp/cconv.el (cconv-convert, cconv--analyze-use)
(cconv-analyze-form):
* lisp/emacs-lisp/check-declare.el (check-declare-warn):
* lisp/emacs-lisp/checkdoc.el (checkdoc-this-string-valid-engine):
* lisp/emacs-lisp/cl-macs.el (cl-symbol-macrolet):
* lisp/emacs-lisp/edebug.el (edebug-format):
* lisp/emacs-lisp/eieio-core.el (eieio-oref):
* lisp/emacs-lisp/eldoc.el (eldoc-minibuffer-message)
(eldoc-message):
* lisp/emacs-lisp/elint.el (elint-file, elint-log):
* lisp/emacs-lisp/find-func.el (find-function-library):
* lisp/emacs-lisp/macroexp.el (macroexp--obsolete-warning):
* lisp/emacs-lisp/map-ynp.el (map-y-or-n-p):
* lisp/emacs-lisp/nadvice.el (advice--make-docstring):
* lisp/emacs-lisp/package.el (package-compute-transaction)
(package-install-button-action, package-delete-button-action)
(package-menu--list-to-prompt):
* lisp/emacs-lisp/timer.el (timer-event-handler):
* lisp/emacs-lisp/warnings.el (lwarn, warn):
* lisp/emulation/viper-cmd.el:
(viper-toggle-parse-sexp-ignore-comments)
(viper-kill-buffer, viper-brac-function):
* lisp/emulation/viper-macs.el (viper-record-kbd-macro):
* lisp/facemenu.el (facemenu-add-new-face):
* lisp/faces.el (face-documentation, read-face-name)
(face-read-string, read-face-font, describe-face):
* lisp/files.el (find-alternate-file, hack-local-variables)
(hack-one-local-variable--obsolete, write-file)
(basic-save-buffer, delete-directory):
* lisp/format.el (format-write-file, format-find-file)
(format-insert-file):
* lisp/help-fns.el (help-fns--key-bindings)
(help-fns--compiler-macro, help-fns--obsolete)
(help-fns--interactive-only, describe-function-1)
(describe-variable):
* lisp/help.el (describe-mode):
* lisp/info-xref.el (info-xref-output):
* lisp/info.el (Info-virtual-index-find-node)
(Info-virtual-index, info-apropos):
* lisp/international/kkc.el (kkc-error):
* lisp/international/mule-cmds.el:
(select-safe-coding-system-interactively)
(select-safe-coding-system, describe-input-method):
* lisp/international/mule-conf.el (code-offset):
* lisp/international/mule-diag.el (describe-character-set)
(list-input-methods-1):
* lisp/international/quail.el (quail-error):
* lisp/minibuffer.el (minibuffer-message):
* lisp/mpc.el (mpc--debug):
* lisp/msb.el (msb--choose-menu):
* lisp/net/ange-ftp.el (ange-ftp-message):
* lisp/net/gnutls.el (gnutls-message-maybe):
* lisp/net/newst-backend.el (newsticker--sentinel-work):
* lisp/net/newst-treeview.el (newsticker--treeview-load):
* lisp/net/nsm.el (nsm-query-user):
* lisp/net/rlogin.el (rlogin):
* lisp/net/soap-client.el (soap-warning):
* lisp/net/tramp.el (tramp-debug-message):
* lisp/nxml/nxml-outln.el (nxml-report-outline-error):
* lisp/nxml/nxml-parse.el (nxml-parse-error):
* lisp/nxml/rng-cmpct.el (rng-c-error):
* lisp/nxml/rng-match.el (rng-compile-error):
* lisp/nxml/rng-uri.el (rng-uri-error):
* lisp/obsolete/iswitchb.el (iswitchb-possible-new-buffer):
* lisp/org/org-ctags.el:
(org-ctags-ask-rebuild-tags-file-then-find-tag):
* lisp/proced.el (proced-log):
* lisp/progmodes/ebnf2ps.el (ebnf-log):
* lisp/progmodes/flymake.el (flymake-log):
* lisp/progmodes/vhdl-mode.el (vhdl-warning-when-idle):
* lisp/replace.el (occur-1):
* lisp/simple.el (execute-extended-command)
(undo-outer-limit-truncate, define-alternatives):
* lisp/startup.el (command-line):
* lisp/subr.el (error, user-error, add-to-list):
* lisp/tutorial.el (tutorial--describe-nonstandard-key)
(tutorial--find-changed-keys):
* src/callint.c (Fcall_interactively):
* src/editfns.c (Fmessage, Fmessage_box):
Restyle the quotes of format strings intended for use as a
diagnostic, when restyling seems appropriate.
* lisp/subr.el (format-message): New function.
* src/doc.c (Finternal__text_restyle): New function.
(syms_of_doc): Define it.
2015-08-23 22:38:02 -07:00
|
|
|
|
(princ (format-message "\n- From ‘%s’\n" mode))
|
2009-09-28 01:39:27 +00:00
|
|
|
|
(mode-local-print-bindings table))
|
|
|
|
|
(setq mode (get-mode-local-parent mode)))))
|
|
|
|
|
|
|
|
|
|
(defun mode-local-describe-bindings-1 (buffer-or-mode &optional interactive-p)
|
|
|
|
|
"Display mode local bindings active in BUFFER-OR-MODE.
|
|
|
|
|
Optional argument INTERACTIVE-P is non-nil if the calling command was
|
|
|
|
|
invoked interactively."
|
|
|
|
|
(if (fboundp 'with-displaying-help-buffer)
|
|
|
|
|
;; XEmacs
|
|
|
|
|
(with-displaying-help-buffer
|
|
|
|
|
#'(lambda ()
|
|
|
|
|
(with-current-buffer standard-output
|
|
|
|
|
(mode-local-describe-bindings-2 buffer-or-mode)
|
|
|
|
|
(when (fboundp 'frob-help-extents)
|
|
|
|
|
(goto-char (point-min))
|
|
|
|
|
(frob-help-extents standard-output)))))
|
|
|
|
|
;; GNU Emacs
|
|
|
|
|
(when (fboundp 'help-setup-xref)
|
|
|
|
|
(help-setup-xref
|
|
|
|
|
(list 'mode-local-describe-bindings-1 buffer-or-mode)
|
|
|
|
|
interactive-p))
|
|
|
|
|
(with-output-to-temp-buffer (help-buffer) ; "*Help*"
|
|
|
|
|
(with-current-buffer standard-output
|
|
|
|
|
(mode-local-describe-bindings-2 buffer-or-mode)))))
|
|
|
|
|
|
|
|
|
|
(defun describe-mode-local-bindings (buffer)
|
|
|
|
|
"Display mode local bindings active in BUFFER."
|
|
|
|
|
(interactive "b")
|
|
|
|
|
(when (setq buffer (get-buffer buffer))
|
2009-11-22 23:49:13 +00:00
|
|
|
|
(mode-local-describe-bindings-1 buffer (called-interactively-p 'any))))
|
2009-09-28 01:39:27 +00:00
|
|
|
|
|
|
|
|
|
(defun describe-mode-local-bindings-in-mode (mode)
|
|
|
|
|
"Display mode local bindings active in MODE hierarchy."
|
|
|
|
|
(interactive
|
|
|
|
|
(list (completing-read
|
|
|
|
|
"Mode: " obarray
|
|
|
|
|
#'(lambda (s) (get s 'mode-local-symbol-table))
|
|
|
|
|
t (symbol-name major-mode))))
|
|
|
|
|
(when (setq mode (intern-soft mode))
|
2009-11-22 23:49:13 +00:00
|
|
|
|
(mode-local-describe-bindings-1 mode (called-interactively-p 'any))))
|
2009-09-28 01:39:27 +00:00
|
|
|
|
|
|
|
|
|
;; ;;; find-func support (Emacs 21.4, or perhaps 22.1)
|
|
|
|
|
;; ;;
|
|
|
|
|
;; (condition-case nil
|
|
|
|
|
;; ;; Try to get find-func so we can modify it.
|
|
|
|
|
;; (require 'find-func)
|
|
|
|
|
;; (error nil))
|
|
|
|
|
|
|
|
|
|
;; (when (boundp 'find-function-regexp)
|
|
|
|
|
;; (unless (string-match "ine-overload" find-function-regexp)
|
|
|
|
|
;; (if (string-match "(def\\\\(" find-function-regexp)
|
|
|
|
|
;; (let ((end (match-end 0))
|
|
|
|
|
;; )
|
|
|
|
|
;; (setq find-function-regexp
|
|
|
|
|
;; (concat (substring find-function-regexp 0 end)
|
|
|
|
|
;; "ine-overload\\|ine-mode-local-override\\|"
|
|
|
|
|
;; "ine-child-mode\\|"
|
|
|
|
|
;; (substring find-function-regexp end)))))))
|
|
|
|
|
|
|
|
|
|
;;; edebug support
|
|
|
|
|
;;
|
|
|
|
|
(defun mode-local-setup-edebug-specs ()
|
|
|
|
|
"Define edebug specification for mode local macros."
|
|
|
|
|
(def-edebug-spec setq-mode-local
|
|
|
|
|
(symbolp &rest symbolp form))
|
|
|
|
|
(def-edebug-spec defvar-mode-local
|
|
|
|
|
(&define symbolp name def-form [ &optional stringp ] ))
|
|
|
|
|
(def-edebug-spec defconst-mode-local
|
|
|
|
|
defvar-mode-local)
|
|
|
|
|
(def-edebug-spec define-overload
|
|
|
|
|
(&define name lambda-list stringp def-body))
|
|
|
|
|
(def-edebug-spec define-overloadable-function
|
|
|
|
|
(&define name lambda-list stringp def-body))
|
|
|
|
|
(def-edebug-spec define-mode-local-override
|
|
|
|
|
(&define name symbolp lambda-list stringp def-body)))
|
|
|
|
|
|
|
|
|
|
(add-hook 'edebug-setup-hook 'mode-local-setup-edebug-specs)
|
|
|
|
|
|
|
|
|
|
(add-hook 'find-file-hook 'mode-local-post-major-mode-change)
|
|
|
|
|
(add-hook 'change-major-mode-hook 'mode-local-on-major-mode-change)
|
|
|
|
|
|
|
|
|
|
(provide 'mode-local)
|
|
|
|
|
|
|
|
|
|
;;; mode-local.el ends here
|