在缓冲区中添加时间 [英] Add times in buffer

查看:182
本文介绍了在缓冲区中添加时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个emacs缓冲区,它包含格式分钟'秒',格式分钟'以及秒''例如5'30,6'15,10'和1 ''。输出(在微型缓冲区中)以分钟'秒('= 21'46''的格式自动在缓冲区中添加所有时间?

解决方案

这是你想要的吗?

 (defun add-times()
(交互式)
(let((分钟0)(秒0))
(save-excursion
(goto-char(point-min))
(while重新搜索转发\\([0-9] + \\)'\\('\\)?(point-max)t)
(if( match-string 2)
(setq seconds(+ seconds(string-to-number(match-string 1))))
(setq minutes(+ minutes(string-to-number 1))))))))
(插入(格式%d'%d'(+分钟(/秒60))(%秒60)))))


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'')?

解决方案

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)))))

这篇关于在缓冲区中添加时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