all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Adam Jiang <jiang.adam@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Some thoughts about more-smarter-operator
Date: Mon, 12 Nov 2012 19:31:40 +0900	[thread overview]
Message-ID: <CALK_+D37UoO09u1y3mXz47P0kuSFoXHf1iCWS7e4nk6ENVjueg@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 3291 bytes --]

Hi,

I think there are some natural requirements from programmers on the editor
to fill up proper whitespaces around operators like typing 'a+b' should be
printed to the buffer as 'a + b'. There is an extension called
smart-operator.el could do a part of these jobs. However, when I tried it
out with my emacs, it failed to me frequently in cc-mode. I have documented
these failure to

http://www.emacswiki.org/emacs/SmartOperator

I also tried to fix these problems. But, finally, my head got shocked when
I tried to mimic some code in autopair.el. It seems that smart-operator.el
is not smart enough because it doesn't use any syntax analysis result which
could be supported by emacs from the beginning. 'smart-operator.el' has to
be customized for each languages for its determinative facts are heavily
depends on regexs which is proceeding operators. The basic logics in
'smart-operator.el' look like

''''' pseudo code
if (in c-buffer)
   if (looking-back "PATTERN1")
       insert-whitespaces-as-wrapper OPERATOR
   else if (looking-back "PATTERN2")
       insert-whitespaces-only-behind OPERATOR
   else if (looking-back "PATTERN3")
       insert-whitespaces-only-front OPERATOR
   else
       insert-whitespaces-none OPERATOR

Actually, I think the conditions could not rely on PATTERNS but OPERATORS
for each major-mode. Then, we can simplify the code for insertion. Here is
the situation.

There is no way to figure out what is an operator with emacs' syntax-table.
(I am not sure about this, if there was, please let me know). However, an
operator is an element in the superset of one of the subsets of
'punctuator'. For example, with cc-mode, we have punctuators in syntax-table

'*', '%', '/', '+', '-', ...

then, operators could be listed in cc-mode would be

'*' - binary operator for multiplication
'*' - unary operator for get value in a point
'*' - delimiter for point declaration
'**' - a point to point
'****' - a point to point to point to point
'*=' - assignment after multiplication
etc.

If there was a way to describe what kind of strings could be an operator
for each major-mode, then, I can introduce some rules based on the
assertion to address the same problem that smart-operator wanted to solve,
like

- remap keybindings to 'puncuators' to a handler
- in the handler,

if ('puncuator' is in 'operator-list')
    if (concat last-N-charactors-before-current-position
value-of-curent-positon) is in 'operator-list')
       (back-to-previous position
        delete-whitespace
        call 'handler recursively)
    if 'operator' is unray
        insert whitespaces before ;;; like char *a;
    else if 'operator' is binary ;;; '?' ':' could be considered as binary
operators
        insert whitespaces wrapper ;;; like c = a * b;
else
    insert 'puncuator' ;;;

backspace, and RET(puncuator) should be solved specially as well.

There are some merits which the current smart-operator.el could not provide.

- solve the problem by more generic way
- easy to be customized; define a list of operators in regex to each
major-mode

I would like to do this, but, now, the biggest problem for me is that I am
not very familiar with elisp. SAD... is anyone interesting in implementing
the code in elisp? Do you have any comments on the analysis?

Best regards,
/Adam

[-- Attachment #2: Type: text/html, Size: 3826 bytes --]

                 reply	other threads:[~2012-11-12 10:31 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CALK_+D37UoO09u1y3mXz47P0kuSFoXHf1iCWS7e4nk6ENVjueg@mail.gmail.com \
    --to=jiang.adam@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.