-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
unicode characters wrong representation #39
Comments
I am invoking gnuplot from org-mode. This works fine: #+begin_src gnuplot :file gnuplot-mode-issue-39.png |
I use GNU Emacs 26.1, gnuplot 5.2 patchlevel 6. And this is my init script for gnuplot-mode. Maybe I messed up some configurations. |
Same Emacs, but Gnuplot Version 4.6 patchlevel 7. |
... on Windows by the way. |
Windows is not supported for now. Ref: #33. |
I don't use Windows |
Problem is still there. |
Nope, I get the same output with |
I'm having the same problem (finally found this issue after a lot of searching!). I'm using:
I have tried so far:
Although I'm unsure if I entered My steps to reproduce are:
;; -*- coding: utf-8; mode: elisp; -*-
;; current-language-environment is "English"
(set-language-environment "UTF-8")
;; sets the value of various coding systems
;; - coding system of a newly created buffer
;; - default coding system for subprocess I/O
;; - file-name-coding-system (if ASCII-compatible)
;; - set-terminal-coding-system
;; - set-keyboard-coding-system (if ASCII-compatible)
(set-default-coding-systems 'utf-8)
;; set clipboard and selection coding systems
(set-clipboard-coding-system 'utf-8)
(set-selection-coding-system 'utf-8)
;; add utf-8 at the front of the priority list for automatic detection
(prefer-coding-system 'utf-8)
;; coding system to be used for encoding the buffer contents on saving
(setq buffer-file-coding-system 'utf-8)
;; decide a coding system to use for a file I/O operation
(add-to-list 'file-coding-system-alist '("\\.org\\'" . utf-8) t)
;; decide a coding system to use for a process I/O operation
(add-to-list 'process-coding-system-alist '("gnuplot\\'" . utf-8) t)
;; add all descendant directories of a directory to your load-path
;; https://www.emacswiki.org/emacs/LoadPath
(let ((default-directory "~/.config/emacs/lisp/"))
(normal-top-level-add-subdirs-to-load-path))
;; add path to elpa packages for purposes of esting with emacs -Q
(add-to-list 'load-path (directory-file-name "~/.config/emacs/elpa/gnuplot-20220102.1637"))
;; disable completions for gnuplot; otherwise we get:
;; run-hooks: Symbol's function definition is void: gnuplot-context-sensitive-mode
(setq gnuplot-use-context-sensitive-completion nil)
(autoload 'gnuplot-mode "gnuplot" "Gnuplot major mode" t)
(autoload 'gnuplot-make-buffer "gnuplot" "open a buffer in gnuplot-mode" t)
(add-to-list 'auto-mode-alist '("\\.gp\\'" . gnuplot-mode) t)
;; enable org-mode
(require 'org)
;; enable gnuplot-mode
(require 'gnuplot)
;; languages to make available in org-mode
(org-babel-do-load-languages
'org-babel-load-languages
'((gnuplot . t)))
Note: I had to modify the equation a bit so that I didn't get some warnings, and I also had to disable Edit: forgot to add gnuplot-mode version. Edit 2: I forgot to mention that I tried both |
By the way, if I switch to the
I also forgot to add an image in the previous post: Slightly different, but same artifacts. Edit: decided to add the extra code that I mentioned here into the custom 'init.el' file above. |
In my case, what I could find is that---apparently---the words for the labels (the only text in my own file that had non-ascii characters) were being decoded in ISO-8859-1 (Latin-1) or possibly ISO-8858-15:
So, this is text encoded as UTF-8 that is somehow being decoded as ISO-8859-1 inside a UTF-8 encoded document (the svg). If I switch to
I'm not sure if I'm wrapping my head around this properly, but I think that that would be the previous 'MÃnimo' taken as UTF-8 and re-decoded as ISO-8859-1 inside an already ISO-8859-1 encoded document (the svg). |
Thank you for the detailed report @rolandog. I will try to reproduce your issue and investigate it, but I doubt I will be able to recreate it. I would wager that the encoding issue comes from the elisp side of things after calling `gnuplot-send-buffer-to-gnuplotˋ. I will look into it today, but I am not too familiar with the internals of the package. |
Hi again. Thank you for the detailed bug report. I am afraid that I don't have more knowledge of the issue than you do at this point, especially regarding encoding in Emacs. Could you open your test gnuplot file, remove all encoding-related configuration and execute the following in the gnuplot buffer using Second, could you inspect the variable It is quite complicated for me to debug your issue directly as I have no encoding issues on my own machine. Interestingly, the gnuplot buffer also shows me the same encoding as you, |
Hi @mtreca . Thank you for your guidance; sorry that it took me long to get back. These are now the contents of the test files: gnuplot-mode-issue-39-test.org
gnuplot-mode-issue-39-test.el;; add path to elpa packages for purposes of testing with emacs -Q
(add-to-list 'load-path (directory-file-name "~/.config/emacs/elpa/gnuplot-20220102.1637"))
;; disable completions for gnuplot; otherwise we get:
;; run-hooks: Symbol's function definition is void: gnuplot-context-sensitive-mode
(setq gnuplot-use-context-sensitive-completion nil)
(autoload 'gnuplot-mode "gnuplot" "Gnuplot major mode" t)
(autoload 'gnuplot-make-buffer "gnuplot" "open a buffer in gnuplot-mode" t)
(add-to-list 'auto-mode-alist '("\\.gp\\'" . gnuplot-mode) t)
;; enable org-mode
(require 'org)
;; enable gnuplot-mode
(require 'gnuplot)
;; languages to make available in org-mode
(org-babel-do-load-languages
'org-babel-load-languages
'((gnuplot . t))) After running: user@computer:~$ LC_ALL=en_US.UTF-8 emacs -Q --load ~/org/gnuplot-mode-issue-39-test.el ~/org/gnuplot-mode-issue-39-test.org or user@computer:~$ emacs -Q --load ~/org/gnuplot-mode-issue-39-test.el ~/org/gnuplot-mode-issue-39-test.org Here are the results. Output of M-S-: (buffer-substring-no-properties (point-min) (point-max))This was the same for either of the two commands, and for commenting out the 'set encoding utf8' line or leaving it uncommented.
And, finally... this was a bit interesting. When I launch Emacs normally (no -Q, with an init.el that has kept the encoding declarations I wrote atop)... I get value of ENCODING key from gnuplot-gui-all-types variable in Emacs with no -Q
But when launching with any of the previous commands (with P.S. I also tried changing the quotes from the strings from double to single (because I thought maybe the Gnuplot Quote Character option had something to do). I also tried saving the same script (while adding a 'set output line') to see if I could get different results, but the results were the same (I sent the buffer to gnuplot with C-c C-b). |
Thank you for the detailed reply. I think I am reaching the limits of my technical abilities here, especially given that I am fairly inexperienced with the package, or encoding in general. I might take a deeper look into the issue, but it won't be right away since I have very little free time at the moment. I am leaving the issue open in the meantime, in case anyone wants to chime in or bring a solution to the problem. |
Don't worry @mtreca. I'm very grateful for your help and support. My intention was to document the issue as thoroughly as possible so that people much smarter and experienced than I am, like yourself, could have a better shot at solving this. temporary solutionI was not able to solve this particular problem, but I was able to side-step the issue by not engaging directly through a gnuplot buffer:
In my actual test-case I think I'll have to look into writing a tsv or csv file to be able to load some data in the gnuplot scriptfile. additional cluesIt may end up being a problem from my environment variables (perhaps nl_NL.UTF-8 should be nl_NL.utf8?). I've read some reporting about possibly related bugs (see links at the end). As I had been in the process of arranging dotfiles according to the XDG Base Directory Specification, I noticed the
In the Emacs After checking the docs once again, I tried pasting the original gnuplot script file, but substituting the UTF-8 characters by their octal representations: set encoding utf8
set terminal pngcairo enhanced
set output 'gnuplot-mode-issue-39-test.png'
set grid
set xlabel "\316\261"
set ylabel "\316\224\316\262"
plot [x=0:5] exp(-x)*cos(5*x) with lines title 'I_{b} = 0,2 \320\220\320\274\320\277\320\265\321\200' And this ended up working in the terminal, and in the org-mode code block:
I'm not sure why using double quotes was necessary for the x and y labels:
I'm out of time for today, but I'll try getting more familiar with the Emacs / gnuplot and gnuplot-mode internals to try to pinpoint where exactly things are going wrong. But I guess this has helped to narrow-down the search-space for the actual bug. Related bugs or S.O. questions: |
Thanks for the extremely detailed information. You are more than welcome to give a shot at fixing the issue and contributing to the emacs-gnuplot package more generally! |
You're welcome! I have finally stumbled upon the root cause for the bug. It seems there is a licensing conflict between gnuplot (which I didn't know wasn't part of the GNU project) and a dependency used to read the lines from the terminal. To avoid that conflict, some distributions --- like Debian --- build gnuplot with editline instead of readline. After recompiling from source with Stephen Kitt's instructions, sending the buffer to gnuplot worked like a charm (as well as just pasting a script in the interactive version of the terminal, and the history file as well). A note for @matsievskiysv:
Sorry for all the trouble @mtreca. I think this issue can finally be closed, as it's not directly related to gnuplot-mode. |
Btw, I'll try reporting the bug upstream (to Ubuntu and Debian). From what I've read online libedit should've supported unicode since 2014 or 2016 by default. If this doesn't get fixed upstream, maybe I'll contribute a small section for the bottom of the README, so that others may find out WHY this may happen and a pointer on how to fix it. |
Very nice detective work @rolandog! I modified the README accordingly. We can finally close this. |
Thanks @mtreca ! Happy to have helped track down how to reproduce and fix this bug. 😄 |
Here is a test script for gnuplot:
When I run this from command line with
gnuplot test.gpi
, I get the following output:But when I open the same file in emacs and issue the command
gnuplot-send-buffer-to-gnuplot
, I get:The text was updated successfully, but these errors were encountered: