Re: [O] electric-pair, autopair, smartparens, etc in org-mode

2018-10-26 Thread Tim Cross


Samuel Wales  writes:

> can either of you give examples of code or settings that you had that
> made behavior of new modes unpredictable because emacs started
> supporting the behavior you made the code or settings for?
>

It is difficult to remember now as it was some time ago that I cleaned
up my init and got rid of much of my old stuff. Areas I do remember
include

- Key bindings. This is probably the most common. You would enable a new
  Emacs feature only to find you had conflicts with key bindings. In the
  best case, some new features couldn't be easily accessed. In the worst
  case, a new feature would create unexpected behaviour. The hard part
  was often in deciding whether to try and change the bindings or change
  my finger memory.

- Hooks. This was probably the second most common problem. A new feature
  would add to a hook where I had a similar feature also on that
  hook. As a result, both would run and result in unexpected outcomes.

- Convenience functions for selecting files, buffers and windows,
  working with sets of files (i.e. projects), My setup predated ido, and
  packages like yasnippets, projectile and company mode which I now use. In many
  cases, my own tweaks were OK, but not as robust or feature rich as
  standard packages that were added to Emacs over releases which
  provided similar functionality.

- As my init had grown in a rather 'organic' manner - bits added as I
  needed them, there was a lack of consistency or structure to my
  configuration. As a result, often when I tried a new feature, there
  would be parts of my init I would forget to remove/disable that would
  conflict with that feature. As I used autoloads quite a bit, things
  would also be a little inconsistent as conflicts could be dependent on
  the order things got loaded and that order could be affected by what I
  did in a specific session.

- One area I do remember was with respect to handling of PDF, HTML and
  other document types. I had a lot of config which would automatically
  convert many of these types to plain text to make them easy to work
  with inside emacs. As modes like doc-view, eww etc were added. I
  recall at times, conflicts would occur. I remember at one point, what
  behaviour I would experience when opening a PDF would depend on what
  mode had been loaded. If doc-view was already loaded, I would see the
  PDF rendered using doc-view - if my code was already loaded, I would
  see a plain text version. Often, the result would not be the one I
  wanted. I now no longer have all that code in my init and leave such
  things to Emacs.

In my case, much of my elisp config was pretty rough - I did as little
as necessary to get the behaviour I wanted. It was often poorly tested,
lacked sufficient error checking, was inconsistent and overall rough -
it did the job. However, this did mean it often did not play well with
others. For ages, I simply didn't bother looking at new features and
modes unless I came across a new requirement e.g. learning a new
programming language, working with a new system etc. My init also had
large amounts of code borrowed with pride (aka stolen) from newsgroup
postings, web sites, mail lists and various elisp repositories. As I
tend not to bother compiling my init, you would not necessary be aware
of obsolete and deprecated functions used by this code. The lack of any
namespace for packages also meant name conflicts were sometimes the
cause of weird bugs etc. Overall, things were 'fragile' and you would
avoid making changes as much as possible.  

I was frequently surprised when I decided it was time to cleanup my init at
various improvements and enhancements that had been added to Emacs. This
is partially a result of the conservative approach Emacs tends to adopt
- a good approach as it means you can usually upgrade to a new version
and not end up spending hours fixing things just to get back to
work. However, the downside is that it also means you may not even be
aware of or benefit from some improvements.

The positive is that now I have a nicely structured and documented org
file with my init and making changes is easy. Actually, I have multiple
configs - a standard working config, a 'new features' config where I try
out new packages etc, a very simple minimal config I use for
testing/debugging problems etc. I have a simple shell script which I can
run and pass it an org file name which will generate a new init.el and I
keep it all in git. At this time, I'm probably happier with my Emacs
setup than during any period in the last 25 years. 

Tim



Tim Cross



Re: [O] electric-pair, autopair, smartparens, etc in org-mode

2018-10-26 Thread Eric S Fraga
On Thursday, 25 Oct 2018 at 15:57, Samuel Wales wrote:
> can either of you give examples of code or settings that you had that
> made behavior of new modes unpredictable because emacs started
> supporting the behavior you made the code or settings for?

In my case, mostly incompatible bindings of keys, e.g. the tab key, especially 
in the context of auto-completion mechanisms and auto-expansion (e.g. 
yasnippet).  It's not so much unpredictable behaviour as wrong behaviour due to 
settings stepping on the toes of subsequently installed packages.

-- 
Eric S Fraga via Emacs 27.0.50, Org release_9.1.11-620-ga548e4



