mickeynp / ligature.el

Display typographical ligatures in Emacs
GNU General Public License v3.0
382 stars 29 forks source link

Can't use c-mode #16

Open OdinZhang opened 3 years ago

OdinZhang commented 3 years ago

I can't use c-mode when I use this package, my configure is:

(use-package ligature
  :load-path ("ligature/")
  :config
  (ligature-set-ligatures 't '("www" "ff" "fi" "ffi" "|||>" "<|||" "<==>" "<!--" "####" "~~>" "***" "||=" "||>"
                                       ":::" "::=" "=:=" "===" "==>" "=!=" "=>>" "=<<" "=/=" "!=="
                                       "!!." ">=>" ">>=" ">>>" ">>-" ">->" "->>" "-->" "---" "-<<"
                                       "<~~" "<~>" "<*>" "<||" "<|>" "<$>" "<==" "<=>" "<=<" "<->"
                                       "<--" "<-<" "<<=" "<<-" "<<<" "<+>" "</>" "###" "#_(" "..<"
                                       "..." "+++" "/==" "///" "_|_" "www" "&&" "^=" "~~" "~@" "~="
                                       "~>" "~-" "**" "*>" "*/" "||" "|}" "|]" "|=" "|>" "|-" "{|"
                                       "[|" "]#" "::" ":=" ":>" ":<" "$>" "==" "=>" "!=" "!!" ">:"
                                       ">=" ">>" ">-" "-~" "-|" "->" "--" "-<" "<~" "<*" "<|" "<:"
                                       "<$" "<=" "<>" "<-" "<<" "<+" "</" "#{" "#[" "#:" "#=" "#!"
                                       "##" "#(" "#?" "#_" "%%" ".=" ".-" ".." ".?" "+>" "++" "?:"
                                       "?=" "?." "??" ";;" "/*" "/=" "/>" "//" "__" "~~" "(*" "*)"
                                        "://"))
  (global-ligature-mode t))

When I wan't to add "\\" into that list, there will be an error My Emacs is 27.1 on Windows

mickeynp commented 3 years ago

Did you consider if your font supports that ligation? If you're on Emacs 27.1 you may get crash bugs also.

OdinZhang commented 3 years ago

I chose to use composite now and it works well now. Maybe there's some bug in this package.

skrytebane commented 3 years ago

I'm seeing the same thing. That is, Emacs (27.1 on Linux) hangs (but doesn't crash) if I open a C-, C++- or Java-file when I have the following configuration:

(add-to-list 'load-path "~/elisp/ligature")
(require 'ligature)
(ligature-set-ligatures 'prog-mode '("/*"))
(global-ligature-mode t)

(This is approximately the smallest reproducible example I could make. Font doesn't seem to matter.)

I've tried running Emacs in GDB, but it's hard to see exactly what's going on. I could try building Emacs with -O0 and have another look.

My actual configuration is the following, and it works fine if I leave /* out:

  (use-package ligature
    :config
    (ligature-set-ligatures
     'prog-mode
     '(".=" ".-" ":=" "=:=" "==" "!=" "===" "!==" "=/=" "<<-"
       "<--" "<-" "<->" "->" "-->" "->>" "<=<" "<<=" "<==" "<=>"
       "=>" "==>" "=>>" ">=>" ">>=" ">>-" ">-" "-<" "-<<" "=<<"
       "<~~" "<~" "~>" "~~>" "<<<" "<<" "<=" "<>" ">="
       ">>" ">>>" "<|" "<|>" "|>" "<$" "<$>" "$>" "<+" "<+>"
       "+>" "<*" "<*>" "*>" "{-" "-}" "//" "///"
       "/**" "**/" "*/" "</" "<!--" "www" "-->" "/>"
       "0xA" "0xB" "0xC" "0xD" "0xE" "0xF" "0x0" "0x1" "0x2"
       "0x3" "0x4" "0x5" "0x6" "0x7" "0x8" "0x9"
       ";;" ";;;" "::" ":::" "!!" "!!!" "??" "%%" "%%%"
       "&&" "&&&" "||" "|||" ".." "..." "..<" "--" "---"
       "++" "+++" "**" "***"  "~-" "-~" "=~" "~@" "^=" "?=" "~="
       "/=" "/==" "|=" "||=" "##" "###" "####" "#{" "#[" "#("
       "#?" "#_" "#_(" "#!"))
    (global-ligature-mode t)))

