org-mode link中的中文路径变乱码

之前电脑是win7,前几天换成win10。在电脑上使用emacs org-mode管理一些笔记文件。在win7的时候正常的。换成win10后org文件的link中的中文文件名称变成了乱码,但其他位置都中文显示都是好的。截图录屏_选择区域_20210421155453

通过“ctrl-x Enter r”切换文件编码好像也只影响到link外面都文字编码。还请各位大神指教解法!

谢谢,我已经解决了。不过遗憾的是elisp不大会用 :money_mouth_face:;用python的urllib.parse.unquote()把整个文档刷了一遍就把url百分码吗转回来了;

我自己卖自己的瓜吧,呵呵!
照@wsug的提示,我使用python的urllib转码暂时解决了问题,但是觉得这样不够完美;再次研究了wsug提供的网页,发现这个页面:
http://ergoemacs.org/emacs/emacs_url_percent_decode.html
上面提供了两个函数可以编解url码;根据这两个函数我又简单包装了一下,定义了快捷键;整体结局方案如下:

      (defun xah-html-encode-percent-encoded-url ()
          "Percent encode URL in current line or selection.
          Example:
          http://example.org/(Dürer)
          becomes
          http://example.org/(D%C3%BCrer)

          Example:
          http://example.org/文本编辑器
          becomes
          http://example.org/%E6%96%87%E6%9C%AC%E7%BC%96%E8%BE%91%E5%99%A8

          URL `http://ergoemacs.org/emacs/emacs_url_percent_decode.html'     
         Version 2018-10-26"
         ;; (interactive)
        (let ($p1 $p2 $input-str $newStr)
             (if (use-region-p)
                  (setq $p1 (region-beginning) $p2 (region-end))
                  (setq $p1 (line-beginning-position) $p2 (line-end-position)))
                  (setq $input-str (buffer-substring-no-properties $p1 $p2))
                  (require 'url-util)
                  (setq $newStr (url-encode-url $input-str))
                  (if (string-equal $newStr $input-str)
                      (progn (message "no change" ))
                      (progn
                      (delete-region $p1 $p2)
                      (insert $newStr)))))

      (defun xah-html-decode-percent-encoded-url ()
          "Decode percent encoded URL of current line or selection.

          Example:
           %28D%C3%BCrer%29
          becomes
           (Dürer)

          Example:
           %E6%96%87%E6%9C%AC%E7%BC%96%E8%BE%91%E5%99%A8
          becomes
           文本编辑器

          URL `http://ergoemacs.org/emacs/emacs_url_percent_decode.html'
          Version 2018-10-26"
          ;; (interactive)     
      (let ( $p1 $p2 $input-str $newStr)
            (if (use-region-p)
                (setq $p1 (region-beginning) $p2 (region-end))
                (setq $p1 (line-beginning-position) $p2 (line-end-position)))
                (setq $input-str (buffer-substring-no-properties $p1 $p2))
                (require 'url-util)
                (setq $newStr (url-unhex-string $input-str))
                (if (string-equal $newStr $input-str)
                (progn (message "no change" ))
                (progn
                (delete-region $p1 $p2)
               (insert (decode-coding-string $newStr 'utf-8))))))

          ;; 把原函数的interactive特性去掉,自己包装了一下
          ;; 如果想直接对整个buffer转码,就把mark-whole-buffer前面的注释去掉
          (defun buffer-url-decode()
                (interactive)
                ;; (mark-whole-buffer)
                (xah-html-decode-percent-encoded-url))

          (defun buffer-url-encode()
               (interactive)
               ;; (mark-whole-buffer)
               (xah-html-encode-percent-encoded-url))

          ;; 设置全局快捷键
          (global-set-key (kbd "C-x RET d") 'buffer-url-decode)
          (global-set-key (kbd "C-x RET e") 'buffer-url-encode)
3 个赞