Re: [O] electric-pair, autopair, smartparens, etc in org-mode

2018-10-25 Thread Samuel Wales
oh i got that slightly wrong.  i meant can you give exmaples of what
yoa re saying.



Re: [O] electric-pair, autopair, smartparens, etc in org-mode

2018-10-25 Thread Samuel Wales
can either of you give examples of code or settings that you had that
made behavior of new modes unpredictable because emacs started
supporting the behavior you made the code or settings for?


On 10/25/18, Eric S Fraga  wrote:
> On Thursday, 25 Oct 2018 at 08:24, Tim Cross wrote:
>> Likewise, started with Emacs 19 and I still have some code which I added
>> back then in my init!
>
> [...]
>
>> The two big benefits from the clean up have been much faster start up
>> (something which never really bothered me as I run emacs for weeks
>> without re-starting anyway) and far more predictable behaviour when I
>> try out or add a new mode (I often found my custom tweaks would not
>> always work well with new modes etc).
>
> The second of these is indeed a benefit of cleaning up initialization
> files.  I have been doing so, in any case, just at a slower pace than I
> should.  I actually have been doing exactly what you suggest: using org
> and tangling.
> --
> Eric S Fraga via Emacs 27.0.50, Org release_9.1.13-894-gf79545
>
>


-- 
The Kafka Pandemic: 

The disease DOES progress. MANY people have died from it. And ANYBODY
can get it at any time.

"You’ve really gotta quit this and get moving, because this is murder
by neglect." ---
.



Re: [O] electric-pair, autopair, smartparens, etc in org-mode

2018-10-25 Thread Eric S Fraga
On Thursday, 25 Oct 2018 at 08:24, Tim Cross wrote:
> Likewise, started with Emacs 19 and I still have some code which I added
> back then in my init!

[...]

> The two big benefits from the clean up have been much faster start up
> (something which never really bothered me as I run emacs for weeks
> without re-starting anyway) and far more predictable behaviour when I
> try out or add a new mode (I often found my custom tweaks would not
> always work well with new modes etc).

The second of these is indeed a benefit of cleaning up initialization
files.  I have been doing so, in any case, just at a slower pace than I
should.  I actually have been doing exactly what you suggest: using org
and tangling.
-- 
Eric S Fraga via Emacs 27.0.50, Org release_9.1.13-894-gf79545



Re: [O] electric-pair, autopair, smartparens, etc in org-mode

2018-10-24 Thread Tim Cross


Eric S Fraga  writes:

> On Wednesday, 24 Oct 2018 at 12:38, Roland Everaert wrote:
>> Pleased to see it was helpful. The funny thing is that I use that config
>> for, maybe, 10 years and never think about changing it.
>
> I've been using emacs for well over 30 years now.  You would not believe the 
> crud that has built up in my config files... ;-) :Q
>
> Mind you, with org, I have started rationalizing the config files but it's a 
> time consuming task and the adage of "if it ain't broke, don't fix it" has 
> power...

+1

Likewise, started with Emacs 19 and I still have some code which I added
back then in my init!

I went through the pain of cleaning up my init file some time ago when I
moved to make better use of 'use-package'. Have to say that while things
were not 'broken' before my cleanup, they are certainly working better
now and my init is much smaller.

What I found was that a lot of what was in my init file was simply no
longer required as similar (often superior) functionality has crept into
the main Emacs distribution - all I needed to do was remove my code and
turn the feature on.

The two big benefits from the clean up have been much faster start up
(something which never really bothered me as I run emacs for weeks
without re-starting anyway) and far more predictable behaviour when I
try out or add a new mode (I often found my custom tweaks would not
always work well with new modes etc).

Org is extremely useful in this process. Create an org file and put all
your existing init in there as source blocks so that you can reproduce
your setup using tangle. Then create a new-init.org file and just add
the stuff you must have i.e. email config, essential modes etc. Then you
can switch between old and new setups using tangle to generate new
init.el file. When you have time, start with the new-init version and
start adding/tweaking to get the behaviour you want. Rather than just
copy across your old setup, check to see what is available in core - if
your like me, you will find lots of we use to tweak in code is now part
of core emacs and all you need to do is turn it on. At some point, you
will find you stay in your new init file and no longer need to revert to
the old version. You will likely find lots of stuff never gets
migrated. 

It really is worth the time and effort.

Tim

-- 
Tim Cross



Re: [O] electric-pair, autopair, smartparens, etc in org-mode

2018-10-24 Thread Eric S Fraga
On Wednesday, 24 Oct 2018 at 09:12, Matt Price wrote:
> Eric, you seem to be replying to an email that I sometimes don't have -- I
> would love to see what @stardiviner wrote, do you stil lhave the email?

I've forwarded that email to you but it's strange that you missed it as
it was sent to the org mode mailing list.

-- 
Eric S Fraga via Emacs 27.0.50, Org release_9.1.13-783-g97fac4



Re: [O] electric-pair, autopair, smartparens, etc in org-mode

2018-10-24 Thread Matt Price
Eric, you seem to be replying to an email that I sometimes don't have -- I
would love to see what @stardiviner wrote, do you stil lhave the email?

On Tue, Oct 23, 2018 at 9:12 AM Eric S Fraga  wrote:

> On Tuesday, 23 Oct 2018 at 19:48, stardiviner wrote:
> > This is really helpful for me, I use smartparens before, but it is a
> > little heavy. So I disabled it. I found your solution is simple and
> > fast. I modified a little:
>
> +1
>
> I gave up long ago on smartparens but skeleton seems to work well.
>
> --
> Eric S Fraga via Emacs 27.0.50, Org release_9.1.13-783-g97fac4
>
>


Re: [O] electric-pair, autopair, smartparens, etc in org-mode

2018-10-24 Thread Eric S Fraga
On Wednesday, 24 Oct 2018 at 12:38, Roland Everaert wrote:
> Pleased to see it was helpful. The funny thing is that I use that config
> for, maybe, 10 years and never think about changing it.

I've been using emacs for well over 30 years now.  You would not believe the 
crud that has built up in my config files... ;-) :Q

Mind you, with org, I have started rationalizing the config files but it's a 
time consuming task and the adage of "if it ain't broke, don't fix it" has 
power...

-- 
Eric S Fraga via Emacs 27.0.50, Org release_9.1.13-783-g97fac4



Re: [O] electric-pair, autopair, smartparens, etc in org-mode

2018-10-24 Thread Roland Everaert


I will borrow your config for the emphasis symbols, but for all the
paren-related symbols, I will keep the global mapping, so it will still
work when writing codes and the like ;)

Pleased to see it was helpful. The funny thing is that I use that config
for, maybe, 10 years and never think about changing it.

stardiviner writes:

