我想将更多的办公室工作转移到Emacs。 我想在每次保存缓冲区时将以下信息附加到%APPDATA%\ log.csv文件中, 将焦点移到另一个应用程序/缓冲区或退出Emacs
其他进程将相同的信息记录到同一个文件中,以便附加 如果出现问题,必须确保警告文件。 任何专门为此做的事都会有很大的帮助。
我目前在本文末尾有两个问题。 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
我不是一个lisp程序员,但我试图解决以下两个问题: