Mercurial > emacs
annotate lisp/fadr.el @ 103504:b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
* progmodes/gdb-ui.el: ... this file.
* progmodes/gud.el: Modify for gdb-mi.el.
* fadr.el: New file.
author | Nick Roberts <nickrob@snap.net.nz> |
---|---|
date | Sun, 21 Jun 2009 12:08:53 +0000 |
parents | |
children | f1303f5d7a0d |
rev | line source |
---|---|
103504
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
1 ;;; fadr.el --- convinient access to recursive list structures |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
2 |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
3 ;; Copyright (C) 2009 Free Software Foundation, Inc. |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
4 |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
5 ;; Author: Dmitry Dzhus <dima@sphinx.net.ru> |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
6 ;; Keywords: lisp, internal |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
7 |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
8 ;; This program is free software; you can redistribute it and/or modify |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
9 ;; it under the terms of the GNU General Public License as published by |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
10 ;; the Free Software Foundation, either version 3 of the License, or |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
11 ;; (at your option) any later version. |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
12 |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
13 ;; This program is distributed in the hope that it will be useful, |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
16 ;; GNU General Public License for more details. |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
17 |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
18 ;; You should have received a copy of the GNU General Public License |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
19 ;; along with this program. If not, see <http://www.gnu.org/licenses/>. |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
20 |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
21 ;;; Commentary: |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
22 |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
23 ;; This code allows accessing data stored in recursive association and |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
24 ;; plain lists using a compact notation. |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
25 ;; |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
26 ;; Consider the following list: |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
27 ;; |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
28 ;; (setq basket '((apples . (((color . green) (taste . delicious)) ((color . red) (taste . disgusting)))))) |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
29 ;; |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
30 ;; Its contents may be accessed using `fadr-member': |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
31 ;; |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
32 ;; (fadr-member basket ".apples[1].color") |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
33 ;; red |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
34 ;; |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
35 ;; Associated values are selected using a dot followed by a key, while |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
36 ;; lists accept an index (0-based) in square brackets. |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
37 ;; |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
38 ;; `fadr-q' is a one-argument shortcut fro `fadr-member', where |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
39 ;; (fadr-q "res.path") results to (fadr-member res ".path"): |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
40 ;; |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
41 ;; (fadr-q "basket.apples[0].taste") |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
42 ;; delicious |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
43 ;; |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
44 ;; `fadr-expand' substitutes ~PATH with results of `fadr-member' calls |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
45 ;; with respective arguments: |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
46 ;; |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
47 ;; (fadr-expand "~.color apple is ~.taste" (fadr-member basket ".apples[0]")) |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
48 ;; "green apple is delicious" |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
49 ;; |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
50 ;; `fadr-format' is like `fadr-expand', but it performs %-substitutions first: |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
51 ;; |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
52 ;; (fadr-format "%s #%d is ~.color and ~.taste" (fadr-member basket ".apples[1]") "Apple" 1) |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
53 ;; "Apple #1 is red and disgusting" |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
54 |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
55 ;;; Code: |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
56 |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
57 (defun fadr-get-field-value (field object) |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
58 "Get value of FIELD from OBJECT. |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
59 |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
60 FIELD is a symbol." |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
61 (cdr (assoc field object))) |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
62 |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
63 (defsubst bol-regexp (regexp) |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
64 (concat "^" regexp)) |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
65 (defconst fadr-field-name-regexp |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
66 "[[:alpha:]_-]+") |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
67 (defconst fadr-field-selector-regexp |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
68 (concat "\\.\\(" fadr-field-name-regexp "\\)")) |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
69 (defconst fadr-index-selector-regexp |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
70 "\\[\\([[:digit:]]+\\)\\]") |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
71 (defconst fadr-path-regexp |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
72 (concat "\\(" fadr-field-selector-regexp "\\|" |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
73 fadr-index-selector-regexp |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
74 "\\)+")) |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
75 |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
76 (defmacro fadr-define-select (name regexp &optional doc filter) |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
77 "Define a function NAME of one string argument which will |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
78 extract data from it using the first subgroup in REGEXP. If |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
79 FILTER is specified, it will be called with the resulting |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
80 string." |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
81 `(defun ,name (path) |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
82 ,doc |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
83 (let ((string (if (string-match ,regexp path) |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
84 (match-string-no-properties 1 path) |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
85 nil))) |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
86 (if string |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
87 ,(if filter |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
88 `(funcall ,filter string) |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
89 'string) |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
90 nil)))) |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
91 |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
92 (fadr-define-select fadr-index-select |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
93 (bol-regexp fadr-index-selector-regexp) |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
94 "Extract name of the next field selected in PATH as a symbol." |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
95 'string-to-number) |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
96 |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
97 ;; Bad case: (fadr-field-select ".nil") |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
98 (fadr-define-select fadr-field-select |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
99 (bol-regexp fadr-field-selector-regexp) |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
100 "Extract value of the next list index selected in PATH as a |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
101 number." |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
102 'intern) |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
103 |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
104 ;; TODO: define this function using macros to ease the adding of new |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
105 ;; selector types |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
106 (defun fadr-member (object path) |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
107 "Access data in OBJECT using PATH. |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
108 |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
109 This function is not match-safe, meaning that you may need to |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
110 wrap a call to it with `save-match-data'." |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
111 (if (string= path "") |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
112 object |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
113 (let ((index (fadr-index-select path)) |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
114 (field (fadr-field-select path))) |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
115 (cond (index |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
116 (fadr-member (elt object index) |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
117 (fadr-peel-path path))) |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
118 (field |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
119 (fadr-member (fadr-get-field-value field object) |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
120 (fadr-peel-path path))) |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
121 (t (error "Bad path")))))) |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
122 |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
123 (defun fadr-q (full-path) |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
124 (catch 'bad-path |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
125 (if (string-match fadr-path-regexp full-path) |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
126 (if (not (= (match-beginning 0) 0)) |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
127 (let ((object (eval (intern (substring full-path 0 (match-beginning 0))))) |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
128 (path (substring full-path (match-beginning 0)))) |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
129 (fadr-member object path)) |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
130 (throw 'bad-path (error "No object specified"))) |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
131 (throw 'bad-path (error "Incorrect path"))))) |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
132 |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
133 (defun fadr-peel-path (path) |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
134 "Return PATH without first selector." |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
135 (cond ((fadr-field-select path) |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
136 (string-match (bol-regexp fadr-field-selector-regexp) path)) |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
137 ((fadr-index-select path) |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
138 (string-match (bol-regexp fadr-index-selector-regexp) path)) |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
139 (t (error "Could not peel path"))) |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
140 (substring path (match-end 0))) |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
141 |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
142 (defun fadr-expand (string object) |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
143 "Format STRING using OBJECT members. |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
144 |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
145 All ~.<path> substrings within STRING are replaced with |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
146 respective values of OBJECT members." |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
147 (replace-regexp-in-string |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
148 (concat "~\\(" fadr-path-regexp "\\)") |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
149 #'(lambda (text) |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
150 (save-match-data |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
151 (format "%s" |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
152 (fadr-member object (substring text 1))))) |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
153 string)) |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
154 |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
155 (defun fadr-format (string object &rest objects) |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
156 "Format STRING with OBJECTS, then `fadr-expand' the result with |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
157 OBJECT." |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
158 (let ((new-string (apply 'format (append (list string) objects)))) |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
159 (fadr-expand new-string object))) |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
160 |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
161 (provide 'fadr) |
b2b747edcf7e
* progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff
changeset
|
162 ;;; fadr.el ends here |