1

では.mailrc、1 行目を取得したいのですが、2 行目を取得します。

alias UIF "UIF Boxning <uifboxning@boxing.se>" # 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 <long@long.long>"                    # 123456
alias s         "S S <s@s.s>"                                   # 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
4

2 に答える 2

3

シェルコマンドに渡される変数引数が常に適切にエスケープされるようにする必要があります。

(shell-command (concat "echo " (shell-quote-argument compl-alias)))
于 2012-06-19T05:13:30.260 に答える
1

Elisp でテキストを追加すると、次のようになります。

(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)))
    (with-temp-buffer
      (insert compl-alias "\n")
      (write-region (point-min) (point-max) "~/.mailrc" t))))
于 2012-06-19T09:53:50.877 に答える