我正在尝试在ace编辑器中添加php自定义代码段,但是自定义代码段在编辑器中不可用

时间:2019-09-29 04:26:35

标签: build ace-editor

我正在尝试在ace编辑器中添加php自定义代码段。我在“ ace-master / lib / ace / snippets / php.snippets”中添加了以下代码段,然后使用“ node Makefile.dryice.js”构建了项目。

snippet rett
    return true;
snippet retf
    return false;
snippet test_snippet
    echo "This is a test snippet";

构建项目后,将自定义代码段正确添加到“ ace-master / build / src / snippets / php.js”中,如下所示

snippet rett\n\
    return true;\n\
snippet retf\n\
    return false;\n\
snippet test_snippet\n\
    echo \"This is a test snippet\";";

但是,自定义代码段在编辑器中不可用。尽管其他代码片段都可以正常工作。 我尝试清除浏览器缓存,重新启动Apache,重新加载编辑器等。

1 个答案:

答案 0 :(得分:0)

一个可能的问题是您正在使用空格而不是制表符来缩进。 另一个问题可能是ace中的错误引起的,如果该行的末尾是html,并且不包含php代码段,则将整行视为html。

但是通常更好的方法是在代码中添加代码段,而不是重建ace

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

//Create a matrix with random value between 0 and 99
double **generate_matrix(int size)
{
    int i;

    double **matrix;

    //This part is just to allocate memory space for the matrix
    matrix = (double **)malloc( size* sizeof(double*));

    for(int n=0; n<size; n++){
      matrix[n] = (double *) malloc(size * sizeof(double));
    }


    //init the random
    srand(1);

    //For each element of the matrix give value between 0 and 99
    for (int i = 0; i < size; i++){
      for (int j = 0; j < size; j++) {
          matrix[i][j] = rand() % 100;
      }
    }
    //return the matrix
    return matrix;
}


//Create identity matrix
double ** MatId(int size){
      double ** id;
      int n,i,j;
      //This part is just to allocate memory space for the matrix
      id = (double**) malloc( size* sizeof(double*));
      for (int i = 0; i < size; i++) {
        id[i] = (double*)malloc(size*sizeof(double));
      }


      for(i=0;i<size;i++){
              for(j=0; j<size; j++){
                      if(i==j){
                              id[i][j] = 1;
                      }
                      else{
                            id[i][j] = 0;
                      }
              }
      }
      return(id);
}



//reverse the matrix tfloat_mat and give the result in tfloat_inv by using Gauss Pivot method,
//tfloat_inv is initialized by identity matrix
//int_ligne and int_collone initialized at 0.
//int_taille size of the matrix

double ** inverseGauss(double ** tfloat_mat, double ** tfloat_inv, int int_ligne, int int_colonne, int int_taille){
  int i;//Variable of loop
  double float_case;//Value of the treated element
  float_case = tfloat_mat[int_ligne][int_colonne];


  //If the element is on the diagonal
  if(int_ligne == int_colonne){
    //If the value is 0 we are blocked
    if(float_case == 0){
      printf("Not reversible with Gauss method \n");
      exit(-1);
    }
    //If the value is not 1 we have to modify it
    if(float_case != 1){
      //Gauss algorithm
      for(i = 0; i < int_taille; i++){
        tfloat_mat[int_ligne][i] = (tfloat_mat[int_ligne][i])/float_case;
        tfloat_inv[int_ligne][i] = (tfloat_inv[int_ligne][i])/float_case;
      }
    }
    //Changment of element of the matrix
    if((int_ligne == int_taille - 1) && (int_colonne == int_taille - 1)){
      return(inverseGauss(tfloat_mat, tfloat_inv, 0, 1, int_taille));
    }
    else{
      return(inverseGauss(tfloat_mat, tfloat_inv, int_ligne + 1, int_colonne, int_taille));
    }
  }


  //If the element is in the lower triangle we do an other part of Gauss algorithm
  else if((int_colonne < int_taille)&&(int_ligne > int_colonne)){
    if(float_case != 0){
      for(i = 0; i < int_taille; i++){
        tfloat_mat[int_ligne][i] = (tfloat_mat[int_ligne][i])-float_case*tfloat_mat[int_colonne][i];
        tfloat_inv[int_ligne][i] = (tfloat_inv[int_ligne][i])-float_case*tfloat_inv[int_colonne][i];
      }
    }
    //Changment of element of the matrix
    if(int_ligne == int_taille - 1){
      return(inverseGauss(tfloat_mat, tfloat_inv, int_colonne + 1, int_colonne + 1, int_taille));
    }
    else{
      return(inverseGauss(tfloat_mat, tfloat_inv, int_ligne + 1, int_colonne, int_taille));
    }
  }

    //If the element is in the upper triangle of the matrix we do an other part of Gauss algotithm
  else{
    if(float_case != 0){
      for(i = 0; i < int_taille; i++){
        tfloat_mat[int_ligne][i] = (tfloat_mat[int_ligne][i])-float_case*tfloat_mat[int_colonne][i];
        tfloat_inv[int_ligne][i] = (tfloat_inv[int_ligne][i])-float_case*tfloat_inv[int_colonne][i];
      }
    }
    //Changment of element of the matrix
    if((int_colonne == int_taille - 1)&&(int_ligne == int_taille -2)){
      //Here we did all the step so we return the reverse matrix
      return(tfloat_inv);
    }
    else if(int_ligne +1 != int_colonne){
      return(inverseGauss(tfloat_mat, tfloat_inv, int_ligne + 1, int_colonne, int_taille));
    }
    else{
      return(inverseGauss(tfloat_mat, tfloat_inv, 0, int_colonne + 1, int_taille));
    }
  }
}



//Print the matrix
void PrintMat(int size, double ** matrix){
  int i;//Variable of loop, row of the matrix
  int j;//Variable of loop, column of the matrix
  //print row per row
  for (i = 0; i < size; i++){
    for (j = 0; j < size; j++){
      printf("%f ", matrix[i][j]);
    }
    printf("\n");
  }
}




int main(int argc, char const *argv[]) {
  int size = atoi(argv[1]);
  //identity matrix
  double ** id = MatId(size);
  //matrix with random value
  double ** mat=generate_matrix(size);


  //reverse matrix of intial mat
  mat = inverseGauss(mat, id, 0,0,size);


//free memory
  for (int i = 0; i < size; i++) {
    free(mat[i]);
  }
  free(mat);

  for (int i = 0; i < size; i++) {
    free(id[i]);
  }
  free(id);


  return 0;
}

,甚至直接将摘要添加为json

var snippetManager = require("ace/snippets").snippetManager
var text = 'snippet rett\n\
\treturn true;\n\
snippet retf\n\
\treturn false;\n\
snippet test_snippet\n\
\techo \"This is a test snippet\";";'
var snippets = snippetManager.parseSnippetFile(text, "php");
snippetManager.register(snippets, "php");