annotate lisp/fadr.el @ 103713:de079772f9f1

*** empty log message ***
author Eli Zaretskii <eliz@gnu.org>
date Fri, 03 Jul 2009 14:22:35 +0000
parents b3548b2342dc
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
103517
f1303f5d7a0d Fix comment typo.
Glenn Morris <rgm@gnu.org>
parents: 103504
diff changeset
1 ;;; fadr.el --- convenient access to recursive list structures
103504
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:
103517
f1303f5d7a0d Fix comment typo.
Glenn Morris <rgm@gnu.org>
parents: 103504
diff changeset
27 ;;
103504
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
103518
b3548b2342dc Unindent and refill some doc-strings.
Glenn Morris <rgm@gnu.org>
parents: 103517
diff changeset
78 extract data from it using the first subgroup in REGEXP. If
b3548b2342dc Unindent and refill some doc-strings.
Glenn Morris <rgm@gnu.org>
parents: 103517
diff changeset
79 FILTER is specified, it will be called with the resulting string."
103504
b2b747edcf7e * progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff changeset
80 `(defun ,name (path)
b2b747edcf7e * progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff changeset
81 ,doc
b2b747edcf7e * progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff changeset
82 (let ((string (if (string-match ,regexp path)
b2b747edcf7e * progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff changeset
83 (match-string-no-properties 1 path)
b2b747edcf7e * progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff changeset
84 nil)))
b2b747edcf7e * progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff changeset
85 (if string
b2b747edcf7e * progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff changeset
86 ,(if filter
b2b747edcf7e * progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff changeset
87 `(funcall ,filter string)
b2b747edcf7e * progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff changeset
88 'string)
b2b747edcf7e * progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff changeset
89 nil))))
b2b747edcf7e * progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff changeset
90
b2b747edcf7e * progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff changeset
91 (fadr-define-select fadr-index-select
b2b747edcf7e * progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff changeset
92 (bol-regexp fadr-index-selector-regexp)
b2b747edcf7e * progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff changeset
93 "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
94 'string-to-number)
b2b747edcf7e * progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff changeset
95
b2b747edcf7e * progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff changeset
96 ;; Bad case: (fadr-field-select ".nil")
b2b747edcf7e * progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff changeset
97 (fadr-define-select fadr-field-select
b2b747edcf7e * progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff changeset
98 (bol-regexp fadr-field-selector-regexp)
b2b747edcf7e * progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff changeset
99 "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
100 number."
b2b747edcf7e * progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff changeset
101 'intern)
b2b747edcf7e * progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff changeset
102
b2b747edcf7e * progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff changeset
103 ;; 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
104 ;; selector types
b2b747edcf7e * progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff changeset
105 (defun fadr-member (object path)
b2b747edcf7e * progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff changeset
106 "Access data in OBJECT using PATH.
b2b747edcf7e * progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff changeset
107
b2b747edcf7e * progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff changeset
108 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
109 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
110 (if (string= path "")
b2b747edcf7e * progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff changeset
111 object
b2b747edcf7e * progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff changeset
112 (let ((index (fadr-index-select path))
b2b747edcf7e * progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff changeset
113 (field (fadr-field-select path)))
b2b747edcf7e * progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff changeset
114 (cond (index
b2b747edcf7e * progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff changeset
115 (fadr-member (elt object index)
b2b747edcf7e * progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff changeset
116 (fadr-peel-path path)))
b2b747edcf7e * progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff changeset
117 (field
b2b747edcf7e * progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff changeset
118 (fadr-member (fadr-get-field-value field object)
b2b747edcf7e * progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff changeset
119 (fadr-peel-path path)))
b2b747edcf7e * progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff changeset
120 (t (error "Bad path"))))))
b2b747edcf7e * progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff changeset
121
b2b747edcf7e * progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff changeset
122 (defun fadr-q (full-path)
b2b747edcf7e * progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff changeset
123 (catch 'bad-path
b2b747edcf7e * progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff changeset
124 (if (string-match fadr-path-regexp full-path)
b2b747edcf7e * progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff changeset
125 (if (not (= (match-beginning 0) 0))
b2b747edcf7e * progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff changeset
126 (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
127 (path (substring full-path (match-beginning 0))))
b2b747edcf7e * progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff changeset
128 (fadr-member object path))
b2b747edcf7e * progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff changeset
129 (throw 'bad-path (error "No object specified")))
b2b747edcf7e * progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff changeset
130 (throw 'bad-path (error "Incorrect path")))))
b2b747edcf7e * progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff changeset
131
b2b747edcf7e * progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff changeset
132 (defun fadr-peel-path (path)
b2b747edcf7e * progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff changeset
133 "Return PATH without first selector."
b2b747edcf7e * progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff changeset
134 (cond ((fadr-field-select path)
b2b747edcf7e * progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff changeset
135 (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
136 ((fadr-index-select path)
b2b747edcf7e * progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff changeset
137 (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
138 (t (error "Could not peel path")))
b2b747edcf7e * progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff changeset
139 (substring path (match-end 0)))
b2b747edcf7e * progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff changeset
140
b2b747edcf7e * progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff changeset
141 (defun fadr-expand (string object)
b2b747edcf7e * progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff changeset
142 "Format STRING using OBJECT members.
b2b747edcf7e * progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff changeset
143
b2b747edcf7e * progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff changeset
144 All ~.<path> substrings within STRING are replaced with
b2b747edcf7e * progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff changeset
145 respective values of OBJECT members."
b2b747edcf7e * progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff changeset
146 (replace-regexp-in-string
b2b747edcf7e * progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff changeset
147 (concat "~\\(" fadr-path-regexp "\\)")
b2b747edcf7e * progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff changeset
148 #'(lambda (text)
b2b747edcf7e * progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff changeset
149 (save-match-data
b2b747edcf7e * progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff changeset
150 (format "%s"
b2b747edcf7e * progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff changeset
151 (fadr-member object (substring text 1)))))
b2b747edcf7e * progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff changeset
152 string))
b2b747edcf7e * progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff changeset
153
b2b747edcf7e * progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff changeset
154 (defun fadr-format (string object &rest objects)
103518
b3548b2342dc Unindent and refill some doc-strings.
Glenn Morris <rgm@gnu.org>
parents: 103517
diff changeset
155 "Format STRING with OBJECTS, then `fadr-expand' the result with OBJECT."
103504
b2b747edcf7e * progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff changeset
156 (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
157 (fadr-expand new-string object)))
b2b747edcf7e * progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff changeset
158
b2b747edcf7e * progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff changeset
159 (provide 'fadr)
103517
f1303f5d7a0d Fix comment typo.
Glenn Morris <rgm@gnu.org>
parents: 103504
diff changeset
160
f1303f5d7a0d Fix comment typo.
Glenn Morris <rgm@gnu.org>
parents: 103504
diff changeset
161 ;; arch-tag: 4edced02-a5c3-4516-b278-3f85a12146ea
103504
b2b747edcf7e * progmodes/gdb-ui.el: Replace with ...
Nick Roberts <nickrob@snap.net.nz>
parents:
diff changeset
162 ;;; fadr.el ends here