在.mailrc
,我想獲得第一行,但我得到了第二排的elisp:獲得引號格式/回聲
alias UIF "UIF Boxning <[email protected]>" # cool (written manually by me)
alias test_alias test_name <test_mail> # no quotation marks (written by below defun)
我不能確定問題是否與format
或echo
。看一看:
(defun save-mail-address (address name alias)
"add an alias to the .mailrc file"
(interactive "sMail address: \nsFull name: \nsAlias: ")
(let ((compl-alias (format "alias %s \"%s \<%s\>\"" alias name address)))
(shell-command (concat "echo " compl-alias " >> .mailrc"))))
(defalias 'sma 'save-mail-address)
編輯:
OK,我們的目標是保持這樣的:
alias long "Long Long <[email protected]>" # 123456
alias s "S S <[email protected]>" # 1
也,言我檢查,這樣不會有重複:
(defun append-blanks (str len)
(concat str (make-string (- len (length str)) ?)))
(defun save-mail-address (mail name alias phone)
"add an alias to the .mailrc file"
(interactive "sMail mail: \nsFull name: \nsAlias: \nnPhone: ")
(let*(
(alias-alias (format "alias %s" alias))
(alias-alias-blanks (append-blanks alias-alias 16))
(mail-str (append-blanks (format "\"%s \<%s\>\"" name mail) 48))
(line (format "%s%s\# %d\n" alias-alias-blanks mail-str phone))
(file "~/.mailrc"))
(with-temp-buffer
(insert-file file)
(if
(search-forward alias-alias (point-max) t) ; t = return nil on fail
(message (format "Error: The alias %s is already in use." alias))
(progn
(insert line)
(sort-columns nil (point-min) (point-max)) ; nil = not reversed
(write-file file nil)))))) ; nil = inhibit confirm
這樣做將是一個緩衝區來參觀.mailrc中,添加文字,保存在緩衝區,殺死它的Lispy方式。 – tripleee
對,雖然我的解決方案可以工作(具有以下幫助),但它具有創建空的'* Shell Command Output *'緩衝區的煩人副作用。但是,與其重新完成整個事情,我認爲我會在代碼中最後殺死_that_緩衝區,並在下一次提取您的建議。 –