Events 将emacs用户活动保存到磁盘

Events 将emacs用户活动保存到磁盘,events,emacs,save,focus,buffer,Events,Emacs,Save,Focus,Buffer,我想把更多的办公室工作转移到Emacs。 每次保存缓冲区时,我都要将以下信息附加到%APPDATA%\log.csv文件中, 将焦点移动到另一个应用程序/缓冲区或退出Emacs 时间戳(yyyy-mm-dd hh:mm)选项卡事件(保存、关闭、聚焦)选项卡 位置(例如缓冲区中的行号,但最好是文本 在组织模式文件的当前分支条目中)EndOfLine 其他进程将类似的信息记录到同一个文件中,以便进行附加 必须确保在出现问题时发出警告。 任何专门针对这一点的东西都会大有帮助 我目前有两个问题,我在

我想把更多的办公室工作转移到Emacs。 每次保存缓冲区时,我都要将以下信息附加到%APPDATA%\log.csv文件中, 将焦点移动到另一个应用程序/缓冲区或退出Emacs

  • 时间戳(yyyy-mm-dd hh:mm)选项卡事件(保存、关闭、聚焦)选项卡 位置(例如缓冲区中的行号,但最好是文本 在组织模式文件的当前分支条目中)EndOfLine
其他进程将类似的信息记录到同一个文件中,以便进行附加 必须确保在出现问题时发出警告。 任何专门针对这一点的东西都会大有帮助

我目前有两个问题,我在本文的最后给出。 emacs使用以下代码存储信息

(defun monthly-log-file ()
(interactive)
(let ((monthly-name (format-time-string "%Y%m")))
(find-file (expand-file-name (concat (getenv "AppData") "/OooData/log" monthly-name ".csv")))))

(defun append-string-to-file (string filename)         
"Appends STRING to FILENAME."                        
(interactive)                                        
(append-to-file (concat string "\n") nil filename))

(defun save-log-after-save-hook ()
(setq user-test-file
(expand-file-name (concat (getenv "AppData") "/OooData/log" (format-time-string "%Y%m") ".csv"))) 
(append-string-to-file (mapconcat 'identity 
                (list (format-time-string  "%Y-%m-%d %H:%M:%S" (current-time))
                  "emacs" buffer-file-name "fix org branch") "\t") user-test-file ))

(add-hook 'after-save-hook 'save-log-after-save-hook)

(when (>= emacs-major-version 24.4)
(add-hook 'focus-out-hook 'save-log-after-save-hook))
但有时录音是不可能的,我得到以下警告: 打开输出文件:权限被拒绝,c:/Users/jerzy/AppData/Roaming/OooData/log201509.csv

从OpenOffice保存时,我使用了4个循环,这实际上消除了任何类似的情况

sub appendTextLigneToFile(s$)
'calls: fnGetLogFileUrl
Const CN = "appendTextLigneToFile"
dim CRLF : CRLF = chr(13) & chr(10)
dim EOL : EOL = chr(10)

dim sURL$ :  sURL = fnGetLogFileUrl

dim sfa as object, tos as object
sfa = CreateUnoService("com.sun.star.ucb.SimpleFileAccess")
tos = CreateUnoService("com.sun.star.io.TextOutputStream")
dim size&
if FileExists(sURL) then size = sfa.getSize(sURL)
dim stream
dim i&
for i = 0 to 3
on error resume next
stream = sfa.openFileReadWrite(sURL)
if not isEmpty(stream) then exit for
on error goto 0
wait 500
next
if isEmpty(stream) then goto ExitWithInfo
dim ios as object
on error goto errorhandler
ios = stream.getInputStream()
ios.skipBytes(size)
tos.setOutputStream(stream.getOutputStream())
'oOutputStream.setEncoding( "UCS2" )
ios.setEncoding( "UTF-8" )  '
tos.writeString(s & EOL)
errorhandler: 
If (err <> 0) Then MsgBox Error, 16, CN
on error Resume Next
if not isNull(tos) then tos.closeOutput()
if not isNull(ios) then ios.closeInput()
If (err <> 0) Then MsgBox "obj closing problem", 16, CN
Exit Sub

ExitWithInfo:
MsgBox "File " & convertfromurl(sURL) & " is locked and timeout was exceeded.",48
end sub
sub-appendTextLigneToFile(s$)
'调用:fnGetLogFileUrl
Const CN=“appendTextLigneToFile”
尺寸CRLF:CRLF=chr(13)和chr(10)
尺寸下线:下线=chr(10)
dim sURL$:sURL=fnGetLogFileUrl
将sfa作为对象,将tos作为对象
sfa=CreateUnoService(“com.sun.star.ucb.SimpleFileAccess”)
tos=CreateUnoService(“com.sun.star.io.TextOutputStream”)
暗淡的尺寸&
如果文件存在(sURL),则size=sfa.getSize(sURL)
暗流
昏暗的我&
对于i=0到3
出错时继续下一步
stream=sfa.openFileReadWrite(sURL)
如果不是isEmpty(流),则退出以获取
错误转到0
等500
下一个
如果是空的(流),则转到ExitWithInfo
将ios作为对象
关于错误转到错误处理程序
ios=stream.getInputStream()
ios.skipBytes(大小)
tos.setOutputStream(stream.getOutputStream())
'oOutputStream.setEncoding(“UCS2”)
ios.setEncoding(“UTF-8”)'
tos.writeString(s&EOL)
错误处理程序:
如果为(错误0),则MsgBox错误,16,CN
出错时继续下一步
如果不为isNull(tos),则tos.closeOutput()
如果不是isNull(ios),则为ios.closeInput()
如果(错误0),则MsgBox“obj关闭问题”,16,CN
出口接头
ExitWithInfo:
MsgBox“文件”&convertfromurl(sURL)&“已锁定且超过超时”。48
端接头
我不是lisp程序员,但我正试图解决以下两个问题:

  • 在写入文件时修改函数append string to file,以消除权限被拒绝时可能出现的问题(当然,如果文件不再被阻止)
  • 在组织模式下,从分支行获取一些文本,将其传递给上述函数

向我们展示您已经尝试过的代码,并向我们展示它是如何工作的。因此,这不是一个代码编写服务。向我们展示您已经尝试过的代码,并向我们展示它是如何不起作用的。因此,这不是一个代码编写服务。