Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

helm-get-org-candidates-in-file truncates headings at the wrong position #1294

Closed
tmalsburg opened this issue Dec 14, 2015 · 28 comments
Closed

Comments

@tmalsburg
Copy link
Member

window-width is used to determine the point for truncation but the function doesn't use the window width of the helm-window but that of the window in which helm was called.

@thierryvolpiatto
Copy link
Member

Thanks to look into this, I have not implemented this myself and BTW I
am not familiar with helm-org.el, anyway I will have a look ASAP,
possibly on thursday, otherwise at end of the week.

Thierry
https://emacs-helm.github.io/helm/

@tmalsburg
Copy link
Member Author

See also my comments on #964. Thank you, Thierry!

thierryvolpiatto pushed a commit that referenced this issue Dec 17, 2015
* helm-org.el (helm-get-org-candidates-in-file): Do it.
thierryvolpiatto pushed a commit that referenced this issue Dec 18, 2015
* helm-org.el (helm-get-org-candidates-in-file):
Don't use helm-window here, it doesn't already exists.
thierryvolpiatto pushed a commit that referenced this issue Dec 18, 2015
* helm-org.el (helm-org--get-candidates-in-file):
Renamed from helm-get-org-candidates-in-file, unquote lambda's.
thierryvolpiatto pushed a commit that referenced this issue Dec 18, 2015
* helm-org.el (helm-org--get-candidates-in-file):
Remove backquote forest.
thierryvolpiatto pushed a commit that referenced this issue Dec 18, 2015
* helm-easymenu.el: Do it.
* helm-org.el (helm-org-get-candidates): Use helm-flatten-list.
(helm-org--get-candidates-in-file): Minor changes.
thierryvolpiatto pushed a commit that referenced this issue Dec 18, 2015
* helm-org.el (helm-org--get-candidates-in-file):
Use apply instead of using a different lambda.
thierryvolpiatto pushed a commit that referenced this issue Dec 18, 2015
#1294).

* helm-org.el (helm-source-org-headings-for-files): Do it.
(helm-org--get-candidates-in-file): Fix long lines.
@thierryvolpiatto
Copy link
Member

Titus von der Malsburg [email protected] writes:

See also my comments on #964. Thank you Thierry!

I tried to improve all this, hope that fixed your problems.

Thanks.

Thierry
https://emacs-helm.github.io/helm/

TheBB added a commit to syl20bnr/spacemacs that referenced this issue Dec 18, 2015
thierryvolpiatto pushed a commit that referenced this issue Dec 18, 2015
* helm-org.el (helm-org--get-candidates-in-file): Do it.
@jagrg
Copy link
Contributor

jagrg commented Dec 18, 2015

With this recent update (helm-20151218.329), I'm no longer able to change min and max-depth on helm-source-org-headings-for-files. I used to be able to set for example (min-depth 2) (max-depth 2) and it would only display level 2 headlines.

@thierryvolpiatto
Copy link
Member

Jonathan Gregory [email protected] writes:

With this recent update (helm-20151218.329), I'm no longer able to
change min and max-depth on helm-source-org-headings-for-files. I used
to be able to set for example (min-depth 2) (max-depth 2) and it would
only display level 2 headlines.

Please clarify how you are using this, with a recipe if possible.

Thanks.

Thierry
https://emacs-helm.github.io/helm/

@jagrg
Copy link
Contributor

jagrg commented Dec 18, 2015

I was using it to search bibliographical notes. See: https://gist.github.com/jagrg/39d68432c783df50d199.

thierryvolpiatto pushed a commit that referenced this issue Dec 18, 2015
* helm-org.el (helm-source-org-headings-for-files): Implicit nil default for parents.
(helm-org-get-candidates): Same use a defun.
@thierryvolpiatto
Copy link
Member

Jonathan Gregory [email protected] writes:

I was using it to search bibliographical notes. See: https://gist.github.com/jagrg/39d68432c783df50d199.

Why are you using:

