Mercurial > emacs
annotate lisp/format-spec.el @ 101490:cfaf6934d659
Changes to remove Feval calls from GUI under NS.
* nsterm.h: Move KEY_NS_... definitions here from nsterm.m. Add
NS_TOGGLE_TOOLBAR, NS_PUT_WORKING_TEXT, NS_UNPUT_WORKING_TEXT.
Remove NS_INSERT_WORKING_TEXT, NS_DELETE_WORKING_TEXT.
* nsterm.m: Move KEY_NS_... definitions to nsterm.h.
(EmacsView-toggleToolbar:): Use KEY_NS_TOGGLE_TOOLBAR.
(EmacsView-setMarkedText:,-deleteWorkingText:): Use NS_TEXT_EVENT
instead of NON_ASCII_KEYSTROKE_EVENT.
(EmacsApp-terminate:): Use KEY_NS_POWER_OFF instead of Feval.
(EmacsApp-applicationShouldTerminate:): Query user.
(EmacsPreferencesController-runHelp:): Use KEY_NS_INFO_PREFS
instead of Feval.
* termhooks.h (NS_TEXT_EVENT): New event type under HAVE_NS.
* keyboard.c (kbd_buffer_get_event): Check for it.
(keys_of_keyboard): Define lispy keys for
ns-put/unput-working-text.
* nsmenu.m (ns_popup_dialog): Resync window setting with X and W32
versions.
(EmacsDialog-runDialogAt:): Use NSModalPanelRunLoopMode.
author | Adrian Robert <Adrian.B.Robert@gmail.com> |
---|---|
date | Sun, 25 Jan 2009 19:43:31 +0000 |
parents | a9dc0e7c3f2b |
children | 1d1d5d9bd884 |
rev | line source |
---|---|
86923 | 1 ;;; format-spec.el --- functions for formatting arbitrary formatting strings |
2 | |
3 ;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, | |
100908 | 4 ;; 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc. |
86923 | 5 |
6 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org> | |
7 ;; Keywords: tools | |
8 | |
9 ;; This file is part of GNU Emacs. | |
10 | |
94678
ee5932bf781d
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
11 ;; GNU Emacs is free software: you can redistribute it and/or modify |
86923 | 12 ;; it under the terms of the GNU General Public License as published by |
94678
ee5932bf781d
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
13 ;; the Free Software Foundation, either version 3 of the License, or |
ee5932bf781d
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
14 ;; (at your option) any later version. |
86923 | 15 |
16 ;; GNU Emacs is distributed in the hope that it will be useful, | |
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 ;; GNU General Public License for more details. | |
20 | |
21 ;; You should have received a copy of the GNU General Public License | |
94678
ee5932bf781d
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
86923 | 23 |
24 ;;; Commentary: | |
25 | |
26 ;;; Code: | |
27 | |
28 (eval-when-compile (require 'cl)) | |
29 | |
30 (defun format-spec (format specification) | |
31 "Return a string based on FORMAT and SPECIFICATION. | |
32 FORMAT is a string containing `format'-like specs like \"bash %u %k\", | |
33 while SPECIFICATION is an alist mapping from format spec characters | |
34 to values. Any text properties on a %-spec itself are propagated to | |
35 the text that it generates." | |
36 (with-temp-buffer | |
37 (insert format) | |
38 (goto-char (point-min)) | |
39 (while (search-forward "%" nil t) | |
40 (cond | |
41 ;; Quoted percent sign. | |
42 ((eq (char-after) ?%) | |
43 (delete-char 1)) | |
44 ;; Valid format spec. | |
45 ((looking-at "\\([-0-9.]*\\)\\([a-zA-Z]\\)") | |
46 (let* ((num (match-string 1)) | |
47 (spec (string-to-char (match-string 2))) | |
48 (val (cdr (assq spec specification)))) | |
49 (unless val | |
50 (error "Invalid format character: `%%%c'" spec)) | |
51 ;; Pad result to desired length. | |
52 (let ((text (format (concat "%" num "s") val))) | |
53 ;; Insert first, to preserve text properties. | |
54 (insert-and-inherit text) | |
55 ;; Delete the specifier body. | |
56 (delete-region (+ (match-beginning 0) (length text)) | |
57 (+ (match-end 0) (length text))) | |
58 ;; Delete the percent sign. | |
59 (delete-region (1- (match-beginning 0)) (match-beginning 0))))) | |
60 ;; Signal an error on bogus format strings. | |
61 (t | |
62 (error "Invalid format string")))) | |
63 (buffer-string))) | |
64 | |
65 (defun format-spec-make (&rest pairs) | |
66 "Return an alist suitable for use in `format-spec' based on PAIRS. | |
67 PAIRS is a list where every other element is a character and a value, | |
68 starting with a character." | |
69 (let (alist) | |
70 (while pairs | |
71 (unless (cdr pairs) | |
72 (error "Invalid list of pairs")) | |
73 (push (cons (car pairs) (cadr pairs)) alist) | |
74 (setq pairs (cddr pairs))) | |
75 (nreverse alist))) | |
76 | |
77 (provide 'format-spec) | |
78 | |
93975
1e3a407766b9
Fix up comment convention on the arch-tag lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87649
diff
changeset
|
79 ;; arch-tag: c22d49cf-d167-445d-b7f1-2504d4173f53 |
86923 | 80 ;;; format-spec.el ends here |