(I'm using Fira Code, but as mentioned, font doesn't seem to matter.)

skrytebane commented 3 years ago

I tried building Emacs 27.1.90 also now, same issue.

skrytebane commented 3 years ago

(But Emacs from the master branch as of commit ac102bb966f7944babbd8594684550905eecca0a works fine. I guess maybe it's git bisect-time. :grin: )

mickeynp commented 3 years ago

Hm. It will also affect the upcoming Emacs 27 minor release? That's a shame. I figured it would've been cherry picked into the branch.

There's a particular commit that fixes it, I think, but I have not actually verified this: fe903c5ab7354b97f80ecf1b01ca3ff1027be446.

skrytebane commented 3 years ago

I had a look at emacs-27.1.91 now. It also doesn't seem to include that commit.

(I tried building it, also. Same problem.)

mickeynp commented 3 years ago

Do you mind M-x report-emacs-bug? I believe that is probably a genuine oversight on their part not to cherry pick it into that branch.

skrytebane commented 3 years ago

Yeah, I've sent a bug report. (Also verified that the commit you mentioned fixes the issue when applied to the emacs-27 branch.)

skrytebane commented 3 years ago

https://debbugs.gnu.org/cgi/bugreport.cgi?bug=46217

(Rejected.)

mickeynp commented 3 years ago

@skrytebane, thanks for raising it. Shame it was too late to get it merged in.

HenningTimm commented 3 years ago

I think I can confirm this (or a variant of this bug) also for emacs 27.2 (Kubuntu 20.04 snap install). In my case elpy, php-mode, and c-mode are affected (rustic/ rust-mode and the basic python mode are not). When opening such a file (or activating the affected modes directly), emacs hangs and cannot be closed (doesn't react to C-g or Esc, but multiple clicks on the close button work). On my machine I also see a constant flickering and a half rendered scroll bar in the middle of the frame.

I am not sure if this is the same error or just something similar. If it is, then this fix is not contained in 27.2, and I guess my options are compiling using the newest version or waiting for emacs-28, right?

skrytebane commented 3 years ago

@HenningTimm I don't think this change will be in a 27.x release, so you need to build Emacs from master to get it. Or you can build the 27.x branch with fe903c5ab7354b97f80ecf1b01ca3ff1027be446 cherry-picked onto it. I seem to recall that I tried it and it seemed to work. See the bug thread I linked to above.

(By the way, I'm running Emacs compiled from master now, and it seems to mostly work fine, even with native compilation enabled.)

EDIT: I should clarify that I'm not using ligature.el at the moment, so I don't actually know how that works now. (Because I have some hosts with only Emacs 26 or 27, and didn't want to bother with version-specific configurations.)

Oh, and what you describe seems like the same error I saw, yes.

HenningTimm commented 3 years ago

Thank you @skrytebane as far as I can see this works!

For others who want to follow along: Assuming all prerequisites to compile EMACS are present, I did roughly the following:

# clone emacs repo 
git clone https://git.savannah.gnu.org/git/emacs.git
cd emacs

# check out emacs-27 branch
git checkout emacs-27

# create a new branch based on this one for the cherry-picked commit
# this hopefully avoids conflicts when updating to newer versions
# you can easily skip this step
git checkout -b emacs-27-ligature

# Apply the fix for ligature.el
git cherry-pick -x fe903c5ab7354b97f80ecf1b01ca3ff1027be446

# build EMACS
./configure
make

# Verify it works
./src/emacs foo.py

Et voila (an example with python/ elpy since it was affected by the same bug. I verified that it also works for c-mode): ligature

If have not done any long term testing yet, but if anythings crops up I will post an update.

kmbgit commented 3 years ago

@HenningTimm's instructions weren't quite right - there's no "configure" file in the repository so you need autoconf and then run "make" in the top-level directory to create it. See the INSTALL.REPO file for further details.