@@ -367,11 +367,17 @@ selecting all possible completions for section that start with
367367(defvar bdx-search-keymap
368368 (let ((map (make-sparse-keymap )))
369369 (define-key map (kbd " C-c C-d" ) #'bdx-toggle-name-demangling )
370+ (define-key map (kbd " C-c C-f" ) #'bdx-toggle-filename )
371+ (define-key map (kbd " C-c C-t" ) #'bdx-toggle-templates )
372+ (define-key map (kbd " C-c C-s" ) #'bdx-toggle-sections )
370373 (define-key map (kbd " <tab>" ) #'bdx-complete )
371374 map)
372375 " Keymap used in minibuffer in `bdx-query' ." )
373376
374377(defvar bdx--demangle-names )
378+ (defvar bdx--show-filenames )
379+ (defvar bdx--show-templates )
380+ (defvar bdx--show-sections )
375381
376382(cl-defun bdx-query (prompt &key initial-input history require-match )
377383 " Search for single symbol with PROMPT.
@@ -391,6 +397,9 @@ a symbol."
391397 (error (buffer-string )))))
392398
393399 (setq bdx--demangle-names nil )
400+ (setq bdx--show-filenames t )
401+ (setq bdx--show-templates t )
402+ (setq bdx--show-sections t )
394403 (setq bdx--query-buffer (current-buffer ))
395404 (setq bdx--last-error nil )
396405 (bdx-data
@@ -421,24 +430,66 @@ HISTORY can be a history variable."
421430 " If non-nil, the symbols in minibuffer are demangled." )
422431
423432(defun bdx-toggle-name-demangling ()
424- " Toggle name demangling in current search session.
425- This will error if `bdx-demangle-names' is nil."
433+ " Toggle name demangling in current search session."
426434 (interactive )
427435 (setq bdx--demangle-names (not bdx--demangle-names)))
428436
437+ (defvar bdx--show-filenames t
438+ " If non-nil, the filenames are shown in the minibuffer." )
439+
440+ (defun bdx-toggle-filename ()
441+ " Toggle showing filenames in current search session."
442+ (interactive )
443+ (setq bdx--show-filenames (not bdx--show-filenames)))
444+
445+ (defvar bdx--show-templates t
446+ " If nil, the templates are hidden in the minibuffer." )
447+
448+ (defun bdx-toggle-templates ()
449+ " Toggle showing templates in current search session."
450+ (interactive )
451+ (setq bdx--show-templates (not bdx--show-templates)))
452+
453+ (defvar bdx--show-sections t
454+ " If nil, the sections are hidden in the minibuffer." )
455+
456+ (defun bdx-toggle-sections ()
457+ " Toggle showing section names in current search session."
458+ (interactive )
459+ (setq bdx--show-sections (not bdx--show-sections)))
460+
461+ (defun bdx--untemplatize-string (str )
462+ " Remove C++ templates from STR.
463+ This turns a string of the form \\= 'function<type<T>>\\= ' into
464+ \\ 'function<...>\\ '."
465+ (cl-loop with depth = 0
466+ for char across str
467+ if (eq char ?< ) do (when (eq 1 (cl-incf depth))
468+ (setq chars (nconc chars (list ?< ?. ?. ?. ))))
469+ else if (eq char ?> ) do (when (zerop (cl-decf depth))
470+ (setq chars (nconc chars (list ?> ))))
471+ else if (zerop depth) collect char into chars
472+ finally return (concat chars)))
473+
429474(defun bdx--ivy-display-transformer (string )
430475 " Return a string for displaying STRING in the minibuffer."
431476 (if-let* ((data (bdx-data string)))
432477 (cl-destructuring-bind
433478 (&key name section path demangled &allow-other-keys) data
434479 (concat
435- (if (and demangled bdx--demangle-names) demangled name)
480+ (if (and demangled bdx--demangle-names)
481+ (if bdx--show-templates
482+ demangled
483+ (bdx--untemplatize-string demangled))
484+ name)
436485 " "
437- (propertize (concat " [" section " ]" )
438- 'face 'ivy-grep-info )
486+ (and bdx--show-sections
487+ (propertize (concat " [" section " ]" )
488+ 'face 'ivy-grep-info ))
439489 " "
440- (propertize (file-relative-name (or path " " ))
441- 'face 'shadow )))
490+ (and bdx--show-filenames
491+ (propertize (file-relative-name (or path " " ))
492+ 'face 'shadow ))))
442493 " " ))
443494
444495(ivy-configure 'bdx
0 commit comments