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

Avoid to indent snippets having setup (yas-indent-line 'fixed) #838

Merged
merged 1 commit into from Jul 23, 2017
Merged

Avoid to indent snippets having setup (yas-indent-line 'fixed) #838

merged 1 commit into from Jul 23, 2017

Conversation

PierreTechoueyres
Copy link
Contributor

Avoid yas--auto-fill call yas--update-mirrors without setting the snippet environment.

When an snippet like the one bellow is expanded and that auto-fill-mode is activated, the snippet is re-indented when you press space in a field replacement.

# -*- mode: snippet; coding: utf-8-unix -*-
# name: fctb - function ... return boolean
# key: fctb
# expand-env: ((yas-indent-line 'fixed) (yas-wrap-around-region nil))
# --
-------------------------------------------------------------------------------
-- NAME    : ${1:function_name}
-- CREATED : `(capitalize (format-time-string "%d/%m/%Y"))`
-- AUTHOR  : `(and (boundp 'user-ngram) user-ngram)`
-------------------------------------------------------------------------------
-- ARGS  :
-- - $3
-------------------------------------------------------------------------------
-- RETURN  : ${4:True when all is OK, false in any other cases'}
-------------------------------------------------------------------------------
-- DESC : ${5:description}
-------------------------------------------------------------------------------
FUNCTION $1(${3:param})
RETURN   BOOLEAN IS
  v_result BOOLEAN := TRUE;
BEGIN
  trace('${2:package_name}',
        '$1 - start' || lf
     || '$3 => ' || $3);
  $0
  trace('$2', '$1 - End' || lf
     || 'v_result => ' || bool2var(v_result));
  return v_result;
END $1;

when expanded:

-------------------------------------------------------------------------------
-- NAME    : my function
-- CREATED : 22/07/2017
-- AUTHOR  : 
-------------------------------------------------------------------------------
-- ARGS  :
-- - param
-------------------------------------------------------------------------------
-- RETURN  : True when all is OK, false in any other cases'
-------------------------------------------------------------------------------
-- DESC : description
-------------------------------------------------------------------------------
FUNCTION my function(param)
RETURN   BOOLEAN IS
  v_result BOOLEAN := TRUE;
BEGIN
  trace('package_name',
  'my function - start' || lf
  || 'param => ' || param);
  
trace('package_name', 'my function - End' || lf
     || 'v_result => ' || bool2var(v_result));
  return v_result;
  END my function;

with the patch:

-------------------------------------------------------------------------------
-- NAME    : my function
-- CREATED : 22/07/2017
-- AUTHOR  : 
-------------------------------------------------------------------------------
-- ARGS  :
-- - param
-------------------------------------------------------------------------------
-- RETURN  : True when all is OK, false in any other cases'
-------------------------------------------------------------------------------
-- DESC : description
-------------------------------------------------------------------------------
FUNCTION my function(param)
RETURN   BOOLEAN IS
  v_result BOOLEAN := TRUE;
BEGIN
  trace('package_name',
        'my function - start' || lf
     || 'param => ' || param);
  
  trace('package_name', 'my function - End' || lf
     || 'v_result => ' || bool2var(v_result));
  return v_result;
END my function;
  • yasnippet.el (yas--auto-fill): reinstate snippet environment before calling yas--update-mirrors.

Copy link
Collaborator

@npostavs npostavs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you put the yas--letenv outside of the mapc please? And use straight quotes in the commit message, it's not markdown.

Otherwise looks good to me, thanks.

@PierreTechoueyres
Copy link
Contributor Author

I'm not sure what you mean by putting yas--letenv outside the mapc as the yas--snippet-expand-env expect only one snippet and snippets is an list of snippets. Could you please elaborate ?

Sorry for the quotes. Does something like that will agree you ?

 Avoid to indent snippets having setup `(yas-indent-line 'fixed)'

Avoid `yas--auto-fill' call `yas--update-mirrors' without setting
the snippet environment.

@npostavs
Copy link
Collaborator

I'm not sure what you mean by putting yas--letenv outside the mapc as the yas--snippet-expand-env expect only one snippet and snippets is an list of snippets. Could you please elaborate ?

Oops! I was talking nonsense.

Sorry for the quotes. Does something like that will agree you ?

Yup, that's fine.

Have you done copyright assignment for Emacs? (the change is small enough to install regardless).

@npostavs npostavs dismissed their stale review July 23, 2017 00:05

It was bogus

@PierreTechoueyres
Copy link
Contributor Author

Yes I've done my copyright agreement (for TRAMP and Emacs I think).
I've updated the patch, could you review it ?

Avoid `yas--auto-fill' call to `yas--update-mirrors' without setting
the snippet environment.

* yasnippet.el (yas--auto-fill): Reinstate snippet environment before
calling `yas--update-mirrors'.
@npostavs npostavs merged commit 7365f9e into joaotavora:master Jul 23, 2017
@npostavs
Copy link
Collaborator

Thanks, merged.

(I put the snippets arg on a separate line because emacs 25+ now colours such things in error-face otherwise. Also removed the#' from the lambda.)

@PierreTechoueyres
Copy link
Contributor Author

PierreTechoueyres commented Jul 23, 2017

I added the #' to quiet the byte compiler:

yasnippet.el:3637:17:Warning: (lambda (snippet) ...) quoted with ' rather than
    with #'

@npostavs
Copy link
Collaborator

Yes, quoting with ' is wrong, quoting with #' is okay, but I prefer the unquoted style (though currently yasnippet.el has a mix). The lambda macro puts in the #' for you.

@PierreTechoueyres
Copy link
Contributor Author

Ok, I've just asked for my information :-)

@PierreTechoueyres PierreTechoueyres deleted the pte/yas--auto-fill branch July 23, 2017 11:36
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

Successfully merging this pull request may close these issues.

None yet

2 participants