Comments (18)
I really prefer the old behavior because it is consistent with REPL. If you hit TAB after a LaTeX symbol, it replaces it, and if you hit TAB at the beginning of the line, it increase indentation. It is much easier (at least in my setup) to format docstrings.
from julia-emacs.
Just to repeat for everyone looking at this issue: #196 works so you can use it, I just did not merge it because I haven't had time to finish it properly (tests etc).
from julia-emacs.
@ronisbr: We can bring it back, and with the hash table lookup it should be easy, but let's focus on the details first.
In the examples below, |
is the point.
\prefix|noise
matches multiple ones, eg\prefix1
,\prefix2
, etc. Herenoise
is irrelevant. What should it do, pick the first one, offer a list with a popup, or something else?\pre|fixnoise
matches\pre
and\prefix
, what should it expand to?
Note that the REPL behavior is the following on 1.9:
- on
\al|eph
, it refuses to replace, just throws up\alpha
,\allequal
, and\aleph
. - on
\al|noise
, same thing. \not|
will just expand greedily, and not offer\notin
.\not|in
will expand to̸in
, again greedily.
I think that the REPL is made for interactively entering text and expanding on whatever comes before the point. It is very rare (I think) to go back in the REPL prompt and expand text. Whereas in an editor there is text before and after the point.
I kind of missed the REPL behavior for a while, so I understand the issue, but in the end I arrived at the conclusion that editors need different semantics. I am very happy with the current setup now, as we get expansion within the symbol a way to resolve multiple options.
That said, I am open to a mechanism that mimics the REPL in some way. Just please spend some time thinking about the semantics.
from julia-emacs.
Perfect @tpapp !
Maybe we should not really replicate the entire REPL behavior. Is there any technical problem to always call auto-completion if a symbol does not resolve to a single solution? So, in all those cases, it would open that popup if I hit TAB?
What I really miss is the ability to use TAB to increase indentation if we does not have a LaTeX symbol. For example, if I hit TAB here:
A = [1| 2
I would like to go to here:
A = [1 | 2
instead of indenting the current line.
from julia-emacs.
(copied from a comment on #185)
Hello!
I have set up my Emacs to upgrade my (m)elpa packages automatically on a weekly basis. Thus, it came as a surprise to me that tab completion substitution for LaTeX symbols in julia-mode broke some time earlier this week. Then it took me a while to investigate the issue and track the root cause down to #185.
Granted, I have ivy-mode installed, and I noticed the comments in the source code related to abo-abo/swiper#2345. But that seems like an old issue, yet julia-mode worked perfectly until recently. Furthermore, there is nothing wrong with the substitution of LaTeX symbols which are unambiguous, e.g., \circeq
, only those which have multiple possible suffixes, e.g., \circ
and \in
.
Moreover, when I type \circ<TAB>
99.99% of the time I want it to be substituted with the circle symbol, and not to be completed to some hardly ever used LaTeX symbol name that also happens to begin with \circ
. The same goes for \in
.
I spent the better part of an hour trying to figure out how to patch the change to bring the old behavior back, to no avail. I finally gave up and went back to the January 19 version of julia-mode which I restored from a snapshot.
Note that I don't really want to start using abbrev. As I switch back-and-forth between Emacs and REPL, I definitely want to use the same key to expand symbols, otherwise I'm sure to mess it up regularly.
I think this will be an issue for others as well, so I'd like to offer my help to come up with a solution that suits (almost) everybody.
from julia-emacs.
@dhanak: please read the discussion above. TL;DR: the key question is defining the semantics, after that we can implement it.
from julia-emacs.
I think I would prefer simple prefix completion, offering choices if there are several. In the case of your examples:
- offer a list;
- expand to \pre and substitute.
I don't think I have ever pressed tab in the middle of a word and expected the editor to take the suffix into account as well. When I do press tab in the middle of a word, it happens because it is not really a word, I just went back and started to enter something before what was already there. So I'd prefer the editor to leave that part as is. With a somewhat forced example:
- input:
eq|
->|eq
->not \circ|eq
,<TAB>
,<SPACE>
- I expect:
not ∘ eq
- I wouldn't like to see:
not ≗
(As for the indentation, I have no issues with it.)
from julia-emacs.
Sounds like we actually have two separate desires here:
- Allow tab-completion of LaTeX symbols while preserving indentation behavior of
(setq tab-always-indent nil)
- Greedily substitute on exact prefix match: Don't prompt when completing
\circ
to offer choice of\circeq
; just directly complete to∘
.
- As noted above, this should not apply to middle-of-symbol completion, and perhaps middle-of-symbol completion should be entirely disabled when in this mode.
Path forward I see is to have a julia-indent-for-tab-command
function and a customization variable for each of the points above. julia-indent-for-tab-command
would just check the values of each of the customization variables, set tab-always-indent
and completion-at-point-functions
to appropriate values, and then explicitly call some combination of expand-abbrev
, indent-for-tab-command
, and completion-at-point
depending on values of customization.
from julia-emacs.
What we could do the following:
On \pre|post
- if
pre
matches a substitution exactly, replace, - if not, flash choices in the Messages buffer, or popup, or say that there is absolutely no match
Otherwise, if there is no \
in the line before the point, try indenting.
@dhanak, @ronisbr, would this match your use case?
from julia-emacs.
Hi @tpapp !
If you mean that try indenting is calling (indent-for-tab-command arg)
, then yes, it will match!
from julia-emacs.
Yes, that sounds good to me.
from julia-emacs.
I am working on a solution in #193. Please test, suggestions welcome (including code improvements, UI suggestions, etc).
from julia-emacs.
Do I understand correctly that at the moment there's no way to get \alph
to be automatically completed to \alpha
and then replaced with α
? I'm asking with or without pressing TAB (which would be taken care of by #196), I don't see any interactive function which can do this operation of completion+substitution at all.
from julia-emacs.
Hi @giordano. Sorry I missed your question until now. Invoking completion-at-point
(C-M-i
in vanilla emacs) in a julia-mode buffer will complete "\alph" directly to "α." I just tested this out using emacs -Q
and installing only julia-mode
and confirmed this works for me as expected. Are you seeing a situation where this doesn't work?
from julia-emacs.
Invoking
completion-at-point
(C-M-i
in vanilla emacs), in a julia-mode buffer will complete "\alph" directly to "α." I just tested this out usingemacs -Q
and installing onlyjulia-mode
and confirmed this works for me as expected. Are you seeing a situation where this doesn't work?
Yes, "\alph" for me is completed to "\alpha", not "α", further pressing M-C-i
does nothing. Not sure it's relevant, but I use Helm. I also have auto-complete installed, but doesn't seem the mode is active in my julia buffer.
from julia-emacs.
I've managed to replicate. Will create a new issue.
from julia-emacs.
Eventually, I upgraded to Emacs 29, and julia-ts-mode
with tree-sitter. Since that uses a different indentation API, this workaround didn't work for me any more, so I gave in and started to use dabbrev to auto-expand escape sequences. My main concern was that this is different from how the REPL works, and my muscle memory will surely mess it up regularly. So I tweaked the REPL instead, to work like dabbrev does. I added this code to my startup.jl
:
atreplinit() do repl
REPL = Base.REPL_MODULE_REF[]
LE = REPL.LineEdit
RC = REPL.REPLCompletions
# define a new keymap
my_keymap = Dict()
push!(repl.options.extra_keymap, my_keymap)
# auto-replace escaped latex and emoji sequences with their symbol
# counterparts after a punctuation key, just like Emacs abbrev-mode
function abbrev_expand(s, data, c)
buf = LE.buffer(s)
(pos, buf) = (position(buf), LE.content(buf))
(comp, r, _) = RC.bslash_completions(buf, thisind(buf, pos))[2]
if length(comp) == 1 && comp[].bslash[1] != '\\'
LE.edit_splice!(s, prevind(buf, r.start) => r.stop, comp[].bslash)
LE.refresh_line(s)
end
LE.edit_insert(s, c)
end
punct = filter(ispunct, Char(1):Char(127))
for c in [' '; setdiff(punct, ";?]>")]
my_keymap[c] = abbrev_expand
end
end
from julia-emacs.
Reopening because #196 doesn't allow you to use TAB
for both LaTeX substitution and inserting "real" TAB
s (see my comment on the PR). Feel free to close again if I'm misunderstanding (it happens rather frequently), and the PR does enable this.
from julia-emacs.
Related Issues (20)
- Support julia markdown mode
- font-lock-warning-face for @inbounds and @generated
- Warning in Emacs 29
- Type a sequence of subscript/superscript characters HOT 1
- julia-mode did not run properly in emacs-28.2 HOT 3
- Update breaks autocomplete in jupyter-emacs org mode code cells HOT 11
- Identation in fresh julia-mode installation HOT 1
- Identation in fresh julia-mode installation HOT 7
- Identation in fresh julia-mode installation HOT 1
- comment region with #= =# HOT 1
- Cannot open load file: No such file or directory, ess (exporting) HOT 3
- automatic insert end to close a function or type definition
- Test failure for julia--test-end-of-defun-nested-2 HOT 6
- Consecutive super/subscript completion HOT 1
- Macro invocations not highlighted if preceded by an exclamation mark
- julia-mode.el not indenting and throwing error HOT 5
- Unicode substitution broken with helm HOT 7
- Help finding a maintainer for julia-ts-mode HOT 9
- Error during redisplay: (jit-lock-function 1) signaled (error "prism: Infinite loop detected in ‘prism-match’. Please report this bug") HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from julia-emacs.