all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Carlos Pita <carlosjosepita@gmail.com>
To: 19761@debbugs.gnu.org
Cc: galli.87@gmail.com
Subject: bug#19761: python.el: improved hideshow mode support
Date: Tue, 3 Feb 2015 19:21:53 -0300	[thread overview]
Message-ID: <CAELgYhcthgAYX+wJPUpG46bpdLiHqvzH8s0D24TUnKYRgcDLQQ@mail.gmail.com> (raw)

X-Debbugs-CC: galli.87@gmail.com
Tags: patch

I've found two issues with the current hs configuration:

1) The hs-block-start-regexp wants to anchor at the beginning of line.
At least, this doesn't behave well with hs-hide-level-recursive. Try
C-c @ C-l on the line after the class statement below. The problem is
that the point is not always at the beginning of line when the regexp
is evaluated by hs.

2) The hs-forward-sexp-func is python-nav-end-of-defun. This is fine
as far as the function is separated by a blank line from the code that
follows it. Otherwise the closed fold is joined with the line
immediately following it. Try C-c @ C-h on the nested def below. This
is easily fixed going one char back when the point is not left in an
empty line after python-nav-end-of-defun.

So after the changes the new hs configuration is:

  (add-to-list 'hs-special-modes-alist
               `(python-mode "\\s-*\\(?:def\\|class\\)\\>" nil "#"
                             ,(lambda (_arg)
                                (python-nav-end-of-defun)
                                (unless (python-info-current-line-empty-p)
                                  (backward-char)))
                             nil))

Here is the (real life) example mentioned above:

class PivotReader:

    def __init__(self, file, num_cols):
        self._pr_file = open(file) if type(file) is str else file
        self._pr_reader = csv.reader(self._pr_file)
        header = next(self._pr_reader)
        self._pr_cols = {col: i for i, col in enumerate(header)}
        self._pr_nums = [col in num_cols for col in header]
        self._pr_vals = None

    def next_row(self):
        try:
            self._pr_vals = next(self._pr_reader)
            return True
        except:
            return False

    def __enter__(self):
        return self

    def __exit__(self, type, value, tb):
        self._pr_file.close()

    def __getattr__(self, col):
        return self[col]

    def __getitem__(self, cols):
        def get(col):
            idx = self._pr_cols[col]
            val = self._pr_vals[idx]
            num = self._pr_nums[idx]
            return float(val) if num else val
        if type(cols) is str:
            return get(cols)
        else:
            return tuple(map(get, cols))





             reply	other threads:[~2015-02-03 22:21 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-03 22:21 Carlos Pita [this message]
2015-02-07 19:48 ` bug#19761: python.el: improved hideshow mode support Fabián Ezequiel Gallina

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=CAELgYhcthgAYX+wJPUpG46bpdLiHqvzH8s0D24TUnKYRgcDLQQ@mail.gmail.com \
    --to=carlosjosepita@gmail.com \
    --cc=19761@debbugs.gnu.org \
    --cc=galli.87@gmail.com \
    /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.