all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Some thoughts about more-smarter-operator
@ 2012-11-12 10:31 Adam Jiang
  0 siblings, 0 replies; only message in thread
From: Adam Jiang @ 2012-11-12 10:31 UTC (permalink / raw)
  To: help-gnu-emacs

[-- 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 --]

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2012-11-12 10:31 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-11-12 10:31 Some thoughts about more-smarter-operator Adam Jiang

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.