This file is indexed.

/usr/share/guile-gnome-2/gnome/contrib/help-browser.scm is in guile-gnome2-gtk 2.16.1-6ubuntu2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
;; guile-gnome
;; Copyright (C) 2003,2004 Andy Wingo <wingo at pobox dot com>

;; This program 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 2 of   
;; the License, or (at your option) any later version.              
;;                                                                  
;; This program 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 this program; if not, contact:
;;
;; Free Software Foundation           Voice:  +1-617-542-5942
;; 59 Temple Place - Suite 330        Fax:    +1-617-542-2652
;; Boston, MA  02111-1307,  USA       gnu@gnu.org

;;; Commentary:
;;
;;A help browser for guile-gnome applications. Designed to be used with
;;stexinfo documents.
;;
;;There can only be one help browser in an application.
;;
;;Example use:
;;
;;@example
;; (use-modules (gnome gtk) (gnome contrib help-browser))
;;
;; ;; optional
;; (set-default-help-document! @var{my-stexi-doc}) ;; optional
;;
;; ;; @var{document} can be a nodal tree or an stexi document
;; (add-help-root! @var{document})
;;
;; ;; shows default page
;; (show-help)
;;
;; ;; shows the node named @var{node}
;; (show-help @var{node})
;;
;; ;; shows the node named @var{node} in manual (root) @var{root}
;; (show-help @var{node} @var{root})
;;@end example
;;
;;; Code:

(define-module (gnome contrib help-browser)
  #:use-module (ice-9 optargs)
  #:use-module (oop goops)
  #:use-module (gnome gobject)
  #:use-module (gnome glib)
  #:use-module (gnome gtk)
  #:use-module (srfi srfi-13)
  #:use-module (texinfo)
  #:use-module (texinfo indexing)
  #:use-module (sxml simple)
  #:use-module (container nodal-tree)
  #:use-module (container delay-tree)
  #:use-module (gnome contrib texinfo-buffer)
  #:use-module (gnome contrib delay-tree-model)
  #:use-module (gnome contrib filtered-list)
  #:export (set-default-help-document! add-help-root! show-help
            populate-help-hook the-help-window))

(warn "(gnome contrib help-browser) is still in development. ")
(warn "It might eat your baby! In any case, don't rely on it yet.")

(pk "mmm, babies taste good")

