emacs-pretest-bug
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: python.el update


From: Stefan Monnier
Subject: Re: python.el update
Date: 10 May 2004 11:20:04 -0400
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3.50

>> -- I see you added a python-comment-indent that aligns the comment to the
>> one on the previous line.  It looks a bit simplistic: it never uses
>> comment-column and it will align strangely as follows:
>> 
>> foo # some comment
>> 
>>     # here is a new strangely aligned comment.

> In what circumstances?

Take a file containing:

    foo # some comment

      # here is blabla

then go to the second comment and hit M-;

> newcomment again, I'm not clear what the hook function is supposed to do

Just return a comment-column to use for the comment at point.
Of course, as you know this is a simplistic description because it doesn't
say whether it should take into account what is possible, ...
What really happens is that it should just basically define what the mode's
coding style prefers, and comment-indent will then interpret the result in
a "meaningful" way.

> and in quite what circumstances it gets called.  Perhaps the doc
> for it could be made more explicit?

I think making it explicit will make it unwieldy.  The details are
just ugly.
The docstring would just mirror the code, so if you want to know more,
you're better off looking at the code (and if you think the code is
unreadable, then I'd say the docstring I'd write would be just as
unreadable.  Maybe someone else can do better :-( ).

>> Furthermore, the default code should already DTRT since it delegates the
>> work to indent-according-to-mode.  So could you explain why you need
>> a specific function?  Maybe we can fix the generic code instead.

> To avoid ending up with something like this on C-M-j:

> def ...
>     ...

> # ...
>     # ...

In what circumstance would that happen?

> Auto-indentation simply can't always DTRT with the offside rule (not
> that Python's layout is proper offside, like Haskell).

Can't it do the same thing as python-comment-indent does?

>> -- python-comment-line-p seems wrong: it returns nil on a blank line
>> contrary to what the doc says.
> The doc's wrong.

Thanks, fixed.

>> -- What's the point of
>> (define-key inferior-python-mode-map "\C-c\C-z" 'python-switch-to-python)
> I guess it's a cut/paste-o, ta.

Thanks.  Removed.

>> -- Any hope to see the emacs.py file included in the python distribution?
> No, but you wouldn't want it to be.  It's specific to the Emacs mode.

OK.  I thought it could be more generally useful (kind of like the
--fullname and --annotate=3 options of gdb).

> There isn't actually anything wrong with including files with bits of
> other languages like that, is there?

No, indeed (well, I guess in some odd cases it could be a problem if the
language indirectly imposes a particular non-GPL-compatible license, but
that's nitpicking).  I just tought it was a bit unclean to fiddle with
PYTHONPATH.  Maybe python should additionally use a PYTHONPRELOAD var
containing a (colon-separated) list of files to load at startup.

>> -- I've replaced
>> 
>> (with-output-to-temp-buffer "*Help*"
>> with
>> (help-setup-xref (list 'python-describe-symbol symbol))
>> (with-output-to-temp-buffer (help-buffer)
>> 
>> so that a [back] button could work 

> That's not relevant currently since you can't link into or out of it,
> so I disabled it to avoid a broken [back].

I don't really understand what you disabled.
I agree it's not currently relevant (that why I said "[back] could work"),
but AFAIK my change didn't introduce a bug (other than the missing second
arg to help-setup-xref: (interactive-p)).  Are you saying otherwise?

>> -- Regarding your comment before python-complete-symbol saying we should
>> have something like that in the core, I agree and we basically already
>> have it: minibuffer-complete.
> I don't understand.  Could you be more explicit?
> I thought minibuffer-complete was basically an internal function.  I
> envisaged something that provided the boilerplate and took a function
> to select the partial symbol and one to produce a completions list
> from it.  I guess if minibuffer-complete can use local variables
> pointing to functions to do that, it's fine, but `local' in that case
> means the minibuffer, doesn't it?

E.g. python-complete-symbol could be rewritten as something like:

(defun python-complete-symbol (...)
  ...
  (let* ((symstart (python-symbol-start))
         (symbol (buffer-substring symstart (point)))
         (minibuffer-completion-table (python-symbol-completions symbol))
         (ol (make-overlay symstart (point) nil nil t)))
    (overlay-put ol 'field 'completion)
    (call-interactively 'minibuffer-complete)))

see my latex-complete example below.  Admittedly the above could be
abstracted into a generic complete-symbol function which might use
the syntax-table to find the symbol's boundaries and then modes would
set a buffer-local complete-symbol-function to get a completion table.
I guess this last step is what you were getting at.


        Stefan
        

(defun latex-complete ()
  "Complete thing at point."
  (interactive)
  (let ((pt (point)))
    (skip-chars-backward "^ {}\n\t\\\\")
    (case (char-before)
      ((nil ?\  ?\n ?\t ?\})
       (goto-char pt)
       (call-interactively 'indent-for-tab-command))
      (?\\
       ;; TODO: Complete commands.
       (goto-char pt)
       (call-interactively 'indent-for-tab-command))
      (?\{
       (let* ((cmd
               (save-excursion
                 (forward-char -1)
                 (skip-chars-backward " \n")
                 (buffer-substring (point)
                                   (progn
                                     (skip-chars-backward "address@hidden")
                                     (let ((n (skip-chars-backward "\\\\")))
                                       (forward-char (* 2 (/ n 2))))
                                     (point)))))
              (start (point))
              (_ (progn (goto-char pt) (skip-chars-backward "^," start)))
              (ol (make-overlay (point) pt nil nil t))
              (key (buffer-substring (point) pt))
              (f nil)
              (minibuffer-completion-table
               (funcall
                (dolist (comp latex-completion-alist (or f (lambda (key) t)))
                  (if (string-match (car comp) cmd)
                      (setq f (cdr comp))))
                (regexp-quote key))))
         (goto-char pt)
         (unwind-protect
             (progn
               (overlay-put ol 'field 'completion)
               (if (eq minibuffer-completion-table t)
                   ;; Unknown command.
                   (call-interactively 'indent-for-tab-command)
                 (let ((completion-ignore-case case-fold-search))
                   (call-interactively 'minibuffer-complete))))
           (delete-overlay ol)))))))




reply via email to

[Prev in Thread] Current Thread [Next in Thread]