Search code examples
regexemacsemacs-helm

Navigating file using helm


I am trying to set up a function using helm to navigate a beamer file following the suggestion at : "http://blog.jenkster.com/2013/10/a-tip-for-navigating-clojure-files-in-emacs.html". I tried:

(defun helm-beamer-headlines ()
  "Display headlines for the current Beamer file."
  (interactive)
  (helm-mode t)
  (helm :sources '(((name . "Beamer Headlines")
                    (volatile)
                    (headline "^\\s\|^\\f")))))

to show only the lines starting with \f and \s (corresponding to sectioning and frame commands), and while the regexp works with emacs regexp search and helm-occur, I get no matches with M-x helm-beamer-headlines.

A minimal file that I tried it on is:

\documentclass{beamer}
\begin{document}
\section{A}
\subsection{Aa}
\frame{\frametitle{}
\begin{enumerate}
\item one
\item two
\end{enumerate}
}
\subsection{Ab}
\frame{\frametitle{}
\begin{align*}
\alpha&=\beta
\end{align*}
}
\section{B}
\subsection{Ba}
\frame{\frametitle{}
\includegraphics[width=\textwidth]{abc.png}
}
\end{document}

Solution

    1. You probably want "^\\\\s.*\\|^\\\\f.*" or at least "^\\\\s\\|^\\\\f" as your regexp. See (elisp) Syntax for Strings and (elisp) Regexp Backslash about backslashes in Lisp.

    2. I can't speak to just what you should use for Helm. But as an alternative, this is all you need if you use Icicles:

      (defun foo ()
        "..."
        (interactive)
        (icicle-search (point-min) (point-max) "^\\\\s.*\\|^\\\\f.*" t))
      

    Then M-x foo TAB in your beamer buffer. Completion candidates are the lines you want. Navigate among them using C-down etc. See the doc for Icicles search for more info.