+;; Automagically add the frame numbers in comments in a beamer file
+
+(defun ff/number-beamer-frames ()
+ "Add the frame numbers as comments after each \begin{frame}"
+ (interactive)
+
+ (save-excursion
+ (let ((total 0)
+ (n 1))
+
+ ;; First, clean-up existing numbering
+ (goto-char (point-min))
+ (while (re-search-forward "^ *\\\\begin{frame}.*\\( %% frame [0-9]* / [0-9]*\\)$" nil t)
+ (kill-region (match-beginning 1) (match-end 1))
+ )
+
+ ;; Then count the total number of frames
+ (goto-char (point-min))
+ (while (re-search-forward "^ *\\\\begin{frame}" nil t)
+ (setq total (+ total 1))
+ )
+
+ ;; Then, add the updated numbers
+ (goto-char (point-min))
+ (while (re-search-forward "^ *\\\\begin{frame}" nil t)
+ (move-end-of-line 1)
+ (insert " %% frame " (prin1-to-string n) " / " (prin1-to-string total))
+ (setq n (+ n 1))
+ )
+ )
+ )
+
+ (message "Added frame numbers in comments.")
+ )
+