Q:

Add times in buffer

Suppose I have an emacs buffer which contains times in the format minutes'seconds'' and in the format minutes' as well as seconds'' for example 5'30'', 6'15'', 10' and 1''.  Is it possible to add all times in the buffer automatically with output (in the minibuffer) in the format minutes'seconds'' (here = 21'46'')? 

A:

Is this what you want? 
(defun add-times ()                 
  (interactive)                                
  (let ((minutes 0) (seconds 0))     
    (save-excursion                        
      (goto-char (point-min))
      (while (re-search-forward "\\([0-9]+\\)'\\('\\)?" ( point-max) t)
        (if (match-string 2)
            (setq seconds (+ seconds (string-to-number (match-string 1))))
          (setq minutes (+ minutes (string-to-number (match-string 1)))))))
    (insert (format "%d'%d''"(+ minutes (/ seconds 60)) (% seconds 60)))))