> Roland Everaert  writes:
>
>> Hi,
>>
>> I use the following configuration:
>>
>>  parenthèses, accolades et brackets ;;
>> (setq skeleton-pair t)
>> (global-set-key "[" 'skeleton-pair-insert-maybe)
>> (global-set-key "{" 'skeleton-pair-insert-maybe)
>> (global-set-key "(" 'skeleton-pair-insert-maybe)
>> (global-set-key "\"" 'skeleton-pair-insert-maybe)
>> (global-set-key "'" 'skeleton-pair-insert-maybe)
>>
>> This will only close the defined characters.
>>
>>
>> Hope this will help.
>>
>> Roland.
>>
>
> This is really helpful for me, I use smartparens before, but it is a little 
> heavy. So I disabled it. I found your solution is simple and fast. I modified 
> a little:
>
> #+begin_src emacs-lisp
> (require 'skeleton)
> (setq skeleton-pair t)
>
> (define-key org-mode-map (kbd "~") 'skeleton-pair-insert-maybe)
> (define-key org-mode-map (kbd "=") 'skeleton-pair-insert-maybe)
> (define-key org-mode-map (kbd "*") 'skeleton-pair-insert-maybe)
> (define-key org-mode-map (kbd "+") 'skeleton-pair-insert-maybe)
>
> (define-key org-mode-map (kbd "[") 'skeleton-pair-insert-maybe)
> (define-key org-mode-map (kbd "{") 'skeleton-pair-insert-maybe)
> (define-key org-mode-map (kbd "(") 'skeleton-pair-insert-maybe)
> (define-key org-mode-map (kbd "\"") 'skeleton-pair-insert-maybe)
> (define-key org-mode-map (kbd "'") 'skeleton-pair-insert-maybe)
> #+end_src


-- 
Luke, use the FOSS

Sent from Emacs



Re: [O] electric-pair, autopair, smartparens, etc in org-mode

2018-10-23 Thread Eric S Fraga
On Tuesday, 23 Oct 2018 at 19:48, stardiviner wrote:
> This is really helpful for me, I use smartparens before, but it is a
> little heavy. So I disabled it. I found your solution is simple and
> fast. I modified a little:

+1

I gave up long ago on smartparens but skeleton seems to work well.

-- 
Eric S Fraga via Emacs 27.0.50, Org release_9.1.13-783-g97fac4



Re: [O] electric-pair, autopair, smartparens, etc in org-mode

2018-10-23 Thread stardiviner


Roland Everaert  writes:

> Hi,
>
> I use the following configuration:
>
>  parenthèses, accolades et brackets ;;
> (setq skeleton-pair t)
> (global-set-key "[" 'skeleton-pair-insert-maybe)
> (global-set-key "{" 'skeleton-pair-insert-maybe)
> (global-set-key "(" 'skeleton-pair-insert-maybe)
> (global-set-key "\"" 'skeleton-pair-insert-maybe)
> (global-set-key "'" 'skeleton-pair-insert-maybe)
>
> This will only close the defined characters.
>
>
> Hope this will help.
>
> Roland.
>

This is really helpful for me, I use smartparens before, but it is a little 
heavy. So I disabled it. I found your solution is simple and fast. I modified a 
little:

#+begin_src emacs-lisp
(require 'skeleton)
(setq skeleton-pair t)

(define-key org-mode-map (kbd "~") 'skeleton-pair-insert-maybe)
(define-key org-mode-map (kbd "=") 'skeleton-pair-insert-maybe)
(define-key org-mode-map (kbd "*") 'skeleton-pair-insert-maybe)
(define-key org-mode-map (kbd "+") 'skeleton-pair-insert-maybe)

(define-key org-mode-map (kbd "[") 'skeleton-pair-insert-maybe)
(define-key org-mode-map (kbd "{") 'skeleton-pair-insert-maybe)
(define-key org-mode-map (kbd "(") 'skeleton-pair-insert-maybe)
(define-key org-mode-map (kbd "\"") 'skeleton-pair-insert-maybe)
(define-key org-mode-map (kbd "'") 'skeleton-pair-insert-maybe)
#+end_src

-- 
[ stardiviner ]
   I try to make every word tell the meaning what I want to express.
   Blog: https://stardiviner.github.io/
   IRC(freenode): stardiviner
   GPG: F09F650D7D674819892591401B5DF1C95AE89AC3
  



Re: [O] electric-pair, autopair, smartparens, etc in org-mode

2018-10-23 Thread Roland Everaert
Hi,

I use the following configuration:

 parenthèses, accolades et brackets ;;
(setq skeleton-pair t)
(global-set-key "[" 'skeleton-pair-insert-maybe)
(global-set-key "{" 'skeleton-pair-insert-maybe)
(global-set-key "(" 'skeleton-pair-insert-maybe)
(global-set-key "\"" 'skeleton-pair-insert-maybe)
(global-set-key "'" 'skeleton-pair-insert-maybe)

This will only close the defined characters.


Hope this will help.

Roland.

Matt Price writes:

> wow, I learned a whole lot from your answer Nicholas, but still not quite
> enough to make this work for me.  After some puzzling over the syntax for
> character values, I believe that what I want should be something like this:
>
> (add-function :before-until electric-pair-inhibit-predicate
>   (lambda (c)
> (and (eq ?\[ c)
>  (eq major-mode 'org-mode)
>  (memq (char-before (1- (point))) '(?\[ ?\])
>
> The manual says to use advice-add instead of add-function for these cases,
> so this could be written like this instead:
>
> (defun mwp-org-mode-electric-inhibit (c)
>   (and
>(eq ?\[ c)
>(eq major-mode 'org-mode)
>(memq (char-before (1- (point))) '(?\[ ?\]) )))
>
> (advice-add electric-pair-inhibit-predicate :before-until
> #'mwp-org-mode-electric-inhibit)
>
> it seems to sort of work.  That is, the code is effective, but it doesn't
> do what I want, so I had to think about the desired behaviour, which is
> maybe too complex for this modification:
>
> when I start a link [
> go ahead and add pair to
> []
> when I add a second [, don't complete
> [[]
> this is what my code does!
>
> but what I really want is, when I finish adding a link reference, somehow
> allow me to stay inside the link to add the link text:
> [[https://google.com]] --> [[https://google.com][]]
> with point between the final [ and ].
> This seems like it needs a more complex intervention.
>
> For now I've just turned off pairing of brackets entirely:
>
> (defun mwp-org-mode-electric-inhibit (c)
>   (and
>(eq ?\[ c)
>(eq major-mode 'org-mode))
>
> This works fine, though I'd still like the other :-/
>
> Thanks Nicholas!
> On Sun, Oct 21, 2018 at 3:28 AM Nicolas Goaziou 
> wrote:
>
>> Hello,
>>
>> Matt Price  writes:
>>
>> > - electric-pair and autopair complete [[ immediately, and don't seem to
>> > allow me to skip past the closing brackets, so if I try to type [[
>> > https://link.to.somewhere][link text]] I end up with
>> > [[link.to.somewhere]][link-text] .
>>
>> I use C-c C-l to insert links with description. However, electric
>> pairing does get in the way when writing sub/superscript. I use the
>> following snippet to work around the issue:
>>
>>(add-function :before-until electric-pair-inhibit-predicate
>>  (lambda (c)
>>(and (eq ?\{ c)
>> (eq major-mode 'org-mode)
>> (memq (char-before (1- (point))) '(?_ ?^)
>>
>> I guess you could do something similar to disable pairing when entering
>> a bracket link.
>>
>> Regards,
>>
>> --
>> Nicolas Goaziou
>>


-- 
Luke, use the FOSS

Sent from Emacs



Re: [O] electric-pair, autopair, smartparens, etc in org-mode

2018-10-21 Thread Matt Price
wow, I learned a whole lot from your answer Nicholas, but still not quite
enough to make this work for me.  After some puzzling over the syntax for
character values, I believe that what I want should be something like this:

(add-function :before-until electric-pair-inhibit-predicate
  (lambda (c)
(and (eq ?\[ c)
 (eq major-mode 'org-mode)
 (memq (char-before (1- (point))) '(?\[ ?\])

The manual says to use advice-add instead of add-function for these cases,
so this could be written like this instead:

(defun mwp-org-mode-electric-inhibit (c)
  (and
   (eq ?\[ c)
   (eq major-mode 'org-mode)
   (memq (char-before (1- (point))) '(?\[ ?\]) )))

(advice-add electric-pair-inhibit-predicate :before-until
#'mwp-org-mode-electric-inhibit)

it seems to sort of work.  That is, the code is effective, but it doesn't
do what I want, so I had to think about the desired behaviour, which is
maybe too complex for this modification:

when I start a link [
go ahead and add pair to
[]
when I add a second [, don't complete
[[]
this is what my code does!

but what I really want is, when I finish adding a link reference, somehow
allow me to stay inside the link to add the link text:
[[https://google.com]] --> [[https://google.com][]]
with point between the final [ and ].
This seems like it needs a more complex intervention.

For now I've just turned off pairing of brackets entirely:

(defun mwp-org-mode-electric-inhibit (c)
  (and
   (eq ?\[ c)
   (eq major-mode 'org-mode))

This works fine, though I'd still like the other :-/

Thanks Nicholas!
On Sun, Oct 21, 2018 at 3:28 AM Nicolas Goaziou 
wrote:

> Hello,
>
> Matt Price  writes:
>
> > - electric-pair and autopair complete [[ immediately, and don't seem to
> > allow me to skip past the closing brackets, so if I try to type [[
> > https://link.to.somewhere][link text]] I end up with
> > [[link.to.somewhere]][link-text] .
>
> I use C-c C-l to insert links with description. However, electric
> pairing does get in the way when writing sub/superscript. I use the
> following snippet to work around the issue:
>
>(add-function :before-until electric-pair-inhibit-predicate
>  (lambda (c)
>(and (eq ?\{ c)
> (eq major-mode 'org-mode)
> (memq (char-before (1- (point))) '(?_ ?^)
>
> I guess you could do something similar to disable pairing when entering
> a bracket link.
>
> Regards,
>
> --
> Nicolas Goaziou
>


Re: [O] electric-pair, autopair, smartparens, etc in org-mode

2018-10-21 Thread Nicolas Goaziou
Hello,

Matt Price  writes:

> - electric-pair and autopair complete [[ immediately, and don't seem to
> allow me to skip past the closing brackets, so if I try to type [[
> https://link.to.somewhere][link text]] I end up with
> [[link.to.somewhere]][link-text] .

I use C-c C-l to insert links with description. However, electric
pairing does get in the way when writing sub/superscript. I use the
following snippet to work around the issue:

   (add-function :before-until electric-pair-inhibit-predicate
 (lambda (c)
   (and (eq ?\{ c)
(eq major-mode 'org-mode)
(memq (char-before (1- (point))) '(?_ ?^)

I guess you could do something similar to disable pairing when entering
a bracket link.

Regards,

-- 
Nicolas Goaziou