(cl-defun helm-bibtex-source-org-headings-for-files (filenames &optional
(min-depth 2) (max-depth 2))

instead of simply passing 2 (min-depth) and 2 (max-depth) to
helm-org-get-candidates ?

I can't try your code because I have no idea how to install helm-bibtex
and its dependencies and no sample file, however the min-depth and
max-depth arguments (1 and 8 by default) are passing correctly here (I
could modify them without problems)

Also be sure to recompile correctly all your files.

Thierry
https://emacs-helm.github.io/helm/

@tmalsburg
Copy link
Member Author

Matching is apparently still done on the truncated headlines. I used the following org mode file for testing:

* Arizona
* sdlkgj dslkjg sldkjg lskdjg lskdjg lksdjg lksdjg lksdjg lskdj glskdjg lskdjg lskdjg lskdjg lskdjg lskdjg lksdjg lskdjg lksdjg lksdjg lksdj glksjd glksjd glskdj glskdjg lskdjglksjdg lks Arizona

When I fire up helm-org-in-buffer-headings and search for "Arizona", I only get a match for the first headline. Tested with 7611133.

@tmalsburg
Copy link
Member Author

@jagrg your issue is probably independent from helm-bibtex. You could make Thierry's life easier by constructing a minimal reproducible example.

@thierryvolpiatto
Copy link
Member

Titus von der Malsburg [email protected] writes:

When I fire up helm-org-in-buffer-headings and search for "Arizona", I
only get a match for the first headline. Tested with 7611133.

Good, thanks for the recipe, will look also into this soon.

Thierry
https://emacs-helm.github.io/helm/

@jagrg
Copy link
Contributor

jagrg commented Dec 18, 2015

@thierryvolpiatto, here's a test file: https://gist.github.com/jagrg/6305b022557b80d7f012. You don't need helm-bibtex installed. This is what you need to do:

  1. (setq my-test-file "~/path/to/test.org")
  2. You can use any org file with level 2 headlines, but suppose you have something like:
#+TITLE: Helm test

* Methods

** Skinner, J. (2012) The interview: an ethnographic approach
Hello world.

** Burgess, R. (1991) In the field: an introduction to field research
The quick brown fox jumps over the lazy dog.
  1. Now do: M-x helm-test-show-notes

This is what I see:

Methods/Skinner, J. (2012) The interview: an ethnographic approach
Methods/Burgess, R. (1991) In the field: an introduction to field research

And this is what I used to see before the commits:

Skinner, J. (2012) The interview: an ethnographic approach
Burgess, R. (1991) In the field: an introduction to field research

thierryvolpiatto pushed a commit that referenced this issue Dec 18, 2015
* helm-org.el (helm-source-org-headings-for-files):
Add a match function.
(helm-org--get-candidates-in-file): Add a text property.
@thierryvolpiatto
Copy link
Member

Thanks for the recipe.

Jonathan Gregory [email protected] writes:

This is what I see:

Methods/Skinner, J. (2012) The interview: an ethnographic approach
Methods/Burgess, R. (1991) In the field: an introduction to field research

Yes this is what is expected.

And this is what I used to see before the commits:

Skinner, J. (2012) The interview: an ethnographic approach
Burgess, R. (1991) In the field: an introduction to field research

This is not related to last commits AFAICT, this was the behavior some months
ago, perhaps you haven't updated helm since a long time ?

Did you try to pass your arguments directly to helm-org-get-candidates ?

Thierry
https://emacs-helm.github.io/helm/

thierryvolpiatto pushed a commit that referenced this issue Dec 18, 2015
* helm-org.el (helm-source-org-headings-for-files):
Ensure candidate is propertized in match fn (paranoia).
@jagrg
Copy link
Contributor

jagrg commented Dec 18, 2015

This is the commit where the problem begins: d6c8b7c

I know this is the desired behaviour but I'm wanting to control exactly which level to display. In my case, that's level 2. I was hoping that changing min and max-depth would work (and it did before the commit above). I also tried to change helm-org-get-candidates as you suggested but it didn't work. Is this what you were thinking:

(cl-defun helm-org-get-candidates (filenames min-depth max-depth &optional (parents nil))
  (helm-flatten-list
   (mapcar (lambda (filename)
             (helm-org--get-candidates-in-file
              filename 2 2
              helm-org-headings-fontify
              (if parents t helm-org-headings--nofilename)
              parents))
           filenames)))

@thierryvolpiatto
Copy link
Member

Jonathan Gregory [email protected] writes:

This is the commit where the problem begins: d6c8b7c

I know this is the desired behaviour but I'm wanting to control
exactly which level to display. In my case, that's level 2.

So that's not what your recipe showed, anyway I am here able to change
in source code the value of min-depth and max-depth.

BTW your recipe is not usable, please give me a recipe I can use.

I was hoping that changing min and max-depth would work (and it did
before the commit above).

(cl-defun helm-source-org-headings-for-files
    (filenames
     &optional (min-depth 1) (max-depth 8) parents)

If I change here min-depth and max-depth it works as expected, arguments
are passed.

Be sure to use lexical-binding though.

I also tried to change helm-org-get-candidates as you suggested but it
didn't work. Is this what you were thinking:

No, I meant in your code.

Thierry
https://emacs-helm.github.io/helm/

@thierryvolpiatto
Copy link
Member

Here example with screenshots:

With actual code, I run helm-org-in-buffer-headings from the test.org buffer:

screenshot - 19122015 - 06 35 13

As you can see all headings are there.
Now I eval in source code helm-source-org-headings-for-files with its default arguments modified:

screenshot - 19122015 - 06 36 12

And now I come back to test.org and I run again helm-org-in-buffer-headings:

screenshot - 19122015 - 06 36 50

As you can see only heading with 2 level is shown.

@jagrg
Copy link
Contributor

jagrg commented Dec 19, 2015

Thanks for the explanation, however you are missing my point (and BTW sorry for not being clear enough). This is what your last screenshot shows:

test1/test2

And this is what I am trying to accomplish (after changing the depth, of course):

test2

If you change min and max-depth prior to d6c8b7c you should see that only level 2 is shown (without the parent headline).

In any case, considering the size of the monitor, this becomes especially problematic when using long headlines. Lower level headlines are sometimes unreadable. One solution (just food for thought) would be to use an outline structure instead, similar to org, which IMO is a lot cleaner. So that this:

My first parent headline
My first parent headline/My second level headline
My first parent headline/My second level headline/My third level headline
My first parent headline/My second level headline/My third level headline/My fourth level headline
My second parent headline
My second parent headline/My second level headline
My second parent headline/My second level headline/My third level headline
My second parent headline/My second level headline/My third level headline/My fourth level headline

becomes this:

My first parent headline
 My second level headline
  My third level headline
   My fourth level headline
My second parent headline
 My second level headline
  My third level headline
   My fourth level headline

@thierryvolpiatto
Copy link
Member

Jonathan Gregory [email protected] writes:

Thanks for the explanation, however you are missing my point (and BTW
sorry for not being clear enough).

Ok I understand now,
I will look on monday what makes the difference, hope this will be fixed
before the end of the year ;-)

This is what your last screenshot shows:

test1/test2

And this is what I am trying to accomplish (after changing the depth, of course):

test2

If you change min and max-depth prior to d6c8b7c you should see that
only level 2 is shown (without the parent headline).

Ok that's clear.

In any case, considering the size of the monitor, this becomes
especially problematic when using long headlines. Lower level
headlines are sometimes unreadable. One solution (just food for
through) would be to use an outline structure instead, similar to org,
which IMO is a lot cleaner. So that this:

PR's welcome, but IMO the best structure to read org files is org
itself.
Doing this is probably cleaner for parsing one file, but with many org
files (with a lot of headers), people generally want to see the path and
the differents levels.

Thierry
https://emacs-helm.github.io/helm/

@thierryvolpiatto
Copy link
Member

Jonathan Gregory [email protected] writes:

If you change min and max-depth prior to d6c8b7c you should see that
only level 2 is shown (without the parent headline).

I observe the same behavior after reverting all the changes I did
recently, i.e I still have "test1/test2".

Thierry
https://emacs-helm.github.io/helm/

@jagrg
Copy link
Contributor

jagrg commented Dec 20, 2015

That's strange. I was even able to reproduce it in emacs -Q. Did you restart emacs?

Try this:

  1. make sure you have the latest melpa version installed, which is helm-20151218.1216
  2. now open the helm-org library, delete its content and paste this code, which is the version previous to when the problem was introduced.
  3. change min and max-depth to 2 (on line 60 of helm-org.el) and save the file.
  4. recompile helm-20151218.1216 by typing M-x byte-recompile-directory.
  5. restart emacs
  6. open the test.org file and type M-x helm-org-in-buffer-headings

What do you see?

thierryvolpiatto pushed a commit that referenced this issue Dec 21, 2015
* helm-org.el (helm-source-org-headings-for-files): Use nreverse.
(helm-org-get-candidates): Use second arg of helm-flatten-list.
thierryvolpiatto pushed a commit that referenced this issue Dec 21, 2015
* helm-org.el (helm-org-get-candidates): Do it.
thierryvolpiatto pushed a commit that referenced this issue Dec 21, 2015
* helm-org.el (helm-org--get-candidates-in-file):
Apply the args when parents is nil and not the contrary.
@thierryvolpiatto
Copy link
Member

Jonathan Gregory [email protected] writes:

What do you see?

I finally was able to reproduce by stepping in all recents changes, it
appear I was doing exactly the contrary of what was done initially to
call org-get-outline-path.
Should be fixed now.
Thanks.

Thierry
https://emacs-helm.github.io/helm/

thierryvolpiatto pushed a commit that referenced this issue Dec 21, 2015
* helm-org.el (helm-source-org-capture-templates): Do it.
@jagrg
Copy link
Contributor

jagrg commented Dec 21, 2015

Thanks. It does work, but there's an issue with changing the depth back and forth, which I think could become a useful feature for cycling through headline levels. Anyhow, here's the problem. Add the following to your test.org file:

* test1
** test2
*** test3
**** test4
* testA
** testB
*** testC
**** testD
  1. restart emacs
  2. open test.org and type M-x helm-org-in-buffer-headings
  3. note that the full path is displayed as expected
  4. now open helm-org.el and change min and max-depth to 2
  5. save file, eval-buffer and recompile
  6. repeat step 2

This is what I see:

testA/test2
testA/testB

Now, apart from the path which I think shouldn't be there, testA is not a parent of test2.

@thierryvolpiatto
Copy link
Member

Jonathan Gregory [email protected] writes:

Now, apart from the path which I think shouldn't be there, testA is not a parent of test2.

Indeed, is that new of this bug was reproductible in previous versions ?

Thierry
https://emacs-helm.github.io/helm/

thierryvolpiatto pushed a commit that referenced this issue Dec 21, 2015
* helm-org.el (helm-org--get-candidates-in-file): Do it,
num-stars and level are the same thing.
@jagrg
Copy link
Contributor

jagrg commented Dec 21, 2015

I wasn't able to reproduce with e42e3ed, which I believe is the version prior to when the depth issue was addressed. As you can see, the paths are correct:

test1/test2
testA/testB

thierryvolpiatto pushed a commit that referenced this issue Dec 22, 2015
* helm-org.el (helm-source-org-headings-for-files): Do it.
@jagrg
Copy link
Contributor

jagrg commented Dec 22, 2015

Changing unless to when on line 143 fixes the parent heading problem. I'm not sure if this would have any implication on the rest of the code though.

@thierryvolpiatto
Copy link
Member

No, this work for you with 2 and 2, but this is not what the original code
wants to do.
BTW the actual code works perfectly with 2 and 2 if you recompile and
restart emacs.
Le 22 déc. 2015 14:00, "Jonathan Gregory" [email protected] a
écrit :

Changing unless to when on line 143
https://github.com/emacs-helm/helm/blob/master/helm-org.el#L143 fixes
the parent heading problem. I'm not sure if this would have any implication
on the rest of the code though.


Reply to this email directly or view it on GitHub
#1294 (comment).

@jagrg
Copy link
Contributor

jagrg commented Dec 23, 2015

As I said, yes, your code does work when changing the source code directly and you are welcome to close this. Helm is tricky though. I haven't quite figured out how to create multiple helm-org-in-buffer-headings functions with different min and max-depth arguments, like:

M-x helm-org-in-buffer-headings --> display the entire headline structure and path
M-x helm-org-in-buffer-headings-1 --> display level 1 only (without the path)
M-x helm-org-in-buffer-headings-2 --> display level 2 only (without the path)
etc.

and eventually a function to cycle through the headline levels back and forth, which I think would make
helm-org a lot more potent, especially for long org files with many layers. Indeed, I never really liked the way helm-org-in-buffer-headings displays the full path, which sometimes makes filtering less effective due to the repetition of words. In any case, I probably wouldn't have the knowledge for a PR, but the outline structure which I mentioned earlier is likely the best option. Maybe something to consider at some point.

thierryvolpiatto pushed a commit that referenced this issue Dec 24, 2015
* helm-org.el (helm-org-format-outline-path): New user var.
(helm-org-headings--nofilename): Removed.
(helm-org-show-filename): New user var.
(helm-org--get-candidates-in-file): Ensure window-with is called on helm-window (#1294).
Use new user vars.
@thierryvolpiatto
Copy link
Member

Closing now as all issues are now fixed, please see #1300 for further changes.

@thierryvolpiatto
Copy link
Member

Jonathan Gregory [email protected] writes:

As I said, yes, your code does work when changing the source code
directly and you are welcome to close this. Helm is tricky though. I
haven't quite figured out how to create multiple
helm-org-in-buffer-headings functions with different min and max-depth
arguments, like:

M-x helm-org-in-buffer-headings --> display the entire headline structure and path
M-x helm-org-in-buffer-headings-1 --> display level 1 only (without the path)
M-x helm-org-in-buffer-headings-2 --> display level 2 only (without the path)
etc.

You can now use helm-org-headings-min/max-depth, HTH.

and eventually a function to cycle through the headline levels back
and forth, which I think would make helm-org a lot more potent,
especially for long org files with many layers. Indeed, I never really
liked the way helm-org-in-buffer-headings displays the full path,

Me too, it is now configurable and the default is no path.

which sometimes makes filtering less effective due to the repetition
of words.

Indeed.

Thanks.

Thierry
https://emacs-helm.github.io/helm/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants