• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /macosx-10.9.5/emacs-92/emacs/lisp/emacs-lisp/

Lines Matching +defs:global +defs:mode

31 ;; minor mode easy, by focusing on the writing of the minor mode
34 ;; natural for the minor-mode end-users.
36 ;; For each mode, easy-mmode defines the following:
37 ;; <mode> : The minor mode predicate. A buffer-local variable.
38 ;; <mode>-map : The keymap possibly associated to <mode>.
39 ;; see `define-minor-mode' documentation
42 ;; (pp (macroexpand '(define-minor-mode <your-mode> <doc>)))
46 ;; lookup proceeds down minor-mode-map-alist, and the order there
51 ;; Additionally to `define-minor-mode', the package provides convenient
58 (defun easy-mmode-pretty-mode-name (mode &optional lighter)
63 ;; Produce "Foo-Bar minor mode" from foo-bar-minor-mode.
65 ;; If the original mode name included "-minor" (some
66 ;; of them don't, e.g. auto-revert-mode), then
71 ;; "foo-bar-minor-mode" -> "foo-bar-minor"
72 "-mode\\'" "" (symbol-name mode))))
73 " mode")))
79 ;; with a literal LIGHTER. E.g., if NAME is "Iimage mode" and
80 ;; LIGHTER is " iImag", then this will produce "iImage mode".
81 ;; (LIGHTER normally comes from the mode-line string passed to
82 ;; define-minor-mode, and normally includes at least one leading
87 (defalias 'easy-mmode-define-minor-mode 'define-minor-mode)
89 (defmacro define-minor-mode (mode doc &optional init-value lighter keymap &rest body)
90 "Define a new minor mode MODE.
94 DOC is the documentation for the mode toggle command.
95 Optional INIT-VALUE is the initial value of the mode's variable.
96 Optional LIGHTER is displayed in the modeline when the mode is on.
97 Optional KEYMAP is the default (defvar) keymap bound to the mode keymap.
104 BODY contains code to execute each time the mode is activated or deactivated.
105 It is executed after toggling the mode,
106 and before running the hook variable `mode-HOOK'.
109 keywords will be passed to `defcustom' if the minor mode is global):
111 Defaults to MODE without the possible trailing \"-mode\".
114 :global GLOBAL If non-nil specifies that the minor mode is not meant to be
116 By default, the mode is buffer-local.
123 (define-minor-mode foo-mode \"If enabled, foo on you!\"
124 :lighter \" Foo\" :require 'foo :global t :group 'hassle :version \"27.5\"
143 (mode-name (symbol-name mode))
144 (pretty-name (easy-mmode-pretty-mode-name mode lighter))
153 (hook (intern (concat mode-name "-hook")))
154 (hook-on (intern (concat mode-name "-on-hook")))
155 (hook-off (intern (concat mode-name "-off-hook")))
164 (:global (setq globalp (pop body)))
175 (intern (concat mode-name "-map"))))
177 (unless set (setq set '(:set 'custom-set-minor-mode)))
186 "-mode\\'" "" mode-name)))))
191 ;; Define the variable to enable or disable the mode.
194 (defvar ,mode ,init-value ,(format "Non-nil if %s is enabled.
195 Use the command `%s' to change this variable." pretty-name mode))
196 (make-variable-buffer-local ',mode))
200 See the command `%s' for a description of this minor mode."
205 `(defcustom ,mode ,init-value
206 ,(format base-doc-string pretty-name mode mode)
215 (defun ,mode (&optional arg ,@extra-args)
218 Interactively, with no prefix argument, toggle the mode.
219 With universal prefix ARG turn mode on.
220 With zero or negative ARG turn mode off.
222 ;; Use `toggle' rather than (if ,mode 0 1) so that using
225 (setq ,mode
227 ((eq arg 'toggle) (not ,mode))
230 (if (null ,mode) t
233 ',mode)
237 (run-hooks ',hook (if ,mode ',hook-on ',hook-off))
240 ,(if globalp `(customize-mark-as-set ',mode))
246 (if ,mode "en" "dis")))))
247 (force-mode-line-update)
249 ,mode)
251 ;; Autoloading a define-minor-mode autoloads everything
255 ;; Define the minor-mode keymap.
262 ,(format "Keymap for `%s'." mode-name)))
264 (add-minor-mode ',mode ',lighter
271 ;;; make global minor mode
275 (defalias 'easy-mmode-define-global-mode 'define-globalized-minor-mode)
277 (defalias 'define-global-minor-mode 'define-globalized-minor-mode)
279 (defmacro define-globalized-minor-mode (global-mode mode turn-on &rest keys)
280 "Make a global mode GLOBAL-MODE corresponding to buffer-local minor MODE.
283 KEYS is a list of CL-style keyword arguments. As the minor mode
284 defined by this function is always global, any :global keyword is
285 ignored. Other keywords have the same meaning as in `define-minor-mode',
289 or :keymap keywords to `define-globalized-minor-mode', since these
290 are usually passed to the buffer-local version of the minor mode.
292 If MODE's set-up depends on the major mode in effect when it was
294 correctly with the current major mode. This is important to
296 call another major mode in their body."
298 (let* ((global-mode-name (symbol-name global-mode))
299 (pretty-name (easy-mmode-pretty-mode-name mode))
300 (pretty-global-name (easy-mmode-pretty-mode-name global-mode))
303 (MODE-buffers (intern (concat global-mode-name "-buffers")))
305 (intern (concat global-mode-name "-enable-in-buffers")))
307 (intern (concat global-mode-name "-check-buffers")))
308 (MODE-cmhh (intern (concat global-mode-name "-cmhh")))
309 (MODE-major-mode (intern (concat (symbol-name mode) "-major-mode")))
317 (:global (setq keys (cdr keys)))
324 "-mode\\'" "" (symbol-name mode))))))
327 (defvar ,MODE-major-mode nil)
328 (make-variable-buffer-local ',MODE-major-mode)
329 ;; The actual global minor-mode
330 (define-minor-mode ,global-mode
335 pretty-name pretty-global-name pretty-name turn-on
336 mode pretty-name)
337 :global t ,@group ,@(nreverse extra-keywords)
339 ;; Setup hook to handle future mode changes and new buffers.
340 (if ,global-mode
342 (add-hook 'after-change-major-mode-hook
345 (add-hook 'change-major-mode-hook ',MODE-cmhh))
346 (remove-hook 'after-change-major-mode-hook ',MODE-enable-in-buffers)
348 (remove-hook 'change-major-mode-hook ',MODE-cmhh))
353 (if ,global-mode (,turn-on) (when ,mode (,mode -1))))))
355 ;; Autoloading define-globalized-minor-mode autoloads everything
367 (if ,mode
368 (unless (eq ,MODE-major-mode major-mode)
369 (,mode -1)
371 (setq ,MODE-major-mode major-mode))
373 (setq ,MODE-major-mode major-mode))))))
374 (put ',MODE-enable-in-buffers 'definition-name ',global-mode)
380 (put ',MODE-check-buffers 'definition-name ',global-mode)
386 (put ',MODE-cmhh 'definition-name ',global-mode))))
431 (substitute-key-definition key binding m global-map))