;; Add a `buffer' column to a normal delay-tree-model
(define-class <help-tree> (<delay-tree-model>))
(define-method (on-get-n-columns (obj <help-tree>))
  3) ;; name, value, buffer
(define-method (on-get-column-type (obj <help-tree>) index)
  (case index
    ((2) <gboxed-scm>)
    (else (next-method))))
(define-method (on-get-value (obj <help-tree>) iter index)
  (case index
    ((2)
     (or (node-ref iter 'buffer)
         (let ((buf (stexi->gtk-text-buffer (force-ref iter 'value))))
           (node-set! iter 'buffer buf)
           buf)))
    (else
     (next-method))))

(define default-document
  '(texinfo
    (% (title "guile-gnome help browser"))
    (node (% (name "top")))
    (chapter "Help")
    (para
     "Welcome to guile-gnome's help system.")
    (para
     "The available sections can be browsed on the left.")
    (para
     "If you are looking for something specific, try the index.")
    (para
     "(This message can be customized. See the documentation for details.)")))

(define default-buffer #f)

;; exported
(define (set-default-help-document! document)
  "Doc me"
  (or (eq? (car document) 'texinfo)
      (error "The default help document must be stexinfo."))
  (set! default-buffer #f)
  (set! default-document document))

(define the-help-tree (make <help-tree>))

(define (add-help-root! document)
  (append-root! the-help-tree document))

;; the index
(define-class <help-index> (<filtered-list-model>))
(define-method (on-get-n-columns (obj <help-index>))
  3) ;; name, node name, tree-iter
(define-method (on-get-column-type (obj <help-index>) index)
  (case index
    ((0 1) <gchararray>)
    ((2) (gtype-name->class "GtkTreeIter"))
    (else (error "Invalid index" index))))
(define-method (on-get-value (obj <help-index>) iter index)
  (case index
    ((0 1 2)
     (list-ref iter index))
    (else
     (error "Invalid index" index))))
(define-method (set-filter (obj <help-index>) filter)
  (define (make-index)
    (let loop ((index '()) (iter (iter-nth-child the-help-tree #f 0)))
      (if (not iter)
          (sort! index (lambda rows (apply string-ci<=? (map car rows))))
          (let ((this-index (map
                             (lambda (x) (list (car x) (cdr x) iter))
                             (stexi-extract-index
                              (get-value the-help-tree iter 1) #f 'all)))
                (kids-index (let ((iter (iter-nth-child the-help-tree iter 0)))
                              (if iter (loop '() iter) '()))))
            (loop (append this-index kids-index index)
                  (iter-next the-help-tree iter))))))

  (if (null? (slot-ref obj 'list))
      ;; Don't actually do the indexing until the first filter is set,
      ;; that is, until the user has typed something in the search box
      (slot-set! obj 'list (make-index)))
  (next-method))

(define the-help-window #f)

;; the parts of the help window that we want to remember
(define *topics-treeview* #f)
(define *textbuffer* #f)
(define *textview* #f)
(define *current-node* #f)

(define (get-help-buffer iter)
  (cond
   (iter (get-value the-help-tree iter 2))
   (default-buffer default-buffer)
   (else
    (set! default-buffer (stexi->gtk-text-buffer default-document))
    default-buffer)))

(define (get-help-mark iter node-name)
  (get-mark (get-help-buffer iter) (string-append "node-" node-name)))

(define (make-help-window)
  (define (add-topics-page w notebook)
    (let* ((treemodel the-help-tree)
           (treeview (make <gtk-tree-view> #:model treemodel #:headers-visible #f))
           (scroll (make <gtk-scrolled-window>
                     #:hscrollbar-policy 'automatic #:vscrollbar-policy 'automatic
                     #:shadow-type 'in))
           (cellrenderer (make <gtk-cell-renderer-text>))
           (column (make <gtk-tree-view-column>))
           (selection (get-selection treeview)))
      (set! *topics-treeview* treeview)
      (append-page notebook scroll (make <gtk-label> #:label "Topics"))
      (add scroll treeview)
      (set-mode selection 'single)
      (pack-start column cellrenderer #t)
      (add-attribute column cellrenderer "text" 0)
      (append-column treeview column)
      (connect
       selection 'changed
       (lambda (selection)
         (call-with-values (lambda () (get-selected selection))
           (lambda (model iter)
             (set! *current-node* iter)
             (set-buffer *textview* (get-help-buffer iter))
             (set the-help-window 'title
                  (if iter
                      (get-value the-help-tree iter 0)
                      (sxml->string
                       (assq-ref (cdadr default-document) 'title))))))))
      (emit selection 'changed)))

  (define (add-index-page w notebook)
    ;; The "Index" page
    (let* ((vbox (make <gtk-vbox>))
           (entry (make <gtk-entry>))
           (list (make <gtk-tree-view>))
           (treemodel (make <help-index>))
           (scroll (make <gtk-scrolled-window>
                     #:hscrollbar-policy 'automatic #:vscrollbar-policy 'automatic
                     #:shadow-type 'in))
           (treeview (make <gtk-tree-view> #:model treemodel #:headers-visible #f))
           (cellrenderer (make <gtk-cell-renderer-text>))
           (column (make <gtk-tree-view-column>))
           (selection (get-selection treeview)))
      (append-page notebook vbox (make <gtk-label> #:label "Index"))
      (pack-start vbox entry #f #f 0)
      (pack-start vbox scroll #t #t 0)
      (add scroll treeview)
      (set-mode selection 'single)
      (pack-start column cellrenderer #t)
      (add-attribute column cellrenderer "text" 0)
      (append-column treeview column)
      (set-text entry "(indexing takes some time)")
      (select-region entry 0 -1)
      (connect
       entry 'changed
       (lambda (entry)
         (let ((text (get-text entry)))
           (set-filter treemodel
                       (if (equal? text "")
                           #f
                           (lambda (row)
                             (string-contains-ci (car row) text)))))))
      (connect
       selection 'changed
       (lambda (selection)
         (call-with-values (lambda () (get-selected selection))
           (lambda (model iter)
             (if iter
                 (select-node (get-value model iter 2)
                              (get-value model iter 1)))))))))

  (let* ((w (make <gtk-window>
              #:default-height 400
              #:default-width 700))
         (textbuffer (make <gtk-text-buffer>))
         (textview (make <gtk-text-view>
                     #:editable #f #:cursor-visible #f #:wrap-mode 'word
                     #:pixels-above-lines 2 #:pixels-below-lines 6
                     #:pixels-inside-wrap 1 ;; #:justification 'fill <- not supported yet
                     #:right-margin 10 #:left-margin 10))
         (pane (make <gtk-hpaned> #:position 200))
         (notebook (make <gtk-notebook> #:show-border #f))
         (text-scroll (make <gtk-scrolled-window>
                        #:hscrollbar-policy 'automatic #:vscrollbar-policy 'automatic
                        #:shadow-type 'in)))
    
    (add w pane)
    (pack1 pane notebook #f #t)
    (pack2 pane text-scroll #t #t)
    (add text-scroll textview)
    (set! the-help-window w)
    (set! *textbuffer* textbuffer)
    (set! *textview* textview)
    
    (connect w 'delete-event (lambda (w e) (hide w) #t))
    
    (add-topics-page w notebook)
    (add-index-page w notebook)
    
    (show-all w)
    (hide w)))

;; If manual-name is #f, look in the currently selected manual.
;; If node-name is #f, select the top of the manual.
(define (find-node node-name manual-name)
  (define (find-node-named top name)
    (or-map
     (lambda (node)
       (if (get-help-mark node name)
           node
           (find-node-named node name)))
     (iter-children the-help-tree top)))
  (let ((manual (if manual-name
                    (let loop ((manual (get-iter-first the-help-tree)))
                      (cond
                       ((not manual)
                        (error "Unknown manual:" manual-name))
                       ((string=? (get-value the-help-tree manual 0)
                                  manual-name)
                        manual)
                       (else
                        (loop (iter-next the-help-tree manual)))))
                    (if (not *current-node*)
                        (error
                         "The TOP node must specify a manual in its cross-references.")
                        (let find-top ((node *current-node*))
                          (let ((parent (iter-parent the-help-tree node)))
                            (if (not parent)
                                node
                                (find-top parent))))))))

    (if (and node-name (not (string=? node-name "top")))
        (or
         (find-node-named manual node-name)
         (error "No such node in manual:" manual-name node-name))
        manual)))

(define (select-node iter node-name)
  (let* ((treeview *topics-treeview*)
         (path (get-path the-help-tree iter)))
    (expand-to-path treeview path)
    (select-path (get-selection treeview) path)
    (scroll-to-cell treeview path #f #f 0 0))
    ;; now the buffer should be correct...
    ;; scroll in an idle loop to give the textview time to compute line heights
    (g-idle-add
     (lambda ()
       (scroll-to-mark *textview*
                       (if node-name
                           (get-help-mark iter node-name)
                           (create-mark (get-help-buffer iter)
                                        #f
                                        (get-start-iter (get-help-buffer iter))
                                        #t))
                       0.15 #f 0 0)
       #f)))

(define populate-help-hook (make-hook 0))

(define (ensure-help-window)
  (if (not the-help-window)
      (begin
        (run-hook populate-help-hook)
        (make-help-window)))
  the-help-window)

(define* (show-help #:optional (node-name #f) (manual-name #f))
  "Show the help window. If @var{manual-name} is @code{#f}, look in the
currently selected manual. If @var{node-name} is @code{#f}, select the
top of the manual."
  (let ((window (ensure-help-window)))
    (show window)
    (if (or node-name manual-name)
        (select-node (find-node node-name manual-name) node-name))
    (present window)))

(add-hook! stexi-buffer-xref-activated-hook show-help)